15

This is the result when i use Wicked_pdf to convert my html.erb page to pdf.

enter image description here

Problem: Seem table 's tr has been splitted into two pages.

What i tried without success:

  1. Use page-break-inside as described here or here

table, tr, td, th, tbody, thead, tfoot { page-break-inside: avoid !important; }

  1. putting text within a div, as explained here
  2. here

Another option: place each tr in its own tbody and then apply the peage break css rules to the tbody. Tables support multiple tbodys. A bit of extra markup, but works decently for me.

I am using Ruby on Rails 4.2.6, Wicked_pdf latest version, bootstrap.

Relate issue on github

Question: How can i make table 's tr not split into two pages.

Community
  • 1
  • 1
Nhat Dinh
  • 3,378
  • 4
  • 35
  • 51
  • 1
    I created a pull request that fixes this issue in May last year. The project maintainer hasn't merged it yet. Grab my fork of the Qt project and compile it. https://github.com/wkhtmltopdf/qt/pull/29 – RickMeasham Mar 22 '17 at 00:06
  • 1
    The pull request has now been merged into the project. See if that solves your problem. We've had it in production since June last year without a repeat of the issue. – RickMeasham Mar 22 '17 at 06:19
  • @RickMeasham Thank you. But how can i install this wkhtmltopdf package on my MAC or Centos server ? – Nhat Dinh Mar 22 '17 at 07:19
  • @RickMeasham `without a repeat of the issue`, isn't just misleading but straight up false. Im on 0.12.4 and am still experiencing this problem – TheRealMrCrowley Nov 10 '17 at 18:43
  • @TheRealMrCrowley .. please re-read: "See if that solves your problem" doesn't promise it does. "We've had it .. without a repeat" is my experience. Again, no promises. – RickMeasham Nov 24 '17 at 05:26
  • 1
    @RickMeasham sorry I thought you we're providing the perspective of a maintainer of the project – TheRealMrCrowley Nov 27 '17 at 19:42
  • Your first page isn't filling up is it? I see no gap at the bottom of the first page which is why I ask. If it fills up, nothing will prevent the page break except defining a larger page when you run wkhtml2pdf. If you been provide a more complete screenshot a well as the exact HTML and CSS that you're using, you'll make more and better answers possible. – rainabba Feb 22 '17 at 16:03

1 Answers1

5

well, to solve this you have to user page-break-inside: avoid !important; with the repeated div the results in this overflow.

like if you have:

<div class="main">
    <div class="article">
        ...
  </div>
    <div class="article">
        ...
  </div>
    <div class="article">
        ...
  </div>
  ...
  ...
  ...
</div>

which results in overflow that will make things overlap with the header within the page breaks..

so >> use: page-break-inside: avoid !important; with this class article.

table.report-container div.article {
    page-break-inside: avoid;
}

---> here is a full answer to print a page properly using html/css

Biskrem Muhammad
  • 4,074
  • 3
  • 31
  • 38