2011-01-05 51 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文件。