我需要能够水印一个文档是从一个模板创建的。我现在有以下代码:
# Note: the raw PDF text (body variable below) is sent from a remote server.
Prawn::Document.new(:template => StringIO.new(body), :page_size =>
'A4') do |document|
# ... including other pages and sections to the template here ...
# watermark
d.page_count.times do |i|
d.go_to_page i
d.stroke_line [d.bounds.left, d.bounds.bottom], [d.bounds.right, d.bounds.top]
d.draw_text "Watermark", :rotate => 45, :at => [100,100], :size => 100
end
end这是因为一些我无法理解的原因而忽略了模板化的页面。现在这里的情节变得更复杂了:如果服务器添加了一个水印,那么这个代码就会像预期的那样工作(例如,在非对虾生成的页面上直接添加Ruby代码=没有叠加文本,但是水印可以在水印前的模板上工作)。我唯一的猜测是,有一些方法可以创建一个z-索引/层的服务器正在做,但对虾本身不能。
以下是完成PDF生成本身的服务器代码的一部分,它使用iText执行水印操作:
PdfStamper stamper = new PdfStamper(...);
PdfContentByte over = stamper.GetOverContent(i + 1);
over.BeginText();
over.SetTextMatrix(20, 40);
over.SetFontAndSize(bf, 20);
over.SetColorFill(new Color(97, 150, 58));
over.ShowTextAligned(Element.ALIGN_CENTER,
watermarkText,
document.PageSize.Width / 2,
document.PageSize.Height / 2,
55);
over.EndText();
over.Stroke();如果运行之前,我可以使用原始数据的虾我可以水印,去数字。
所以我的问题是:
,
GetOverContent()吗?:template和StringIO的情况下将原始的PDF数据输入到对虾中?(我看到了#add_content方法,但这不起作用)TL;DR:我需要将文本浮动在对虾模板文本之上,a la水印文档。
任何见解或途径,我可以研究,将不胜感激。如果这没有意义,我可以澄清。
发布于 2013-11-17 13:13:01
你可以试着在文件上加盖印花。
create_stamp("watermark") do
rotate(30, :origin => [-5, -5]) do
stroke_color "FF3333"
stroke_ellipse [0, 0], 29, 15
stroke_color "000000"
fill_color "993333"
font("Times-Roman") do
draw_text "Watermark", :at => [-23, -3]
end
fill_color "000000"
end
end
stamp_at "watermark", [210, 210] 发布于 2019-09-08 18:50:31
create_stamp("stamp") do
fill_color "cc0000"
text_rendering_mode(:fill_stroke) do
transparent(0.5){
text_box "WATERMARK",
:size => 50,
:width => bounds.width,
:height => bounds.height,
:align => :center,
:valign => :center,
:at => [0, bounds.height],
:rotate => 45,
:rotate_around => :center
}
end
end
repeat (:all) do
stamp("stamp")
endhttps://stackoverflow.com/questions/6125587
复制相似问题