使用wkhtmltopdf生成PDF失败,返回退出代码1求助
问题日志
True Html to PDF conversion of '-' failed. Wkhtmltopdf output: Loading pages (1/6) [> ] 0% [======> ] 10% QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files [===========> ] 19% [==============> ] 24% [===================> ] 33% libpng warning: iCCP: known incorrect sRGB profile [============================================================] 100% QPainter::begin(): Returned false Error: Unable to write to destination Exit with code 1, due to unknown error.
此前使用wkhtmltopdf生成PDF一切正常,突然出现上述错误,共享存储路径无法生成目标文件,已检查访问权限及相关配置,未发现变动。
排查与解决步骤
- 验证目标路径实际可写性:手动在共享存储的目标路径创建测试文件,执行
touch /your/target/path/test.pdf,若失败则说明存储挂载存在隐性问题(如NFS挂载失效、存储配额耗尽),需联系存储管理员排查。 - 补全本地资源路径Schema:HTML中引用的本地图片、CSS等资源,需添加
file://前缀,例如将/assets/img/logo.png改为file:///assets/img/logo.png,避免路径解析异常。 - 修复图片ICC配置:针对日志中的libpng警告,用ImageMagick处理问题图片:
convert problematic.png -strip fixed.png,替换原图片后再尝试生成。 - 强制使用绝对输出路径:调用wkhtmltopdf时指定完整绝对路径作为输出目标,避免因进程工作目录变化导致路径解析错误,例如:
wkhtmltopdf input.html /mnt/shared_storage/result.pdf。 - 重启服务进程:若通过后台服务调用wkhtmltopdf,重启服务释放异常持有的资源后再测试。
内容的提问来源于stack exchange,提问作者LPK
相关产品推荐
相关产品推荐

