通过 chrome headless 生成的 PDF 上的字体问题

问题描述 投票:0回答:2

在我的项目(PHP)中,我使用 headless chrome 从 HTML 文件生成 PDF。我使用了这个命令:

google-chrome --headless --disable-gpu --print-to-pdf-no-header --no-margins --print-to-pdf=example.pdf example.html

它工作完美,但由于某些原因,某些结果 pdf 上没有任何文本。 PDF + HTML 文件链接:https://disk.yandex.ru/d/Jw3GlM_h3Zf_QA

看起来像这样:

命令输出:

mkdir:无法创建目录“/srv/projects//.local”:权限被拒绝 | touch:无法触摸“/srv/projects//.local/share/applications/mimeapps.list”:没有这样的文件或目录 | [1019/033555.836260:错误:nss_util.cc(53)] 无法创建 /srv/projects/.pki/nssdb 目录。 | [1019/033556.904768:INFO:headless_shell.cc(619)]写入文件/srv/projects/aa/api/reports/19_10_2021/B258C488D7ED8AF8/90589391634614272.pdf

我能做什么来解决这个问题?

pdf-generation google-chrome-headless
2个回答
1
投票

为了其他人在旧问题上登陆这里的利益:-

我对无头打印该文件没有任何问题,但您添加了一个未知的开关(--无边距),并且没有添加可能有帮助的开关,例如。

google-chrome --headless --disable-gpu --print-to-pdf-no-header --run-all-compositor-stages-before-draw --print-to-pdf=example.pdf example.html

其他可以帮助避免运行时问题的开关是

--disable-extensions --disable-popup-blocking --disable-checker-imaging
,对于一些调试,您可以尝试
 --enable-logging

但是错误消息暗示这是一个

mkdir: cannot create directory
与 chrome 或无头打印无关的权限问题


0
投票

这可能是关于从 Chrome Headless 打印到 PDF 时丢失字体的这篇文章的重复,在这种情况下,解决方案是给该过程更多的时间,在命令中添加以下标志:

--virtual-time-budget=10000

© www.soinside.com 2019 - 2024. All rights reserved.