PDF大虾:图像覆盖文本的问题
我想在每个页面上放置一个图像作为背景。这是我的代码:
Prawn::Document.generate("#{Rails.root.to_s}/public/#{filename}.pdf", :page_size => [576,576], :left_margin => 50,:right_margin => 50, :page_layout => :portrait, :skip_page_creation => true, :skip_encoding => true ) do |pdf|
pdf.repeat :all do
pdf.image open(APP_CONFIG['site_url']+"/images/pdf/bg_blank_high.jpg"), :at => [-pdf.bounds.absolute_left, pdf.bounds.absolute_top], :width => 576, :height => 576
end
pdf.start_new_page(:margin => [75,50,50,50])
pdf.fill_color "8c8464"
pdf.text story.contents, :size => 12, :align => :left, :leading => 3
end
问题是 - 图像覆盖所有页面中的文本。
有没有办法将文本放在图像上或使图像“发送到后面”或任何其他想法?
I want to put an image as a background on every page. This is my code :
Prawn::Document.generate("#{Rails.root.to_s}/public/#{filename}.pdf", :page_size => [576,576], :left_margin => 50,:right_margin => 50, :page_layout => :portrait, :skip_page_creation => true, :skip_encoding => true ) do |pdf|
pdf.repeat :all do
pdf.image open(APP_CONFIG['site_url']+"/images/pdf/bg_blank_high.jpg"), :at => [-pdf.bounds.absolute_left, pdf.bounds.absolute_top], :width => 576, :height => 576
end
pdf.start_new_page(:margin => [75,50,50,50])
pdf.fill_color "8c8464"
pdf.text story.contents, :size => 12, :align => :left, :leading => 3
end
The problem is - image overrides the text in all pages.
Is there any way to put text over the image or make image 'send to back' or any other ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来重复块中的代码是在文本渲染后调用的,因此将其放在文本的“上方”。
提供的代码片段有效,因为它只涉及单个图像。
可能对你有用。但它只提供低分辨率(72 dpi)图像。
有一个允许设置背景图像分辨率的拉取请求:
https://github.com/sandal/prawn/pull/292
It seems that the code in the repeat-block is called after the text is rendered, thus putting it 'above' the text.
The code snippet provided works because it just concerns a single image.
Might work for you. But it only provides low_res (72 dpi) images.
There is a pull request for allowing the resolution to be set for background images:
https://github.com/sandal/prawn/pull/292
在 Prawn 手册中,他们给出了一个被文本覆盖的图像的示例:
因此,据我所知,这可能是您构建文档的方式或光标放置的问题。
In the Prawn manual they give this as an example of an image covered by text:
So from what I can tell this might be a problem with how you are constructing the document or perhaps your cursor placing.