2012-08-06 23 views
2

我需要在pdf的每一頁上顯示重複的圖像。這個唯一的解決辦法,到目前爲止,我發現是將其放入標題使用使用Ruby on Rails在PDFKit中設置標題大小?

%meta{:name => 'pdfkit-header_html', :content => pdf_header_url}

工作正常,但圖像比頭大小大。有沒有什麼辦法可以增加標題的高度或者在標題之外以某種方式放置重複的圖像?

謝謝!

回答

1

我結束了添加此代碼

PDFKit.configure do |config| 
    config.default_options = { 
    :page_size  => 'Letter', 
    :margin_top => '3.6in', 
    :margin_right => '0.3in', 
    :margin_bottom => '1.3in', 
    :margin_left => '0.3in' 
    } 
end 

到/config/initializers/pdfkit.rb。我重新啓動服務器後工作得像魅力一樣。

+1

如果僅使用其中一些,則可能需要使用「mm」而不是英寸。我發現這個試驗和錯誤,當錯誤說「所有單位必須是相同的」 - 沒有指出它遇到過什麼單位。我在其他地方沒有設置單位 - 所以也許'mm'是默認設置。 – JosephK 2017-04-24 11:03:31

3

您需要調整margin-topheader-spacing值。例如:

%meta{:name => 'pdfkit-header_html', :content => pdf_header_url} 
%meta{:name => 'pdfkit-margin_top', :content => '3cm' } 
%meta{:name => 'pdfkit-header_spacing', :content => '10' } 

the wkhtmltopdf docs

--header-spacing * <real>   Spacing between header and content in mm 
            (default 0) 
-T, --margin-top <unitreal>  Set the page top margin (default 10mm) 

你可以把任何的meta標籤和PDFKit的wkpdftohtml選項將通過他們通過。

+0

這也行得通,是的! – Cojones 2012-10-31 14:12:19