1

Rails 3.1 と PDFKit gem を使用しています。

カスタム page_size を設定するにはどうすればよいですか? (デフォルトの「レターまたはA4」は使いたくない)

4

3 に答える 3

1

Thanks to this SO Post:

PDFKit.configure do |config|
  config.wkhtmltopdf = `which wkhtmltopdf`.to_s.strip
  config.default_options = {
    :encoding=>"UTF-8",
    :page_size=>"A4", #or "Letter" or whatever needed
    :margin_top=>"0.25in",
    :margin_right=>"1in",
    :margin_bottom=>"0.25in",
    :margin_left=>"1in",
    :disable_smart_shrinking=>false
    }
end

You can change the :page_size variable to whatever you need.

于 2012-03-06T01:06:22.933 に答える
1

page_widthイニシャライザでandを指定page_heightします。

PDFKit.configure do |config|
  config.default_options = {
     :page_width => '169.33',
     :page_height => '95.25'
  }
end

またはpage_widthpage_heightコード内。

kit = PDFKit.new(html, page_width: '169.33', page_height: '95.25')

このソリューションを共有してくれたj.aviに感謝します。

于 2014-05-25T17:59:39.877 に答える
1

これは私のために働いた:

var doc = new PDFDocument({
  size: [240, 320]
});
于 2015-11-08T21:28:52.283 に答える