如何在 wickedPDF 中设置页面宽度
我正在使用 wickedPDF 在 Rails 中创建 pdf,一切似乎都很顺利,直到我尝试放入全宽图像。我希望页面宽度为 595px(a4 at 72dpi),但是,如果我设置
body{
width: 595px;
}
And一个宽度为 595px 的简单图像标签,它只填充屏幕的 2/3 秒。如果我将图像的宽度更改为 700px,它将填满整个屏幕。
我的问题是如何更改 WickedPDF 生成的宽度,这是我的 PDF 目前的样子:
format.pdf {
render :pdf => "pdf_1",
:show_as_html => params[:debug].present?,
:layout => 'pdf.html',
:template => "/pdfs/show_pdf",
:margin => {:top => 0,
:bottom => 0,
:left => 0,
:right => 0},
:orientation => 'Portrait', # default , Landscape,
:no_background => true
}
我尝试添加缩放和页面宽度等选项,但没有成功,如果我设置 :dpi=>72 我得到一个空白屏幕,所以这也不好
I'm using wickedPDF to create pdfs in rails and all seems to be going well, until I try to put a full width image in. I want my width of the page to be 595px (a4 at 72dpi) however, if I set
body{
width: 595px;
}
And a simple image tag with a width of 595px, it only fills 2/3s of the screen. If I change the width of the image to be 700px, it fills with entire screen.
My question is how do I change the width that WickedPDF generates, Here's what my PDf currently looks like:
format.pdf {
render :pdf => "pdf_1",
:show_as_html => params[:debug].present?,
:layout => 'pdf.html',
:template => "/pdfs/show_pdf",
:margin => {:top => 0,
:bottom => 0,
:left => 0,
:right => 0},
:orientation => 'Portrait', # default , Landscape,
:no_background => true
}
I've tried adding options like zoom and page width with no success, If i set :dpi=>72
I get a blank screen so that's no good either
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许你可以看看
:page_size => '...'
选项。从 man wkhtmltopdfMaybe you can look at
:page_size => '...'
option. From man wkhtmltopdf取决于你需要什么@Yule。我使用这个:
并且我在 wicked_pdf.rb 中也有这个:
Depends on what you need @Yule. I use this:
and I also have this in wicked_pdf.rb:
我有同样的问题。我制作 .container div 宽度为 1200-1400px,因为页面上有一个宽表。里面放一些宽度=100%的div。它对我来说效果很好,就像某种变焦一样。
I had the same issue. I make .container div with 1200-1400px width, because had a wide table on the page. Inside put some div's with width=100%. It works fine for me, like some sort of zoom.
对于边距选项,您可以传递给 wicked pdf,后者又将它们传递给二进制文件:
options = { margin: { right: 0, left: 0, top: 0, Bottom: 0 }
请参阅
https://github.com/mileszs/wicked_pdf/blob/master/test/unit/wicked_pdf_test.rb#L134
For margin options you can pass to wicked pdf which in turn will pass them to the binary:
options = { margin: { right: 0, left: 0, top: 0, bottom: 0 }
See
https://github.com/mileszs/wicked_pdf/blob/master/test/unit/wicked_pdf_test.rb#L134