Wicked PDF无法使用页眉页脚问题求助(Ubuntu 14.04环境)
针对Ubuntu 14.04下Wicked PDF页眉页脚问题的解决方案
1. 更换带Qt补丁的wkhtmltopdf版本
你遇到的参数不支持问题,核心是当前wkhtmltopdf_binary 0.12.5.4未带Qt补丁,导致页眉页脚相关参数被忽略。
- 卸载现有gem:
gem uninstall wkhtmltopdf_binary - 安装带补丁的版本:执行
gem install wkhtmltopdf_binary -v 0.12.5.4 -- --with-patched-qt - 或者直接在Ubuntu系统中手动安装带补丁的二进制包:下载对应Ubuntu 14.04的patched Qt版wkhtmltopdf deb包,安装后在wicked_pdf配置里指定路径:
WickedPdf.config = { exe_path: '/usr/local/bin/wkhtmltopdf' # 替换为实际安装路径 }
2. 修正use_xvfb配置并验证参数传递
如果保留现有版本,检查参数是否正确传递:
- 确保wicked_pdf配置中完整设置页眉页脚参数,示例:
WickedPdf.config = { use_xvfb: true, header: { html: { template: 'layouts/pdf_header.html' }, spacing: 10 }, footer: { html: { template: 'layouts/pdf_footer.html' } } }
- 先直接用命令行测试:
xvfb-run --server-args="-screen 0 1024x768x24" wkhtmltopdf --header-html ./pdf_header.html --footer-html ./pdf_footer.html input.html output.pdf,如果命令行能生成页眉页脚,再排查wicked_pdf的参数传递是否有误。
3. 降级到稳定版本(备选)
若上述方法无效,可降级到wkhtmltopdf 0.12.4版本,该版本预编译包默认带Qt补丁,对页眉页脚支持更可靠:
- 修改Gemfile:
gem 'wkhtmltopdf_binary', '~> 0.12.4' - 执行
bundle install后重启应用测试。
内容的提问来源于stack exchange,提问作者Devi Firdaus
相关产品推荐
相关产品推荐

