php – 当我使用波斯文本时,DomPDF输出被破坏了
我正在使用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文件: 我怎样才能解决这个问题?
好吧,我想我有一个解决你的问题的方法.我可以制作一个看起来像我认为你正在寻找的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软件包. 通过阅读make install的输出,您将知道该模块所在的目录.通常是: /usr/lib64/php/modules/ 第三:设置php以了解这个模块 extension=phpwkhtmltox.so 第四:运行ldconfig $ldconfig 第五:重启apache(或者你正在使用的httpd) 最后:像这样使用它: <?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可以正常工作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |