库Mpdf(php):设置utf-8并使用带有utf-8的WriteHTML

问题描述 投票:0回答:1

我需要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个回答
0
投票

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

0
投票

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

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

如果您确定您的html是utf-8,请使用此选项

© www.soinside.com 2019 - 2024. All rights reserved.