linux 安装 wkhtmltopdf 中文乱码或者空白解决方法

本文详细介绍了在Ubuntu12.04环境下安装wkhtmltopdf,解决OpenERP使用过程中遇到的wkhtmltopdf版本不兼容问题。包括使用sudo apt-get install命令安装默认版本,发现版本过低导致无法正确显示中文,进而通过下载编译好的Linux版本(32位和64位),解压、复制到/usr/bin目录,修改所有者和权限,最终测试成功并验证wkhtmltopdf已安装完成。此外,文章还提供了解决中文乱码或空白显示的方法,即在Linux服务器上复制Windows的simsun.ttc字体文件到/usr/share/fonts目录下。
部署运行你感兴趣的模型镜像

安装OpenERP8.0 之后,使用打印功能,提示没有wkhtmltopdf,只能以html预览。

在Ubuntu 12.04 安装wkhtmltopdf

sudo apt-get install wkhtmltopdf

提示OpenERP需要至少wkhtmltopdf 0.12.0,检查安装的wkhtmltopdf的版本

wkhtmltopdf -V

只到 0.8.x,google wkhtmltopdf发现,wkhtmltopdf的主机已经迁移到http://wkhtmltopdf.org/downloads.html,Ubuntu的源无法更新。wkhtmltopdf有编译好的Linux版本,找到http://wkhtmltopdf.org/downloads.html中对应的版本,查看打包文件的URL,下载编译好的版本:
32位版本:

wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-linux-i386_0.12.0-03c001d.tar.xz

64为版本:

wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz

解压缩下载到的文件:

tar -vxf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz

得到一个目录wkhtmltox,把wkhtmltopdf复制到/usr/bin目录,更改所有者,并增加可执行属性

 

sudo cp wkhtmltox/bin/wkhtmltopdf /usr/bin/
sudo chown root:root /usr/bin/wkhtmltopdf
sudo chmod +x /usr/bin/wkhtmltopdf
测试一下 

wkhtmltopdf http://www.baidu.com /opt/baidu.pdf

"Done"表明顺利完成,当前目录下出现一个baidu.pdf,打开,正是百度首页。
至此wkhtmltopdf已顺利安装完成,从OpenERP客户端,测试打印功能。
OK通过!
中文乱码或者空白解决方法
如果wkhtmltopdf中文显示空白或者乱码方框
打开windows c:\Windows\fonts\simsun.ttc拷贝到linux服务器/usr/share/fonts/目录下,再次生成pdf中文显示正常

您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

Traceback (most recent call last): File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\site-packages\pdfkit\configuration.py", line 35, in __init__ with open(self.wkhtmltopdf) as f: FileNotFoundError: [Errno 2] No such file or directory: 'C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:\PyCharm\pythonProject1031\出账程序\缴费通知单-康桥漕河泾2.py", line 175, in <module> create_bill_pdf(bill_df.sort_values("计量点名称"), tax_rate=0.13) File "E:\PyCharm\pythonProject1031\出账程序\缴费通知单-康桥漕河泾2.py", line 170, in create_bill_pdf html_to_pdf("bill_{}.html".format(sn), File "E:\PyCharm\pythonProject1031\出账程序\utils.py", line 39, in html_to_pdf wkhtmltopdf_config = pdfkit.configuration(wkhtmltopdf=wkhtmltopdf_exe_path) File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\site-packages\pdfkit\api.py", line 86, in configuration return Configuration(**kwargs) File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\site-packages\pdfkit\configuration.py", line 38, in __init__ raise IOError('No wkhtmltopdf executable found: "%s"\n' OSError: No wkhtmltopdf executable found: "C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe" If this file exists please check that this process can read it or you can pass path to it manually in method call, check README. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf
06-21
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值