版權聲明:本文爲博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接和本聲明。
本文鏈接:https://blog.csdn.net/wljk506/article/details/77650652
因爲涉及到賬單,並且要生成PDF併發送郵件,所以試用了好多轉換PDF的都不成功,基本上都是格式錯亂,唯一就是 wkhtmltopdf 滿足 我的需求
https://wkhtmltopdf.org/downloads.html
這裏下載是 linux 64
安裝環境
CENTOS 7.3下載及安裝
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
風.foxiswho
解壓縮
tar -Jxv -f **.tar.xz
或者
xz -d **.tar.xz
tar -xv -f **.tar
移動文件目錄到相關位置,例如 移動文件夾到/www/lanmps/目錄下
mv wkhtmltox /www/lanmps/wkhtmltox
建立軟連接,
ln -s /www/lanmps/wkhtmltox/wkhtmltoimage /usr/local/bin/wkhtmltoimage #轉換成圖片
ln -s /www/lanmps/wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf #轉換成 PDF
PHP 中使用 shell_exec 執行
shell_exec("wkhtmltopdf http://www.lanmps.com lanmps.com.pdf")
shell 中執行
wkhtmltopdf http://www.lanmps.com lanmps.com.pdf
中文字體
服務器上必須安裝字體
http://blog.csdn.net/wlwlwlwl015/article/details/51482065
新建字體目錄
/usr/share/fonts/chinese
chmod -R 755 /usr/share/fonts/chinese
上傳字體宋體,你自己電腦中的字體,或者網上下載的也可以,字體如下
simsun.ttc # 宋體 http://down7.pc6.com/qd3/simsun.zip 記得解壓縮
simsun.ttf
接下來需要安裝ttmkfdir來搜索目錄中所有的字體信息,並彙總生成fonts.scale文件,輸入命令:
yum -y install ttmkfdir
然後執行ttmkfdir命令即可:
ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
最後一步就是修改字體配置文件了,首先通過編輯器打開配置文件:
vim /etc/fonts/fonts.conf
可以看到一個Font list,即字體列表,在這裏需要把我們添加的中文字體位置加進去:加入到類似的位置
<dir>/usr/share/fonts/chinese</dir>
然後輸入:wq保存退出,最後別忘了刷新內存中的字體緩存,這樣就不用reboot重啓了:
字體緩存
fc-cache
查看字體
fc-list |grep SimSun
可以看到已經成功安裝上了中文字體,
中文編碼解決
http://aiilive.blog.51cto.com/1925756/1340243/
Q
error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory
./bin/wkhtmltopdf: error while loading shared libraries: libXrender.so.1: cannot open shared object file: No such file or directory
解決方法:
yum install -y libXrender
http://blog.csdn.net/wlwlwlwl015/article/details/51482065
————————————————
版權聲明:本文爲CSDN博主「風.foxwho」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/fenglailea/article/details/77650652