【问题标题】:Dompdf not rendering INR symbol in PDFDompdf 未在 PDF 中呈现 INR 符号
【发布时间】:2018-08-30 05:27:10
【问题描述】:

我在尝试使用 INR 货币符号时遇到了 dompdf 问题。我已经设法在我的本地服务器上使用Dejavu Sans font family 解决了这个问题。但是,当我将文件上传到实时服务器时,它只会生成一个? 来代替INR symbol。我尝试了很多方法,例如提供@fontface{...} 代码、define("DOMPDF_UNICODE_ENABLED",true)、使用“货币”字体系列,但它不起作用。

require_once 'class-my-pdf-creator.php';
$dompdf = new my_pdf_obj();
define("DOMPDF_UNICODE_ENABLED", true);
$dompdf->set_option('isHtml5ParserEnabled', true);
$dompdf->loadHtml('<style>@font-face {
  font-family: "DejaVu Sans";
  font-style: normal;
  font-weight: normal;
}</style><span style="font-family: DejaVu Sans; sans-serif;">&#8377;</span>');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
$dompdf->set_option('font_subsetting', true);
// Render the HTML as PDF
$dompdf->render();
$dompdf->stream();

【问题讨论】:

  • 你用的是哪个版本的 dompdf?
  • 我使用的是 .6 版
  • 请查看我的回答,如果您在渲染 INR 符号时仍有问题,请告诉我。
  • github.com/dompdf/dompdf/wiki/Usage load_html 和 set_paper,而不是 loadHtml/setPaper
  • @teejay - 你提到我的答案了吗?如果您仍然遇到任何问题,请告诉我。

标签: php dompdf html-to-pdf


【解决方案1】:

Dompdf 0.6.x 及以上版本支持不同的编码。

显示 INR 的最简单方法是将您的文档编码为 UTF-8。然后您可以参考 INR 符号。

将以下语句添加到您的 HTML:

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

将上面添加到您的 HTML 后,您可以使用以下代码显示 INR 符号:

<span style="font-family: DejaVu Sans; sans-serif;">&#8377;</span>

【讨论】:

    猜你喜欢
    • 2013-11-18
    • 2012-01-28
    • 2021-10-31
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    • 1970-01-01
    • 2019-12-03
    • 1970-01-01
    相关资源
    最近更新 更多