3
votes

I am using wkhtmltopdf (through the 'pdfkit' ruby gem) to generate pdf from html. There is a section in the page where the text content is lengthy, and it usually spans 2 (or more) pages. What happens sometimes is that a line of text is split across pages. Here's an image to help you understand what I mean:

enter image description here

Now I have done my fair bit of research on this: for example I have tried CSS fix on the sorrounding div (which was suggested in some other stackoverflow questions), like so:

page-break-inside:avoid !important;

and/or

page-break-before: always !important;

didn't work.

I have also tried:

display: block !important;

which didn't work either.

Does anyone know how to fix this problem?

FYI: I am using the latest version of wkhtmltopdf: wkhtmltopdf-0.11.0_rc1

2
Could you show/link to the HTML and the CSS? I use wkhtmltopdf daily and for me this is not an issue so I'd like to test with your data and scenario.Joel Peltonen
hmm.. I passed the same html content to wkhtmltopdf's "linux" static binary, and the issue disappeared. I am now thinking this might be an issue with the Mac version. I'll post the solution once I find it out. In the meantime, I will appreciate any help. p.s. Seems like when you do wkhtmltopdf --version on homebrew-installed package, it displays the wrong version number. The actual installed version seems to be 0.10 rc.Pouya
Check if this or parent divs have overflow set as hidden. If so, change it to visible. That fixed the issue for me.El Kopyto

2 Answers

1
votes

This solution is on for wicked-pdf andwkhtmltopdf.

Once got into similar kind of issue but fixed by changing the contents in configuration folder wicked_pdf.rb file to

WickedPdf.config = {
    :layout => "pdf.html",
    :margin => {    :top=> 60, #previously 40
                    :bottom => 40, #previously 20
                    :left=> 30,
                    :right => 30},
    :header => {:html => { :template=> 'layouts/pdf_header.html'}},
    :footer => {:html => { :template=> 'layouts/pdf_footer.html'}},
    :exe_path => '/usr/bin/wkhtmltopdf'
}

changing from previous to new values, it worked fine on local machine.

Whenever you make changes in wicked_pdf.rb the server must be re-started, and make sure page-break-before: always is at right place.

Hope this helps :)

1
votes

In my case, the issue was resolved by commenting out the following css:

html, body {
  overflow-x: hidden;
} 

As El Kopyto stated in one of the comments to a previous answer:

Check if this or parent divs have overflow set as hidden. If so, change it to visible.

In my case, removing the overflow property altogether did the job.