我使用DomPDF和PHP来创建PDF文件。当文本是英文时,一切正常,但当我想转换波斯语文本时,输出就中断了。
这是包含波斯语和英语文本的示例文件:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {
font-family: 'dejavu sans';
direction;rtl;
}
p {
font-size: 2em;
background: #eee;
padding: 1em;
}
h2 {
color: #999;
}
</style>
<style type="text/css"></style></head>
<body marginwidth="0" marginheight="0">
<div style="text-align:right">
<h2>Give You Glory</h2>
<br/>
Hadi
</div>
<br/>
هادی
</body></html>这是输出PDF文件:http://i.stack.imgur.com/HOyMO.png
我怎么才能解决这个问题?
发布于 2015-08-02 22:22:37
好吧,我想我有办法解决你的问题。我可以做一个pdf,看上去像我认为你要找的东西。这是它的截图
http://i.imgur.com/UBdkNDx.png
要做到这一点,您必须使用一种与dompdf不同的pdfs方式:wkhtmltox。
wkhtmltox是从源代码编译的自定义php命令,它使用libwkhtmltox生成pdfs。安装它需要一些努力,但它将呈现您的波斯语文本如上文和将比dompdf快得多。
这些指令假设linux或类似于您的操作系统:
首先:安装wkhtmltopdf。在这里,大多数操作系统都有预编译的二进制文件:
http://wkhtmltopdf.org/downloads.html
第二:获取、编译和安装。
cd /tmp/
wget https://github.com/mreiferson/php-wkhtmltox/archive/master.zip
unzip master.zip
cd php-wkhtmltox-master/
phpize
./configure
sudo make install注意:如果计算机上没有安装phpize,则需要安装phpize包。注意:如果您在配置或make上出现错误,则需要安装c编译工具,如“make”和“gcc”。
通过读取make install的输出,您将知道模块位于哪个目录中。通常是:
/usr/lib64/php/modules/第三:设置php以了解php.ini文件中的这个模块,在标题“动态扩展”下添加以下一行
extension=phpwkhtmltox.so第四:运行ldconfig
$ ldconfig第五:重新启动apache (或您正在使用的任何httpd )
最后:像这样使用它:对于这里的例子,我只是使用维基百科中的国际象棋开始页面,因为我没有您的示例html的url。
<?php
/**
* the config_array has lots of options but the two most important are:
* "out" this is the full path to where you want your pdf made
* "imageQuality" basically the same as jpg image quality. lower quality is slower, higher quality is a bigger file
*/
$config_array = array( "out" => "/tmp/pdfdocument.pdf",
"imageQuality" => 95);
/**
* the array of urls that are the input html for making your pdf. note that these are not files, but urls
* also note that this is an array of arrays keyed by "page"
*/
$htmls_array = array(array("page"=>"http://en.wikipedia.org/wiki/Queen's_Gambit_Declined"));
/**
* run the conver like so and your pdf file should be on disk
*/
wkhtmltox_convert('pdf', $config_array, $htmls_array);
?>如果你看一下我上面发布的截图,你会发现phpwkhtmltox做的很好。
https://stackoverflow.com/questions/19952345
复制相似问题