2010-08-04 86 views
7

是否有更簡單的代碼來設置由PRAWN插件生成的PDF文件中的所有N頁上的頁眉和頁腳。Rails PDF Prawn頁眉和頁腳

的代碼將被寫在一個

report.pdf.prawn」文件,該文件是PDF查看頁面

以下的直接編碼區是該文件中的代碼report.pdf.prawn

pdf.text "Creation Date " + Time.now.strftime('%d-%m-%Y') 
pdf.text "Page Count:#{pdf.page_count}" 

所有我想要的是這些價值定位到頁眉和/或頁腳左側和右側。

任何建議都會有幫助。

+0

你有沒有看到關於這個問題的建議嗎?他們可能會做你所問的聽起來像這樣:http://stackoverflow.com/questions/2695019/header-and-footer-in-prawn-pdf – jasonpgignac 2010-08-04 18:56:28

回答

4

非常感謝你爲你的concern.I得到笏我從鏈接 想這是我做過什麼,使其工作..

creation_date = Time.now.strftime('%d-%m-%Y') 

page_count=pdf.page_count 

powered_by = @companylogo 

# will get @companylogo from the controller 

Prawn::Document.generate("show_sd_report_pdf.pdf", :skip_page_creation => true) do 

pdf.page_count.times do |i| 

pdf.go_to_page(i+1) 

pdf.draw_text "Creation Date : " + creation_date, :at=>[590,530] 

pdf.draw_text "Page Count : #{i+1}/#{pdf.page_count}", :at=>[1,1] 

pdf.draw_text "Powered by : ", :at=>[590,1] 

pdf.image powered_by, :width => 25, :at=>[670,15] 

end 

end 

**or insted of draw_text** 

pdf.bounding_box([1,540], :width => 300, :height => 300) do 

pdf.text "Username : " + user_name 

end