dongzhiju0324 2018-02-26 09:50
浏览 45

Dompdf unicode字符(仅在服务器上)

I use dompdf to render my html pages to pdf. I prepared templates in php and used the codes below. It works fine on localhost, but fails (shows question marks instead of unicode chars) when I upload it on the server. And FontAwesome also fails to show icons.

generator.php

<?php
session_start();
ob_start();
//dompdf
require_once('../../dompdf/autoload.inc.php');
use Dompdf\Dompdf;
require_once('../pdf-template/template.php');
$template=ob_get_clean();
$dompdf=new Dompdf();
$dompdf->loadHtml($template);

//paper
$dompdf->setPaper('A4','portrait');

// render
$dompdf->render();
$pdf_content = $dompdf->output();
file_put_contents('test.pdf',$pdf_content);
echo "successful";
?>

template.php

<i class="fa fa-paw"></i>
<h2 style="font-family: DejaVu Sans; font-size: 22px">ığĞüÜşŞİöÖçÇ</h2>
  • 写回答

1条回答 默认 最新

  • doumi9618 2018-02-28 11:02
    关注

    I solved the problem. It is about the dompdf_font_family_cache.dist.php. Once it is triggered on localhost, it changes the folder according to my computer. So the font doesn't change on the server. To solve, The php files in dompdf/lib/fonts folder should be deleted and the clean "dompdf_font_family_cache.dist.php" you get from Github/DOMPDF should be uploaded.

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型