Yule
Yule

Reputation: 9764

how do I set page width in wickedPDF

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

Upvotes: 2

Views: 7642

Answers (4)

damau
damau

Reputation: 334

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

Upvotes: 0

Tomasz Giba
Tomasz Giba

Reputation: 541

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'
}

Upvotes: 1

Skydan
Skydan

Reputation: 1246

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.

Upvotes: 0

vlain
vlain

Reputation: 712

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

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

Upvotes: 2

Related Questions