脚本宝典收集整理的这篇文章主要介绍了php – 当我使用波斯文本时,DomPDF输出被破坏了,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这是包含波斯文和英文文本的示例文件:
<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>
http://i.imgur.com/UBdkNDx.png
要做到这一点,你必须使用不同的方式制作pdf而不是dompdf:wkhtmltox-PHP.
wkhtmltox-PHP是一个从源代码编译的自定义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,则需要安装PHP dev软件包.
注意:如果你在configure或make install上遇到错误,你需要安装c编译工具,比如’make’和’gcc’
通过阅读make install的输出,您将知道该模块所在的目录.通常是:
/usr/lib64/PHP/modules/
第三:设置PHP以了解这个模块
在您的PHP.ini文件中,在“动态扩展”标题下添加以下行
extension=PHPwkhtmltox.so
第四:运行ldconfig
$ldconfig
最后:像这样使用它:
对于我的例子,我只是使用维基百科的国际象棋开放页面,因为我没有你的示例HTML的网址.
<?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可以正常工作.
以上是脚本宝典为你收集整理的php – 当我使用波斯文本时,DomPDF输出被破坏了全部内容,希望文章能够帮你解决php – 当我使用波斯文本时,DomPDF输出被破坏了所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。