wicked_pdf and wkhtmltopdf page size issue

Nazar Hussain picture Nazar Hussain · Apr 18, 2011 · Viewed 10.7k times · Source

I used these settings

WickedPdf::config = {
    :layout           => 'application.pdf.html', # use 'pdf.html' for a pfd.html.erb file
    :wkhtmltopdf      => '/bin/wkhtmltopdf', # path to binary
    :orientation      => 'Portrait', # default , Landscape
    :page_size        => 'A4',
    :dpi              => '300',
    :print_media_type => true,
    :no_background    => true,
    :margin           => {:top    => 0, # default 10 (mm)
                          :bottom => 0,
                          :left   => 0,
                          :right  => 0},

}

and set the body style to

body {
    margin: 0;
    padding: 0;
    background-color: #FFF;
    width: 210mm;
    height: 297mm;
}

and a div of class .page

.page {
    display: inline-block;
    clear: both;
    border: 2px solid #FF0000;
    width: 210mm;
    height: 297mm;
    page-break-after: auto;
}

but when the pdf is created, the .page divs are almost half of the pdf page.

Answer

Benoit E. LeBlanc picture Benoit E. LeBlanc · Nov 9, 2011

If you are floating your page container, then it won't work. I had the exact same problem and once I removed the floating pro.

So your page container should be:

.page {
display: block;
clear: both;
border: 2px solid #FF0000;
page-break-after: auto;}

Because the inline-block is just like floating it left.