php – 当我使用波斯文本时,DomPDF输出被破坏了

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 当我使用波斯文本时,DomPDF输出被破坏了脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用DomPDFPHP来创建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

怎样才能解决这个问题?

好吧,我想我有一个解决你的问题的方法.我可以制作一个看起来像我认为你正在寻找的PDF.这是它的截图

http://i.imgur.com/UBdkNDx.png

要做到这一点,你必须使用不同的方式制作pdf而不是dompdf:wkhtmltox-PHP.

wkhtmltox-PHP一个代码编译的自定义PHP命令,它使用libwkhtmltox制作pdfs.安装它需要花费一些精力,但它会像上面那样呈现你的波斯文本并且比dompdf快得多.

这些说明假设linux或类似你的操作系统:

第一:安装wkhtmltopdf.
这里有大多数操作系统的预编译二进制文件

http://wkhtmltopdf.org/downloads.html

第二:获取并编译并安装PHP-wkhtmltox.

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

第五:重启apache(或者你正在使用的httpd)

最后:像这样使用它:
对于我的例子,我只是使用维基百科国际象棋开放页面,因为我没有你的示例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,请注明来意。