wkhtmltopdf / wkhtmltopdf

Convert HTML to PDF using Webkit (QtWebKit)

Home Page:https://wkhtmltopdf.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tables: lines within a row may break in between pages

Ognian opened this issue · comments

As suggested this is a separate issue resulting from #1640

I was trying with a document of mine with different sorts of tables on Safari 8.0.3 / OS X:

  • Export as PDF does not appear to cut lines. Although it cuts rows.
  • "Print to a PDF" cuts lines.

If I "Print to a PDF" on Firefox it does not cut lines, it does not cut rows, and it repeats THEAD nicely at the beginning of each row.

@ashkulz Have you considered using Gecko instead of WebKit?

note: I'm not trolling; just proposing a radical change to solve an issue that looks inherent to WebKit.

commented

Having same issue, ubuntu 13.10, using wicked_pdf for rails last version with wkhtmltopdf-binary, have updated wkhtmltopdf --version: 0.12.2.1 (with patched qt). The problem is looking like this: screenshot I've tried everything while reading other similar issues. I've have also tried hendricius code from issue #1640, and also get divided rows, the same with @ashkulz code example from #1524 Problem appears in Chrome(34.0.1847.116) and Firefox(30.0)

Guys, there is hope that it will be fixed?

@mewlabs: it will be fixed eventually, but there is no ETA when it will happen. The page-break-inside: avoid logic is a hack done at the table level, but does not work in certain scenarios. I can explain it to someone who knows the WebKit internals, but I'm not sure that anyone has an idea of how to fix it (it would've been fixed upstream if it was easy and easily cherry-picked here) without a rewrite of the existing code.

A workaround to this is by putting your text within a div, as explained here: http://stackoverflow.com/questions/9288802/avoid-page-break-inside-row-of-table/17982110#17982110

workaround on SO does not work.

same problem. what is bizarre is that exactly the same html and exactly the same content works perfectly on the osx version 0.12.3 but doesn't work (cuts rows) on the same linux version

Placing text into div with style

page-break-inside: avoid !important;
margin: 4px 0 4px 0;

does not fix the issue. This is described in #3141 and in http://stackoverflow.com/questions/39685685/how-to-show-first-line-in-page-without-truncation

I'm running the wkhtmltox-0.12.4_linux-generic-amd64.tar.xz version from Ubuntu 16.10 x64.

The commands

wkhtmltopdf input.html output.pdf
wkhtmltopdf --print-media-type -s A4  input.html output.pdf

both result in occasional lines of text output being split by the page break; the upper part of the line prints on the bottom of a page, and the lower part of the line prints at the top of the next page.

This happens a few times on a 95 page document.

Adding appropriately-positioned blank lines

<br/>

moved the text out of the way of the page break.

I tried the

page-break-inside: avoid

style but couldn't get wkhtmltopdf to respect page break settings.

Post my question here.
Tried almost everything from stackoverflow, github issue without success.
http://stackoverflow.com/questions/42341604/wicked-pdf-avoid-page-break-inside-not-working

So after researching 4 hours i found total 2 solutions .

  1. with css

tr{ page-break-before: avoid; display: "inline-block"; //or display: "inline-table" }

This solution worked for me. but it also changes the design of my page. because of display: inline-block and page-break-before: avoid; not working with out display: inline-block; in tr.

  1. updated the gem version of wkhtmltopdf-binary

Very effective solution. because from my older wkhtmltopdf's version was 0.9 in which the page break issue is common. So i updated gem version of wkhtmltopdf-binary.

Replace this gem gem **'wkhtmltopdf-binary' with gem 'wkhtmltopdf-binary', '~> 0.12.3'

Nothing works when I get this issue. It's been b0rked for several years. Now we'd like to see a library that can handle page breaks! It is completely unreasonable for me to randomly try and guess what rendering will work. Now I'm stuck with no hope.

Similar issue. Still no fix?

In my case adding to a container div page-break-inside: avoid !important; works! But the div cannot not be inside a table so what I did was separate my template table into several small tables, each one inside a container div.

So there is still not solution for one large table to avoid page break between two specific rows?

I had this issue, very frustrating. The way I solved it was change my CSS. At the end it was possible to fix.

I had this issue, very frustrating. The way I solved it was change my CSS. At the end it was possible to fix.

What did you do to fix it? I've seen moved on to domPDF.

I had this issue, very frustrating. The way I solved it was change my CSS. At the end it was possible to fix.

What did you do to fix it? I've seen moved on to domPDF.

It was specific to my project. I had a very large CSS file (~10000 lines). I found the offending CSS style and experimented with it until the rendering was correct. I thought it was impossible but after several hours of trial-and-error it was actually possible to fix it.

I no longer have access to the code, but since this issue is still active I wanted to say that there is hope.

In my case (wkhtmltopdf 0.12.6 (with patched qt)), this issue can be reproduced with a bootstrap (v4.2.1) responsive table.

<div class="table-responsive">
<table data-striping="1" class="table table-hover table-striped">
...
</table>
</div>

After I change CSS from:

.table-responsive{
  overflow-x: auto;
}

to

.table-responsive{
  overflow-x: visible;
}

It's fixed.

Adding
html, body { margin: 0; padding: 0; border: 0; font-size: 100%; font: inherit; vertical-align: baseline; }

Fixed it for me.

I tried all ways, but it still not work. Finnally, thepuppeteer solved my problems. I made a demo in here