2011-01-05 86 views
12

这是我到目前为止,但我需要设置页边距:如何设置红宝石虾的利润率?

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 
+0

值得一提的是,您正在专门设置页边距。 – Tass 2014-01-22 18:04:10

回答

18

Prawn::Document.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

+0

谢谢,我无法按照指示,你做得更清楚 – Angela 2011-01-05 16:32:47

+0

你是怎么弄出来的,我检查了这个文件,我仍然不知道该怎么做...应该只是设置:margin => [ 0.5,0.5,0.5,0.5]如果它全部是0.5英寸?我需要使用英寸吗? [0.5英寸]? – Angela 2011-01-11 02:42:21

+4

'[0.5英寸]'是给定属性的默认设置。所以,如果你没有明确地为':margin'设置一个值,它将在所有4边都默认为半英寸。 如果您想覆盖任何默认值,您应该提供一个与您想要的点数相对应的数字。每英寸有72点。这有点令人困惑,因为默认值以英寸为单位提供,而您以点为单位设置值。如果您将默认值设为'[36分]' – 2011-01-13 03:59:09

4

只是增加了知识的殿堂在这里,但如果你来这里寻找使用Prawn Label 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 

如果你使用的虾隐版本取下.bounding_box和.bounds的PDF文件。