Wicked_pdf and wkhtmltopdf page size problem

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

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

and div of class .page

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

but when pdf is created, div.page is almost half the pdf page.

+5
source share
2 answers

If you float your page container this will not work. I had the same problem and as soon as I deleted the floating pro.

So your page container should be:

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

Because it’s inline-blocklike floating.

+3
source

Try pasting your css

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

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

<link href="/stylesheets/scaffold.css?1304060088"
      media="all" rel="stylesheet" type="text/css">
+1
source

All Articles