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部署,记得相应的操作是在容器里边,而不是宿主机上。)
sudo mkdir -p /usr/share/fonts/winFonts
sudo cp /home/username(用户名)/fonts/Yahei.ttf /usr/share/fonts/winFonts/
sudo chmod 644 /usr/share/fonts/winFonts/Yahei.ttf
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
root@ubuntu:/usr/share/fonts/winFonts# mkfontscale The program 'mkfontscale' is currently not installed. You can install it by typing: apt install xfonts-utils
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 mkfontdir (创建雅黑字体的fonts.dir文件,它用来控制字体粗斜体产生)
sudo fc-cache -fv (建立字体缓存信息,也就是让系统认识认识雅黑)