我有成功的HTML到pdf转换,但不是特殊字符.
下面只是我想要显示的一个特殊字符,它显示在我的Mac上的浏览器中,当我把它放在一个html文档中时.(但不在我的窗户盒子上)
<?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);
?>
Run Code Online (Sandbox Code Playgroud)
我一直得到一个"?" (pdf)提交pdf时的问号.我知道在特殊字符方面记录了很多问题,但是我想我会尝试使用我实际使用的代码.
如果DomPdf不是推荐的html-to-pdf转换工具,我会接受任何其他建议!
Ric*_*ins 16
转换UTF-8 html页面时,我遇到过DOMPDF问题.我只是通过添加来解决问题
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Run Code Online (Sandbox Code Playgroud)
在<head>标签之间.如果您使用编码类型设置它可能是一个替代方案.
重要说明来自以下注释:不要在同一个pdf实例上使用stream()和output()方法.如果你这样做不会工作.
DOMPDF拉丁土耳其语(Türkçe)char问题,我的解决方案%100工作.
Char'dejavu sans mono'(土耳其支持)或:
第1步:dompdf_config.inc.php编辑到
mb_internal_encoding('UTF-8');
def("DOMPDF_UNICODE_ENABLED", true);
Run Code Online (Sandbox Code Playgroud)
第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',
),
Run Code Online (Sandbox Code Playgroud)
第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);
}
Run Code Online (Sandbox Code Playgroud)
结束完成PDF>示例
http://limitsizbilgi.com/pdf/dompdf-chartest.pdf
在网上尝试所有解决方案后。我可以解决而无需修改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>
Run Code Online (Sandbox Code Playgroud)
小智 5
您必须使用其他字符集。例如 dejavu Sans Mono。添加您的代码
<style>
*{
font-family:"DeJaVu Sans Mono",monospace;
}
</style>
Run Code Online (Sandbox Code Playgroud)
我在这个视频里也提到过。
0.6.x 之前的任何版本对 iso-8859-1 编码之外的字符的支持有限。0.5.x 中通过使用适当的 Windows ANSI 字符代码 ( ) 支持欧元€,但否则您必须跳过一些 PDF 编码环节。
0.6.0 版本更好地支持“特殊”字符。默认编码基于 Windows ANSI(PDF 1.3 规范认可的少数编码之一)。您可以通过加载基于 Unicode 的字体并在 dompdf 中启用 Unicode 并在文档中指定该编码来启用更好的字符支持。
\n\n以下内容应该适用于 dompdf 0.6.0 或更高版本:
\n\n<!DOCTYPE html>\r\n<html>\r\n<head>\r\n <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\r\n</head>\r\n<body>\r\n <p>\xe2\x82\xac</p>\r\n</body>\r\n</html>Run Code Online (Sandbox Code Playgroud)\r\n(或者为了偷懒,€在测试中使用欧元实体)
有一个文档概述了在 DOMPDF 中启用 Unicode 支持所需的步骤。\n另外请阅读此答案以了解如何加载字体的概述。
\n