dompdf 特殊字符

发布于 2024-10-19 14:54:10 字数 521 浏览 0 评论 0原文

我成功地将 html 转换为 pdf,但不包含特殊字符。

下面是我试图显示的一个特殊字符,当我将其简单地放在 html 文档中时,它会显示在我的 Mac 上的浏览​​器中。 (但不是在我的 Windows 盒子上)

<?php
require_once("../dompdf_config.inc.php");
$html = '&#8364;';
$dompdf = new DOMPDF(); $html = iconv('UTF-8','Windows-1250',$html);
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("contract.pdf");
exit(0);
?>

我不断收到一个“?” (问号)当 pdf 呈现时。 我知道有很多关于特殊字符的问题记录在案,但我想我应该用我实际使用的代码尝试一下。

如果 DomPdf 不是推荐的 html 到 pdf 转换工具,我会接受任何其他推荐!

I'm having successful html-to-pdf conversions, but not with special characters.

Below is just a special character I'm trying to display, which displays in browsers on my Mac, when I put it simply inside an html document. (but not on my windows box)

<?php
require_once("../dompdf_config.inc.php");
$html = '€';
$dompdf = new DOMPDF(); $html = iconv('UTF-8','Windows-1250',$html);
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("contract.pdf");
exit(0);
?>

I keep getting a "?" (question mark) when the pdf is rendered.
I know there's been lots of issues documented with regards to special characters, but I thought I'd give this a try, with the code I'm actually using.

If DomPdf isn't a recommended html-to-pdf conversion tool, I'll take any other recommendations!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

你又不是我 2024-10-26 14:54:10

我在转换 UTF-8 html 页面时遇到了 DOMPDF 问题。
解决了这个问题

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

我只是通过添加Between < 头>标签。
如果您使用编码类型设置它,也许它可能是一种替代方案。

以下评论中的重要注意事项:不要在同一 pdf 实例上使用 stream()output() 方法。如果你这样做是行不通的。

I have experienced problems with DOMPDF when converting an UTF-8 html page.
I simply solved the problem by adding

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

Between < head > tag.
Maybe it could be an alternative if you set it with your encoding type.

IMPORTANT NOTE from comments below: don't use stream() and output() methods on the same pdf instance. If you do this wont work.

稚然 2024-10-26 14:54:10

尝试了网上所有的解决方案后。我可以在不修改 dompdf 的情况下解决。问题出在 html 内容上。当然,我只需要添加正确且适当的 HTML 结构并设置字体即可。在 v0.6.0 和 v0.6.1 上测试。这里我留下代码

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
  <meta http-equiv="Content-Type" content="charset=utf-8" />
  <style type="text/css">
    * {
      font-family: "DejaVu Sans Mono", monospace;
    }
  </style>
</head>

<body>your content ćčžšđ...</body>

</html>

after trying all solutions on the net. I could solve without modifying the dompdf. the problem was on the html content. I just had to add the correct and appropriate HTML structure and setting the font of course . Tested on v0.6.0 and v0.6.1. here I leave the code

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
  <meta http-equiv="Content-Type" content="charset=utf-8" />
  <style type="text/css">
    * {
      font-family: "DejaVu Sans Mono", monospace;
    }
  </style>
</head>

<body>your content ćčžšđ...</body>

</html>
简单 2024-10-26 14:54:10

DOMPDF 拉丁土耳其语 (Türkçe) 字符问题,我的解决方案 %100 有效。

服务器需求控制:
服务器要求control

Char 'dejavu sans mono'(土耳其语支持)或:

第 1 步:dompdf_config.inc.php 编辑为

mb_internal_encoding('UTF-8');
def("DOMPDF_UNICODE_ENABLED", true);

第 2 步:lib/fonts/dompdf_font_family_cache.dist。编辑php添加代码:

'futural' => 
  array (
    'normal' => DOMPDF_FONT_DIR . 'FUTURAL',
    'bold' => DOMPDF_FONT_DIR . 'FUTURAL',
    'italic' => DOMPDF_FONT_DIR . 'FUTURAL',
    'bold_italic' => DOMPDF_FONT_DIR . 'FUTURAL',
  ),

第3步:doqnload字体文件复制lib/fonts文件夹。
下载字体文件链接 http://www.2shared.com/file/k6hdky_b/fonts.html

第 4 步:您的代码 编辑示例:

require_once("dompdf_config.inc.php");
$html='<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
    html{padding:-30px;}
    body { font-family: futural; }
