问题描述
我一直在寻找文档,但是找不到答案.如何指定pdf文档的页面大小以及可用的页面大小是多少?我一直在寻找,但是找不到很好的文档.请指向我一个URL或让我知道如何将页面大小编码到我的PDF文档中.
I have been looking in the documentation but can't find the answer. How can I specify the page size of my pdf document and what are the available page sizes? I keep on looking and looking but I can't find good documentation. Please point me to a URL or let me know how can I code some page size into my PDF document.
哦,我不想在任何配置文件上执行此操作,因为我需要生成不同大小的PDf文档.
Oh and I don't want to do that on any config file because I need to generate PDf documents of different sizes.
不在配置文件中...
NOT in config file...
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
推荐答案
您可以在创建新PDF时设置页面大小,如下所示:
You can set the page size when creating a new PDF like this:
kit = PDFKit.new(source, :page_size => "Legal")
PDFKit使用WKHTMLTOPDF,后者又使用QPrinter.您可以在 QPrinter文档(有一堆),但可以肯定地说,您想要的任何尺寸的纸张都可以使用.另外,如果找不到所需的尺寸,则可以设置自定义尺寸.
PDFKit uses WKHTMLTOPDF which in turn uses QPrinter. You can find the available sizes in the QPrinter documentation (there's a bunch), but its pretty safe to say that any size paper you want is available. Also, you can set a custom size if you can't find what you need.
注意:如果未在某处的配置中为page_size
设置默认选项,并且在方法调用中未提供默认选项,则PDFKit将使用其内部默认值(字母).参见 lib/pdfkit/configuration.rb 的第10行
NB: If you don't set a default option for page_size
in a config somewhere AND don't supply one in your method call, PDFKit will use its internal default (Letter). See line 10 of lib/pdfkit/configuration.rb
这篇关于Rails 3和PDFKit.如何指定页面大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!