python: linux服务器上weasyprint生成pdf时中文变乱码

一,原因:

目标服务器上缺少需要的中文字体

二,解决:

把simhei和simsun两种字体:黑体和宋体
上传到linux服务器

设置权限

# chmod 644 -R /usr/share/fonts/simhei/
# chmod 644 -R /usr/share/fonts/simsun/

刷新字体使生效:

# fc-cache -fv
Font directories:
        /usr/share/fonts
        /usr/share/X11/fonts/Type1
        /usr/share/X11/fonts/TTF
        /usr/local/share/fonts
        /root/.local/share/fonts
        /root/.fonts
        /usr/share/fonts/adobe-source-code-pro
        /usr/share/fonts/cantarell
        /usr/share/fonts/simhei
        /usr/share/fonts/simsun
/usr/share/fonts: caching, new cache contents: 0 fonts, 4 dirs
/usr/share/fonts/adobe-source-code-pro: caching, new cache contents: 14 fonts, 0 dirs
/usr/share/fonts/cantarell: caching, new cache contents: 11 fonts, 0 dirs
/usr/share/fonts/simhei: caching, new cache contents: 1 fonts, 0 dirs
/usr/share/fonts/simsun: caching, new cache contents: 2 fonts, 0 dirs
/usr/share/X11/fonts/Type1: skipping, no such directory
/usr/share/X11/fonts/TTF: skipping, no such directory
/usr/local/share/fonts: skipping, no such directory
/root/.local/share/fonts: skipping, no such directory
/root/.fonts: skipping, no such directory
/usr/share/fonts/adobe-source-code-pro: skipping, looped directory detected
/usr/share/fonts/cantarell: skipping, looped directory detected
/usr/share/fonts/simhei: skipping, looped directory detected
/usr/share/fonts/simsun: skipping, looped directory detected
/usr/lib/fontconfig/cache: cleaning cache directory
/root/.cache/fontconfig: not cleaning non-existent cache directory
/root/.fontconfig: not cleaning non-existent cache directory
/usr/bin/fc-cache-64: succeeded

 

posted @ 2026-05-04 16:06  刘宏缔的架构森林  阅读(3)  评论(0)    收藏  举报