大虾: 静态头可以包含模型特定信息吗?
我正在 Rails 和 Prawn 中构建一个 PDF 导出功能,我想在一个 PDF 中导出多个“公司”。一家公司通常有 2-3 个页面。现在,在导出单个公司时,可以使用 pdf.repeat(:all)。不过,我希望根据公司在标题中更改徽标。一个简单的代码示例是:
@companies.each do |c|
pdf.repeat(:all) do
pdf.image company.logo.url(:thumb), :at => [0,520]
end
end
有办法做到这一点吗?我查看了相关主题,例如 Prawn PDF 中的页眉和页脚,但它对我没有帮助,因为我无法看到哪个公司在生成后属于哪个页面。
I'm building a PDF export function in Rails and Prawn where I want to export a number of "Companies" in one single PDF. A company usually flows over 2-3 pages. Right now when exporting a single Company this works with a pdf.repeat(:all). I want the logo to change in the header based on the Company though. A simple code example is:
@companies.each do |c|
pdf.repeat(:all) do
pdf.image company.logo.url(:thumb), :at => [0,520]
end
end
Is there a way of doing this? I have looked at related topics, like header and footer in Prawn PDF but it won't help me since I can't see what Company belongs to which page after it's generated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很棒的自文档手册(http://cloud.github.com/downloads/sandal/prawn/manual.pdf)包含此代码(第 105 页),这可能会有所帮助:
lambda 或动态应该可以解决问题对于您来说,前提是您知道哪家公司从哪个页面开始。
如果您不知道每个公司的页数,请为每个公司制作一个 pdf 并合并它们。手册,第 109 页:
在最坏的情况下,您最终会一次合并两个。
您还可以检查带有
:filter
选项的pdf.number_pages
是否适用于图像(如果您尚未尝试过)。我完全不知道它是否有效,而且我现在没有机会检查它。The awesome self-documenting manual (http://cloud.github.com/downloads/sandal/prawn/manual.pdf) contains this code (page 105), which may be of help:
Either lambda or the dynamic should do the trick for you, provided that you know what company starts at what page.
In case you do not know about the number of pages per company, make a pdf for each of them and merge them. Manual, page 109:
In the worst case you will end up with merging two at a time.
You might also check if
pdf.number_pages
with:filter
option works with images (if you have not tried it yet). I have absolutely no idea if it works and I have no chance to check it right now.不确定这是否有帮助,但 WickedPDF 是虾的良好替代品。
Not sure if this'll help but WickedPDF is a good alternative to Prawn.