html2pdf中的CP1251编码问题

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

我是从以下网站下载和设置脚本:http://www.html2pdf.fr/en它可以正常使用默认编码,但是当我尝试使用CP-1251中的字符生成文档时,我得到的是空格而不是字符。还有我在CP-1251中的所有文件,CP-1251中的数据,你可以看到我使用简单的字体-Arial

请,可能存在一些解决方案,让它工作。

P / s对不起我的英语

    ob_start();

include(dirname(__FILE__).'/res/exemple00.php');

$content = ob_get_clean();

require_once(dirname(__FILE__).'/../html2pdf.class.php');

try

{

    $html2pdf = new HTML2PDF('P','A4','fr');

    $html2pdf->setDefaultFont('Arial');

    $html2pdf->writeHTML($content, isset($_GET['vuehtml']));

    $content1=$html2pdf->Output('', 'S');

//一些PHP代码

    $db->query("set names cp1251");

$query="SELECT data from files Where id=$file_id ";

$result=$db->query($query);

    $row=$result->fetch_assoc();

$content=($row['data']);

标题('Content-Type:application / pdf');

header(“Content-Length:”。。strlen(content));

header('Content-Disposition:attachment; filename = Invoice#'。$ invoice_id。'。pdf');

打印$ content;

}

catch(HTML2PDF_exception $e) { echo $e; }    enter code here
php pdf-generation html2pdf cp1251
1个回答
0
投票

我没有使用这个库,但你在HTML2PDF构造函数中设置编码吗?

    $html2pdf = new HTML2PDF('P','A4','fr', true, 'CP-1251');

如果它不起作用,请尝试'cp1251'或'CP1251',我在文档中找不到已识别编码的列表。您也可以使用iconv并转换为UTF-8,因为它似乎是默认值。

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