如何使用rails 3中的IO.popen和wkhtmltopdf创建带页眉/页脚的PDF

har*_*h4u 2 pdf-generation wkhtmltopdf ruby-on-rails-3

我想使用IO.popen命令创建PDF文件wkhtmltopdf.我wkhtmltopdf使用以下代码使用命令成功创建了pdf文件:

IO.popen('wkhtmltopdf '+ source_url.to_s + ' ' + Rails.root.to_s + '/app/assets/pdfs/' + file_to_download) do
end
Run Code Online (Sandbox Code Playgroud)

但我想使用相同的代码创建带页眉和页脚的PDF.我找不到这个解决方案,如果有人请发给我.

GBD*_*GBD 5

有一个选项--header-html&--footer-html可以在外部用你的命令提供html标题

1)html文件

wkhtmltopdf http://domain.com/pagetopdf.html --footer-html "footer.html" /path/to/folder/test.pdf
Run Code Online (Sandbox Code Playgroud)

2)您也可以将文本传递到页脚和标题,如下所示

wkhtmltopdf http://domain.com/pagetopdf.html --footer-center "Hello Footer" /path/to/folder/test.pdf
Run Code Online (Sandbox Code Playgroud)

还有很多其他选项可供使用,请参阅此链接