首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当我使用波斯文本时,DomPDF输出中断

当我使用波斯文本时,DomPDF输出中断
EN

Stack Overflow用户
提问于 2013-11-13 11:18:13
回答 1查看 1.4K关注 0票数 8

我使用DomPDF和PHP来创建PDF文件。当文本是英文时,一切正常,但当我想转换波斯语文本时,输出就中断了。

这是包含波斯语和英语文本的示例文件:

代码语言:javascript
运行
复制
<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

我怎么才能解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 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

第二:获取、编译和安装。

代码语言:javascript
运行
复制
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的输出,您将知道模块位于哪个目录中。通常是:

代码语言:javascript
运行
复制
 /usr/lib64/php/modules/

第三:设置php以了解php.ini文件中的这个模块,在标题“动态扩展”下添加以下一行

代码语言:javascript
运行
复制
extension=phpwkhtmltox.so

第四:运行ldconfig

代码语言:javascript
运行
复制
$ ldconfig

第五:重新启动apache (或您正在使用的任何httpd )

最后:像这样使用它:对于这里的例子,我只是使用维基百科中的国际象棋开始页面,因为我没有您的示例html的url。

代码语言:javascript
运行
复制
<?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做的很好。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19952345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档