【问题标题】:Library Mpdf (php): Set utf-8 and use WriteHTML with utf-8库 Mpdf (php):设置 utf-8 并将 WriteHTML 与 utf-8 一起使用
【发布时间】:2019-07-28 21:14:12
【问题描述】:

我需要有关 php Mpdf 库的帮助。我正在为 pdf 生成内容,它位于 div 标签中,并由 jquery 发送到 php 服务器,其中 Mpdf 用于生成最终文件。

在生成的 pdf 文件中,utf-8 字符出错,例如“generación”而不是“generación”。

我详细说明了它们是如何实现的:

HTML

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

为 pdf (jquery) 发送内容

$('#pdf').click(function() {       
    $.post( 
            base_url,
            { 
                contenido_pdf:      $("#div").html(),
            },
            function(datos) {
            }       
    );
});

接待内容 (PHP)

$this->pdf = new mPDF();
$this->pdf->allow_charset_conversion = true;                                
$this->pdf->charset_in = 'iso-8859-1';
$contenido_pdf  = this->input->post('contenido_pdf');

$contenido_pdf_formateado = mb_convert_encoding($contenido_pdf, 'UTF-8', 'windows-1252');
$this->m_pdf->pdf->WriteHTML($contenido_pdf_formateado);

其他经过测试的选项:

1。 $this->pdf->charset_in = 'UTF-8';

得到错误:

Severity: Notice  --> iconv(): Detected an illegal character in input string

2.

$contenido_pdf_formateado = mb_convert_encoding($contenido_pdf, 'UTF-8', 'UTF-8');

3.

$contenido_pdf_formateado = utf8_encode($contenido_pdf);

获取不正确的字符,如原始大小写。

有什么问题或遗漏了什么才能看清楚文字?谢谢

【问题讨论】:

    标签: php jquery pdf-generation mpdf


    【解决方案1】:

    解决方案

    $contenido_pdf_formateado = utf8_decode($contenido_pdf);
    $this->m_pdf->pdf->WriteHTML($contenido_pdf_formateado);
    

    【讨论】:

      【解决方案2】:

      我在创建对象时使用了模式

      $mpdf = new Mpdf(['mode' => 'UTF-8']);
      

      如果你确定你的 html 是 utf-8 就使用这个

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-08-28
        • 2017-01-02
        • 2018-08-21
        • 2012-03-10
        • 2011-06-16
        • 1970-01-01
        • 2012-03-11
        相关资源
        最近更新 更多