如何在 wickedPDF 中设置页面宽度

发布于 2024-12-25 01:30:51 字数 938 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

恍梦境° 2025-01-01 01:30:51

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

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

Maybe you can look at :page_size => '...' option. From man wkhtmltopdf

-s, --page-size Set paper size to: A4, Letter, etc.

别在捏我脸啦 2025-01-01 01:30:51

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

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

并且我在 wicked_pdf.rb 中也有这个:

WickedPdf.config = {
  :page_size  => "Letter",
  :dpi => '300'
}

Depends on what you need @Yule. I use this:

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

and I also have this in wicked_pdf.rb:

WickedPdf.config = {
  :page_size  => "Letter",
  :dpi => '300'
}
神魇的王 2025-01-01 01:30:51

我有同样的问题。我制作 .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.

千仐 2025-01-01 01:30:51

对于边距选项,您可以传递给 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文