Record the pitfalls of printing PDF files through custom labels. #7736
zly20129
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
Hi @zly20129 please keep any issues / discussions limited to English language on the github pages. While the project code is translated, these pages are not and the development team's common language is English. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Title: Record the pitfalls of printing PDF files through custom labels.
Related problem demonstration
Tags can be customized through HTML files, such as the official part QR code and text printing template provided below:
The text part is defined by the
.part
segment, where the first item:font-family
defines the set of fonts that can be used.But the default of these three fonts are purely English fonts, does not support the Chinese printout, which leads to the printing of labels when the Chinese content is blank, while the English content can be displayed, such as 【0805电阻】, the actual output to the PDF only 【0805】.
The reason for this problem is that the official Docker container does not have Chinese font support installed by default. Using
docker exec inventree-server fc-list :lang=zh
you can see that the output is empty, which means that none of the Chinese fonts are installed in the container.Since there is no font support, this results in no output - IMO, a solution idea can be constructed from this.
Solution (system is Ubuntu 20.04 Server):
sudo apt-get install ttf-wqy-microhei
andsudo apt-get install ttf-wqy-zenhei
on your operating system, and use these two commands to install Chinese open source fonts;fc-list :lang:zh
to check if the installation is successful, if the following result appears, the installation is successful;/usr/share/fonts/truetype/wqy/wqy-microhei.ttc' and
/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc' are the paths to the fonts that were installed by the two commands executed in step 1. Save this path temporarily;docker cp /usr/share/fonts/truetype/wqy/wqy-zenhei.ttc inventree-server:/usr/share/fonts/wqy-zenhei.ttc
anddocker cp /usr/share/fonts/wqy/microhei.ttc inventree-server:/usr/share/fonts/wqy-microhei.ttc
. fonts/truetype/wqy/wqy-microhei.ttc inventree-server:/usr/share/fonts/wqy-microhei.ttc` to copy each of the two fonts installed to your system into the containers;docker exec inventree-server fc-cache -fv /usr/share/fonts/wqy-zenhei.ttc
anddocker exec inventree-server fc-cache -fv /usr/share/fonts/ wqy-microhei.ttc
to install the two copied fonts into the server container environment;font-family:
paragraph of the.part
of the custom tag HTML file, addwqy-zenhei
orwqy-microhei
, which is the font to be used in the Chinese language, or, of course, you can add all of the two fonts in descending order of priority from front to back, with the formatting without any quotation marks but separated by commas. without any quotes, but separated by commas;P.S. Personally, I prefer the wqy-zenhei font.
Problems:
Note: This refers to the docker container updating environment variables and rebooting, not the normal system reboot of the server!
标题:记录通过自定义标签打印PDF文件输出的坑。
相关问题演示
标签可通过HTML文件实现自定义,例如官方提供的零件二维码+文本打印模板如下:
文本部分是由
.part
段定义的,这段里边第一项:font-family
定义了可以使用到的一系列字体。但是默认的这三个字体都是纯英文字体,不支持中文打印输出,这就导致了打印标签的时候中文内容是一片空白,而英文内容则可以显示,例如0805电阻,实际输出到PDF的只有0805。
出现这种问题的原因就是官方的Docker容器默认并没有安装中文字体支持,使用
docker exec inventree-server fc-list :lang=zh
可以看到输出为空,这说明容器中并没有安装任何一个中文字体。因为没有字体支持,所以导致没有输出——综上所述,可以由此构建解决思路。
解决方案(系统为Ubuntu20.04 Server):
sudo apt-get install ttf-wqy-microhei
和sudo apt-get install ttf-wqy-zenhei
,使用这两条指令安装中文开源字体;fc-list :lang:zh
查看是否安装成功,如果出现以下结果,说明安装成功;/usr/share/fonts/truetype/wqy/wqy-microhei.ttc
和/usr/share/fonts/truetype/wqy/wqy-zenhei.ttc
分别是第1步中所执行的两条指令所安装字体的路径,暂存这个路径;docker cp /usr/share/fonts/truetype/wqy/wqy-zenhei.ttc inventree-server:/usr/share/fonts/wqy-zenhei.ttc
和docker cp /usr/share/fonts/truetype/wqy/wqy-microhei.ttc inventree-server:/usr/share/fonts/wqy-microhei.ttc
,把安装到系统的两个字体分别复制到容器内;docker exec inventree-server fc-cache -fv /usr/share/fonts/wqy-zenhei.ttc
和docker exec inventree-server fc-cache -fv /usr/share/fonts/wqy-microhei.ttc
,将复制过去的两个字体安装到服务器容器环境中;.part
的font-family:
段中,加入wqy-zenhei
或者wqy-microhei
,加入哪入中文用的就是哪种字体,当然,也可以按照从前到后优先级下降的顺序将两个全加进去,格式不用加任何的引号,但要加逗号分隔;附:个人更喜欢wqy-zenhei字体。
存在的问题:
注意:这里指的是docker容器更新环境变量并重启,而不是服务器的普通系统重启!
Beta Was this translation helpful? Give feedback.
All reactions