</style>
</head><body>';
$html.='ı İ Ş ş ç Ç ö Ö ü Ü ğ Ğ ÿ þ ð ê ß ã Ù Ñ È »  ¿ İsa Şahintürk';
$html.='</body></html>';
if ( isset( $html ) ) {
    if ( get_magic_quotes_gpc() )
    $html = stripslashes($html);
    $old_limit = ini_set("memory_limit", "16M");
    $dompdf = new DOMPDF();
    $dompdf->load_html($html,'UTF-8');
    $dompdf->set_paper('a4', 'portrait');// or landscape
    $dompdf->render();
    $dompdf->stream("limitless.pdf");
exit(0);
}

完成PDF>示例在此处输入图像描述
http://limitsizbilgi.com/pdf/dompdf-chartest.pdf

DOMPDF Latin Turkish (Türkçe) char problem, my solution %100 Work.

Server requirenment control:
Server requirenment control

Char 'dejavu sans mono' (Turkish support) OR:

Step 1: dompdf_config.inc.php edit to

mb_internal_encoding('UTF-8');
def("DOMPDF_UNICODE_ENABLED", true);

Step 2: lib/fonts/dompdf_font_family_cache.dist.php edit to add code:

'futural' => 
  array (
    'normal' => DOMPDF_FONT_DIR . 'FUTURAL',
    'bold' => DOMPDF_FONT_DIR . 'FUTURAL',
    'italic' => DOMPDF_FONT_DIR . 'FUTURAL',
    'bold_italic' => DOMPDF_FONT_DIR . 'FUTURAL',
  ),

Step 3: doqnload font files to copy lib/fonts folder.
Download font files Link http://www.2shared.com/file/k6hdky_b/fonts.html

Step 4: Your code Edit example:

require_once("dompdf_config.inc.php");
$html='<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
    html{padding:-30px;}
    body { font-family: futural; }
</style>
</head><body>';
$html.='ı İ Ş ş ç Ç ö Ö ü Ü ğ Ğ ÿ þ ð ê ß ã Ù Ñ È »  ¿ İsa Şahintürk';
$html.='</body></html>';
if ( isset( $html ) ) {
    if ( get_magic_quotes_gpc() )
    $html = stripslashes($html);
    $old_limit = ini_set("memory_limit", "16M");
    $dompdf = new DOMPDF();
    $dompdf->load_html($html,'UTF-8');
    $dompdf->set_paper('a4', 'portrait');// or landscape
    $dompdf->render();
    $dompdf->stream("limitless.pdf");
exit(0);
}

End Finish PDF > exampleenter image description here
http://limitsizbilgi.com/pdf/dompdf-chartest.pdf

巷雨优美回忆 2024-10-26 14:54:10

您必须使用其他字符集。例如 dejavu Sans Mono。添加您的代码

<style>
*{
    font-family:"DeJaVu Sans Mono",monospace;
}
</style>

我也在视频中提到过。

You must use another character set. For example dejavu Sans Mono. Add your code

<style>
*{
    font-family:"DeJaVu Sans Mono",monospace;
}
</style>

I also mentioned it in this video.

骑趴 2024-10-26 14:54:10

0.6.x 之前的任何版本对 iso-8859-1 编码之外的字符的支持有限。 0.5.x 中通过使用适当的 Windows ANSI 字符代码 () 支持欧元,但否则您必须跳过一些 PDF 编码环节。

0.6.0 版本更好地支持“特殊”字符。默认编码基于 Windows ANSI(PDF 1.3 规范认可的少数编码之一)。您可以通过加载基于 Unicode 的字体并在 dompdf 中启用 Unicode 并在文档中指定该编码来启用更好的字符支持。

以下内容应该适用于 dompdf 0.6.0 或更高版本:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
  <p>€</p>
</body>
</html>

(或者为了偷懒,只需在测试中使用欧元实体

有一个文档概述了 在 DOMPDF 中启用 Unicode 支持
另外,请阅读此答案,了解如何加载字体的概述

Anything prior to 0.6.x has limited support for characters outside iso-8859-1 encoding. The Euro is supported in 0.5.x by using the appropriate Windows ANSI character code (), but otherwise you have to jump through some PDF encoding hoops.

The 0.6.0 release has better support for "special" characters. The default encoding is based on Windows ANSI (one of the few recognized by the PDF 1.3 spec). You can enable better character support by loading a Unicode-based font and enabling Unicode in dompdf and specifying that encoding in your document.

The following should work in dompdf 0.6.0 or greater:

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
  <p>€</p>
</body>
</html>

(or to be lazy just use the euro entity in your test)

There is a document outlining the steps needed to enable Unicode support in DOMPDF.
Plus read this answer for an overview of how to load fonts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文