This is what I have so far, but I need to set margins:
这是我目前所拥有的,但我需要设置边界:
def send_fax
contact = Contact.find_by_id(self.contact_id)
pdf = Prawn::Document.new
pdf.font "Times-Roman"
pdf.move_down(20)
pdf.text "ATTN: #{contact.first_name} #{contact.last_name}", :size => , :style => :bold
pdf.text "RE: #{self.subject}"
pdf.move_down(20)
pdf.text "#{self.body}"
OutboundMailer.deliver_fax_email(contact, self, pdf)
end
2 个解决方案
#1
21
Prawn::Document.new( :margin => [0,0,0,0] )
虾:文档。new(:margin => [0,0,0,0])
:margin: Sets the margin on all sides in points [0.5 inch]
:left_margin: Sets the left margin in points [0.5 inch]
:right_margin: Sets the right margin in points [0.5 inch]
:top_margin: Sets the top margin in points [0.5 inch]
:bottom_margin: Sets the bottom margin in points [0.5 inch]
http://rdoc.info/github/sandal/prawn/master/Prawn/Document
http://rdoc.info/github/sandal/prawn/master/Prawn/Document
#2
4
Just adding to the pantheon of knowledge here, but in case you came here looking to do this using the Prawn Label gem, you can't set the document margin this way. You'll have to do a work around. Here's a quick and flexible snippet for creating a bounding box with a uniform pad that sits inside the document bounding box.
这里只是增加了知识的万神殿,但是如果你想用虾标签gem来做这个,你不能这样设置文档的页边距。你得做点什么。这里有一个快速而灵活的代码片段,用于创建一个具有统一填充的边框框,该边框位于文档边框内。
pad = 5
pdf.bounding_box([pad, pdf.bounds.height - pad], :width => pdf.bounds.width - (pad * 2), :height => pdf.bounds.height - (pad * 2)) do
#Draw all your content in this block and it will be padded uniformly by 5
end
Remove the pdf from .bounding_box and .bounds if you're using an Implicit version of Prawn.
如果您使用的是内隐版本的对虾,则从.bounding_box和.bounds中删除pdf。
#1
21
Prawn::Document.new( :margin => [0,0,0,0] )
虾:文档。new(:margin => [0,0,0,0])
:margin: Sets the margin on all sides in points [0.5 inch]
:left_margin: Sets the left margin in points [0.5 inch]
:right_margin: Sets the right margin in points [0.5 inch]
:top_margin: Sets the top margin in points [0.5 inch]
:bottom_margin: Sets the bottom margin in points [0.5 inch]
http://rdoc.info/github/sandal/prawn/master/Prawn/Document
http://rdoc.info/github/sandal/prawn/master/Prawn/Document
#2
4
Just adding to the pantheon of knowledge here, but in case you came here looking to do this using the Prawn Label gem, you can't set the document margin this way. You'll have to do a work around. Here's a quick and flexible snippet for creating a bounding box with a uniform pad that sits inside the document bounding box.
这里只是增加了知识的万神殿,但是如果你想用虾标签gem来做这个,你不能这样设置文档的页边距。你得做点什么。这里有一个快速而灵活的代码片段,用于创建一个具有统一填充的边框框,该边框位于文档边框内。
pad = 5
pdf.bounding_box([pad, pdf.bounds.height - pad], :width => pdf.bounds.width - (pad * 2), :height => pdf.bounds.height - (pad * 2)) do
#Draw all your content in this block and it will be padded uniformly by 5
end
Remove the pdf from .bounding_box and .bounds if you're using an Implicit version of Prawn.
如果您使用的是内隐版本的对虾,则从.bounding_box和.bounds中删除pdf。