odoo开发笔记 -- wkhtmltox打印不显示中文 --ubuntu字体安装

摘要:
Wkhtmltox是一个开源软件包,可将web内容转换为PDF。它通常嵌套在网页中进行打印。对于Windows系统,字体文件的目录通常位于C:WindowsFonts(注意2:如果您的程序是使用Docker部署的,请记住相应的操作在容器中,而不是在主机上。

wkhtmltox 是一个开源的将网页内容转换成PDF的软件包,常嵌套在网页页面里边做打印功能。

ubuntu16.04 安装wkhtmltopdf参考:https://www.cnblogs.com/hellojesson/p/11206184.html

以微软雅黑字体为例(其他的宋体、黑体等点阵字体都一样的),我们的雅黑字体文件是:Yahei.ttf(放在自己的主目录下)(在widows目录的Fonts目录下找需要的字体)
由于我是双系统,我直接从Win7中复制了 msyh.ttf和msyhbd.ttf 到Ubuntu下;如果在docker容器里边,需要在将字体复制到容器里边。

windows系统,字体文件的目录一般在:C:WindowsFonts

开始操作:

(注1:这里操作系统以ubuntu系统为例,其他系统操作原理一样,请做相应调整。)

(注2:如果你的程序用了Docker部署,记得相应的操作是在容器里边,而不是宿主机上。)

1. 在/usr/share/fonts/下新建文件夹 如:winFonts目录,准备把从windows下拷贝过来的字体都放在这个目录里,这里就是把雅黑字体Yahei.ttf 放进来
sudo mkdir -p /usr/share/fonts/winFonts
 
2. 然后将字体文件拷贝到此文件夹下
sudo cp /home/username(用户名)/fonts/Yahei.ttf /usr/share/fonts/winFonts/
 
3. 然后,改变权限:
sudo chmod 644 /usr/share/fonts/winFonts/Yahei.ttf 
(改成755也没问题的,但起码要444,修改雅黑字体文件的权限为644,即当前用户读写,当前组用户只读,其他用户只读)

4. 开始安装:
root@hellojesson:/usr/share/fonts/winFonts# chown root msyh*
root@hellojesson:/usr/share/fonts/winFonts# ls -l
total 35524
-rwxrwxr-x 1 root root 21767952 Oct 21 04:53 msyh.ttf
-rwxrwxr-x 1 root root 14602860 Oct 21 04:52 msyhbd.ttf
root@hellojesson:/usr/share/fonts/winFonts# 
root@hellojesson:/usr/share/fonts/winFonts# 
root@hellojesson:/usr/share/fonts/winFonts# 
root@hellojesson:/usr/share/fonts/winFonts# 
root@hellojesson:/usr/share/fonts/winFonts# mkfontscale
root@hellojesson:/usr/share/fonts/winFonts# mkfontdir
root@hellojesson:/usr/share/fonts/winFonts# ls
fonts.dir  fonts.scale    msyh.ttf  msyhbd.ttf
root@hellojesson:/usr/share/fonts/winFonts# fc-cache -fv
/usr/share/fonts: caching, new cache contents: 0 fonts, 4 dirs
/usr/share/fonts/X11: caching, new cache contents: 0 fonts, 4 dirs
/usr/share/fonts/X11/75dpi: caching, new cache contents: 358 fonts, 0 dirs
/usr/share/fonts/X11/encodings: caching, new cache contents: 0 fonts, 1 dirs
/usr/share/fonts/X11/encodings/large: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/X11/misc: caching, new cache contents: 59 fonts, 0 dirs
/usr/share/fonts/X11/util: caching, new cache contents: 0 fonts, 0 dirs
/usr/share/fonts/truetype: caching, new cache contents: 0 fonts, 2 dirs
/usr/share/fonts/truetype/dejavu: caching, new cache contents: 6 fonts, 0 dirs
/usr/share/fonts/truetype/liberation: caching, new cache contents: 16 fonts, 0 dirs
/usr/share/fonts/type1: caching, new cache contents: 0 fonts, 1 dirs
/usr/share/fonts/type1/gsfonts: caching, new cache contents: 35 fonts, 0 dirs
/usr/share/fonts/winFonts: caching, new cache contents: 2 fonts, 0 dirs
/usr/X11R6/lib/X11/fonts: skipping, no such directory
/usr/local/share/fonts: caching, new cache contents: 0 fonts, 0 dirs
/root/.local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/usr/share/fonts: caching, new cache contents: 0 fonts, 4 dirs
/usr/X11R6/lib/X11/fonts: skipping, no such directory
/usr/local/share/fonts: caching, new cache contents: 0 fonts, 0 dirs
/root/.local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/var/cache/fontconfig: cleaning cache directory
/root/.cache/fontconfig: not cleaning non-existent cache directory
/root/.fontconfig: not cleaning non-existent cache directory
fc-cache: succeeded 
---异常处理1:执行mkfontscale报错: 处理 apt install xfonts-utils
root@ubuntu:/usr/share/fonts/winFonts# mkfontscale
The program 'mkfontscale' is currently not installed. You can install it by typing:
apt install xfonts-utils
---异常处理2:
root@ubuntu:/usr/share/fonts/winFonts# fc-cache -fv
The program 'fc-cache' is currently not installed. You can install it by typing:
apt install fontconfig

cd /usr/share/fonts/winFonts/

sudo mkfontscale (创建雅黑字体的fonts.scale文件,它用来控制字体旋转缩放)
sudo mkfontdir (创建雅黑字体的fonts.dir文件,它用来控制字体粗斜体产生)
sudo fc-cache -fv (建立字体缓存信息,也就是让系统认识认识雅黑)
 
5. 尝试打印相关网页页面:终端命令行执行
wkhtmltopdf https://www.baidu.com/ baidu.pdf
wkhtmltopdf https://www.taobao.com/ taobao.pdf
 
参考:
http://huqiji.iteye.com/blog/2278225
http://blog.csdn.net/shenshen123jun/article/details/17334857
http://blog.csdn.net/vmboys/article/details/54581369
http://www.laozuo.org/9998.html
http://www.cnblogs.com/kfx2007/p/5926467.html
http://wiki.ubuntu.org.cn/%E5%AD%97%E4%BD%93
http://blog.163.com/bjcclzw@126/blog/static/129968414201281124457883/
 

免责声明:文章转载自《odoo开发笔记 -- wkhtmltox打印不显示中文 --ubuntu字体安装》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇用layui实现下拉框select多选,取值thrift的使用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Ubuntu Linux启用root用户登录

Ubuntu Linux有一个与众不同的特点,那就是初次使用时,你无法作为root来登录系统,为什么会这样?这就要从系统的安装说起。对于其他Linux系统来 说,一般在安装过程就设定root密码,这样用户就能用它登录root帐户或使用su命令转换到超级用户身份。与之相反,Ubuntu默认安装时,并没有 给root用户设置口令,也没有启用root帐户。问题是...

关于linux免密登录的配置及ssh客户端基于私钥文件的登录

操作系统环境: CentOS Linux release 7.7.1908 (Core) 1、首先在linux服务器上,使用ssh-keygen命令生成密钥对文件(一直回车即可,默认使用rsa算法),如下所示       其中还支持的算法有dsa | ecdsa | ed25519 | rsa | rsa1,使用其他算法只需要使用-t选项指定即可    ...

(转载)Linux定时任务cron配置

(转载)http://blog.csdn.net/jbgtwang/article/details/7995801 实现linux定时任务有:cron、anacron、at等,这里主要介绍cron服务。 名词解释:    (1)cron是服务名称;    (2)crond是后台进程;    (3)crontab则是定制好的计划任务表; 软件包安装: 要使用...

SVN版本管理与大型代码上线

SVN版本管理与大型代码上线 一、SVN简介 SVN是近年来崛起的非常优秀的版本管理工具,是一个开源的版本控制系统,开发的代码版本,这些数据位置放置在一个中央资料档案库,很想一个普通的文件服务器或者FTP服务器与其他服务器不用的是,SVN会备份并记录每个文件每一次的修改更新变动,可以进行回滚操作,可以把任意一个时间点的档案恢复到想要的某一个旧的版本,也可...

sudo 有效用户 ID 不是 0,sudo 属于 root 并设置了 setuid 位吗?

【原因】 使用了这个命令:sudo chmod -R 777 /usr 【错误现象】 sudo: 有效用户 ID 不是 0,sudo 属于 root 并设置了 setuid 位吗? 【解决办法】 1、进入recovery模式,以root身份登录。 2、将文件系统重新挂载为rw,否则执行后续命令是可能出现Read-only file system错误,重新挂...

MySQL集群搭建

MySQL集群概述和安装环境 MySQL Cluster是MySQL适合于分布式计算环境的高实用、高冗余版本。Cluster的汉语是“集群”的意思。它采用了NDB Cluster 存储引擎,允许在1个 Cluster 中运行多个MySQL服务器。 MySQL Cluster 是一种技术,该技术允许在无共享的系统中部署“内存中”数据库的 Cluster...