6

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.

Nazar Hussain
  • 5,102
  • 6
  • 40
  • 67
  • I think you may be better off specifying units in something other than millimeters. I don't think the scale works reliably. The page is a fixed size, so you should be able to tweak it to where you want with pixels or percentages. – Unixmonkey Apr 21 '11 at 22:38
  • 2
    I also tried px, in, %, but nothing solves the issue. – Nazar Hussain Apr 22 '11 at 09:16

2 Answers2

3

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.

sth
  • 222,467
  • 53
  • 283
  • 367
  • 'Because the inline-block is just like floating it left.' this save me a lot of time :D, thanks you. – Thanh Sep 23 '13 at 09:00
  • Here , talking from the future =) , well thanks this only works when is Portrait , can you do it using Landscape? What do I need to add? – Carlos Morales Mar 20 '14 at 22:01
1

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">
Eric
  • 95,302
  • 53
  • 242
  • 374