TCPDF returning weird characters

浪尽此生 提交于 2020-02-24 12:28:14

问题


maybe you can help me. When I try to show a pdf I created I got some weird symbols like this

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 = $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.

Any ideas?

Thanks in advance,


回答1:


You need to convert the response to a Blob (link)

After creating the blob, you can create an URL object (link)

This is how I create a server side generated pdf and display it on the front end.

Adding code snippet:

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



回答2:


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!



来源:https://stackoverflow.com/questions/46492596/tcpdf-returning-weird-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!