邪恶的pdf不呈现页眉/页脚 [英] Wicked pdf not rendering header/footer

查看:66
本文介绍了邪恶的pdf不呈现页眉/页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 wicked_pdfhtml<生成 pdf/code> 在我的 rails 项目中.它正在呈现 template 但我无法打印 header/footer 部分.下面是我的代码,只打印 template 部分

I am using wicked_pdf for generating pdf from html on my rails project. It is rendering template but I could not manage to print header/footer sections. Below is my code that print only template section

render pdf: "pdf_name",
               layout: 'application',
               template: 'reports/show',
               formats: [:html],
               margin: { top: 10, bottom: 10, left: 10, right: 10 },
               disable_javascript: true,
               show_as_html: params[:debug],
               header: {
                 html: { template: 'shared/header' },
                 spacing: 10
               },
               footer: {
                 html: { template: 'shared/footer' },
                 spacing: 30,
                 line: true
               }

如果我尝试使用 WickedPdf.new.pdf_from_string render_to_string 它显示 Failed to load PDF document 错误即使是简单的 WickedPdf.new.pdf_from_string('<html><body><h1>你好!</h1></body></html>') 不起作用.

If I try to use WickedPdf.new.pdf_from_string render_to_string it show Failed to load PDF document error even simple WickedPdf.new.pdf_from_string('<html><body><h1>Hello There!</h1></body></html>') does not work.

我尝试使用 render_to_string_with_wicked_pdf, render_with_wicked_pdf 但没有成功.我的 Rails 版本是 3.2.19wicked_pdf gem 版本是 1.1.0wkhtmltopdf 版本是 wkhtmltopdf-0.13.0-alpha-7b36694_linux-trusty-amd64.deb.我也尝试使用 wkhtmltopdf 版本 0.12.0.

I have tried to use render_to_string_with_wicked_pdf, render_with_wicked_pdf but did not success. My Rails version is 3.2.19, wicked_pdf gem version is 1.1.0 and wkhtmltopdf version is wkhtmltopdf-0.13.0-alpha-7b36694_linux-trusty-amd64.deb. I also tried to use wkhtmltopdf version 0.12.0.

我的问题是

  1. 为什么我的上述实现不起作用?
  2. 为什么 pdf_from_string 不起作用?
  1. Why my above implementation does not work?
  2. Why pdf_from_string does not work?

感谢任何形式的帮助.谢谢.

Any kind of help is appreciated. Thanks.

推荐答案

使用带有补丁的 qt 构建的 wkhtmltopdf 版本,它可以正确地与页脚和页眉配合使用.

Use a version of wkhtmltopdf built with patched qt, which properly works with footer and header.

$ wget http://download.gna.org/wkhtmltopdf/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
$ tar xf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
$ sudo mv wkhtmltox /usr/local/share/
$ sudo update-alternatives --install /usr/local/bin/wkhtmltopdf wkhtmltopdf /usr/local/share/wkhtmltox/bin/wkhtmltopdf 1005

检查版本:

$ wkhtmltopdf --version

应该说:

wkhtmltopdf 0.12.4 (with patched qt)

测试一下:

$ wkhtmltopdf --footer-center 'footer' http://www.google.com google.pdf

你也可以安装 wkhtmltoimage:

you can also install the wkhtmltoimage:

$ sudo update-alternatives --install /usr/local/bin/wkhtmltoimage wkhtmltoimage /usr/local/share/wkhtmltox/bin/wkhtmltoimage 1005

您可以使用这样的脚本:wkhtmltox installer

you can use a script like this: wkhtmltox installer

这篇关于邪恶的pdf不呈现页眉/页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