简体   繁体   English

TCPDF 返回奇怪的字符

[英]TCPDF returning weird characters

maybe you can help me.也许你可以帮助我。 When I try to show a pdf I created I got some weird symbols like this当我尝试显示我创建的 pdf 时,我得到了一些像这样的奇怪符号

u\>�'���O���r>c!%�@�R�`YPd+��vv����1��E�'^k-�WD�*+��W^��wy��V Z��dUdJ�B���C�ڳtK����j:c���5����50���D3lgH#�}%���D+������ix����,��-�'\�� �_st^&0�Y���������v�*Ӗ,W����u!H��sNN��0cӝ��`xEk��d��^� �8K9�BL����9�̋"6/�E�|�̛�-�7�P��B�#�T�F���4`����

What I do is transform a html file with this code我所做的是使用此代码转换 html 文件

    $html = $this->load->view('ReporteIngresoView', $data, TRUE);
    $pdf = new Pdf('P', 'mm', 'A4', TRUE, 'UTF-8', FALSE);
    $pdf->SetTitle('Reporte ingreso');
    $pdf->SetHeaderMargin(30);
    $pdf->SetTopMargin(40);
    $pdf->setFooterMargin(20);
    $pdf->SetAutoPageBreak(TRUE);
    $pdf->SetAuthor('Pontificia Universidad Católica del Ecuador');
    $pdf->SetDisplayMode('real', 'default');
    $pdf->AddPage();
    $pdf->writeHTML($html, TRUE, 0, TRUE, 0);
    $pdf->Output('My-File-Name.pdf', 'I');  

On the other side I recieve it like this在另一边我收到这样的

Ext.Ajax.request
            (
                {
                    method: 'post',
                    url: '../servidor/archivo/ingreso/getreporte',
                    success: function(response){
                    Ext.getCmp('winReporteRegistro').update( response.responseText );
                       }
                    }
            );

I am using php (server), html (create the page), extjs (interface), ajax (request) and TCPDF to create the pdf.我正在使用 php(服务器)、html(创建页面)、extjs(接口)、ajax(请求)和 TCPDF 来创建 pdf。

Any ideas?有什么想法吗?

Thanks in advance,提前致谢,

You need to convert the response to a Blob ( link )您需要将响应转换为 Blob(链接

After creating the blob, you can create an URL object ( link )创建 blob 后,您可以创建一个 URL 对象( 链接

This is how I create a server side generated pdf and display it on the front end.这就是我创建服务器端生成的 pdf 并将其显示在前端的方式。

Adding code snippet:添加代码片段:

var blob = new Blob(response.responseText, {type: 'application/pdf'}); 
var objectURL = URL.createObjectURL(blob);

Returning the location of the file and open that in another web page was the answer, the code is:返回文件的位置并在另一个网页中打开它是答案,代码是:

Server:服务器:

$html = $this->load->view('ReporteCajaView', $data, TRUE);

    $pdf = new Pdf('P', 'mm', 'A4', TRUE, 'UTF-8', FALSE);
    $pdf->SetTitle('Reporte item');
    $pdf->SetHeaderMargin(30);
    $pdf->SetTopMargin(20);
    $pdf->setFooterMargin(20);
    $pdf->SetMargins(25, 20, 20, true);
    $pdf->SetAutoPageBreak(TRUE);
    $pdf->SetAuthor('Universidad Católica');
    $pdf->SetDisplayMode('real', 'default');
    $pdf->setPrintHeader(FALSE);
    $pdf->setPrintFooter(FALSE);
    $pdf->AddPage();

    $id = uniqid();
    $pdf->writeHTML($html, TRUE, 0, TRUE, 0);
    $pathservidor = 'c:/wamp64/www/Archivo/pdf/';
    $pdf->Output($pathservidor . 'Reporte de caja' . '.pdf', 'F');

    echo 'c:/wamp64/www/Archivo/pdf/'.'Reporte de caja'.'.pdf';

Client:客户:

Ext.Ajax.request
            (
                {
                    method: 'post',
                    url: '../servidor/archivo/item/getreporte',

                    success: function(response){
                    window.open(response.responseText);

                       }
                }
            );

Thanks!谢谢!

很抱歉我的回答迟到了,但我昨天和今天早上对此感到很抱歉:-) 您需要支持 mime 类型,因此只需将其添加到您的 .htaccess 中:

AddType application/pdf .pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM