【问题标题】:TCPDF returning weird charactersTCPDF 返回奇怪的字符
【发布时间】:2018-03-11 13:57:27
【问题描述】:

也许你可以帮助我。当我尝试显示我创建的 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`����

我所做的是用这段代码转换一个 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');  

另一方面,我是这样收到的

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

我正在使用 php(服务器)、html(创建页面)、extjs(接口)、ajax(请求)和 TCPDF 来创建 pdf。

有什么想法吗?

提前致谢,

【问题讨论】:

标签: php html ajax extjs tcpdf


【解决方案1】:

您需要将响应转换为 Blob (link)

创建 blob 后,可以创建 URL 对象 (link)

这就是我创建服务器端生成的 pdf 并将其显示在前端的方式。

添加代码sn-p:

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

【讨论】:

  • 这样的? var blob = new Blob(response.responseText); objectURL = URL.createObjectURL(blob); Ext.getCmp('winReporteRegistro').update(objectURL);窗口没有显示任何东西:(
  • 接近我所拥有的。 var blob = new Blob(response.responseText, {type: 'application/pdf'}); var objectURL = URL.createObjectURL(blob);获得对象 URL 后,您可以将其显示为下载链接或直接下载 pdf。还发现了这个link
  • 我尝试添加一个窗口 var window = Ext.create('Ext.window.Window', { items: [{ xtype: 'component', autoEl: { tag: 'a', href : objectURL, html: 'Example.com' } 显示超链接但还是不行。窗口没有出现
  • 你可以做一个简单的window.open(objectURL);它应该在一个新的浏览器窗口中打开它
  • 它不起作用,没有任何反应。 Ext.Ajax.request ( {method: 'post',url: '../servidor/archivo/ingreso/getreporte',success: function(response){ var blob = new Blob(response.responseText, {type: 'application /pdf'}); var objectURL = URL.createObjectURL(blob); window.open(objectURL); }, } );我不知道为什么..
【解决方案2】:

返回文件的位置并在另一个网页中打开是答案,代码是:

服务器:

$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';

客户:

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

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

                       }
                }
            );

谢谢!

【讨论】:

    【解决方案3】:

    很抱歉回答迟了,但我昨天摔断了牙齿,今天早上我有一个照明:-) 您需要支持 mime 类型,因此只需将其添加到您的 .htaccess 中:

    AddType application/pdf .pdf
    

    【讨论】:

      猜你喜欢
      • 2019-07-05
      • 2017-07-04
      • 2019-07-27
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 1970-01-01
      • 2019-03-22
      相关资源
      最近更新 更多