Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wicked_pdf and wkhtmltopdf page size issue

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.

like image 453
Nazar Hussain Avatar asked Apr 18 '11 09:04

Nazar Hussain


2 Answers

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.

like image 55
Benoit E. LeBlanc Avatar answered Nov 11 '22 13:11

Benoit E. LeBlanc


Try putting in your css

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

Also make sure you add media="all" if you are referencing external stylesheet:

<link href="/stylesheets/scaffold.css?1304060088"
      media="all" rel="stylesheet" type="text/css">
like image 31
Shreyas Agarwal Avatar answered Nov 11 '22 15:11

Shreyas Agarwal