2

我正在使用 wickedPDF 在 rails 中创建 pdf,一切似乎都进展顺利,直到我尝试放入全宽图像。但是,如果我设置,我希望页面的宽度为 595px(a4 为 72dpi)

body{
  width: 595px;
}

还有一个宽度为 595px 的简单图片标签,它只占屏幕的 2/3s。如果我将图像的宽度更改为 700 像素,它会填满整个屏幕。

我的问题是如何更改 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我得到一个空白屏幕,那也不好

4

4 回答 4

2

也许你可以看看:page_size => '...'选项。从 man wkhtmltopdf

-s, --page-size 将纸张尺寸设置为:A4、Letter 等。

于 2012-06-23T13:17:09.530 回答
0

我遇到过同样的问题。我制作 .container div 的宽度为 1200-1400px,因为页面上有一个宽表。里面放了一些宽度= 100%的div。它对我来说很好,就像某种缩放一样。

于 2012-12-11T19:34:45.883 回答
0

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

于 2014-10-28T10:50:59.853 回答
0

取决于你需要什么@Yule。我用这个:

  <div style="width: 820px; margin: auto;">
    <%= render :partial => "pdf_partial" %>
  </div>

我在 wicked_pdf.rb 中也有这个:

WickedPdf.config = {
  :page_size  => "Letter",
  :dpi => '300'
}
于 2013-02-15T10:50:18.570 回答