Xportability / css-to-pdf

Convert any HTML page or region to PDF - supports CSS, SVG, embedded XML objects, and more..
http://www.cloudformatter.com/CSS2Pdf
206 stars 78 forks source link

page-break rules not respected #57

Closed adaptifyDesigns closed 7 years ago

adaptifyDesigns commented 7 years ago

First of all, thanks for this script. It's definitely the easiest client-side pdf generator I've found.

I've been having trouble getting the pdf to respect my page-break rules.

For example, I have sections of content that are structured like the following:

<div>
    <h2 style="page-break-after: avoid;">Section Title</h2>
    <div style="page-break-before: avoid;">
        All the section content goes here. Mostly paragraph text, etc.
    </div>
</div>

The goal with this is to avoid page breaks directly after a section title because it's unsightly and jarring for the reader.

But even when doubling up on the page break rules, my pdfs are still breaking directly after section titles.

At first I just had the page break rules in my stylesheet. Then I moved them into the "@media print {...}" section of my stylesheet. And when that still didn't work, I finally wrote them inline directly on the elements, as seen above, but it still isn't working.

In the js console output, when I search for inline "page-break-..." occurances there are no such inline css rules applied to any of the elements.

Are the rules getting ignored or stripped for some reason?

Any suggestions?

Thank you in advance for your time and any assistance you can provide.

Cheers!

kbrown01 commented 7 years ago

See http://www.cloudformatter.com/CSS2Pdf.CustomTipsTricks.XSLFOStyling

It shows all examples of keeps and specifically how to set headings to keep with the following information.

Kevin Brown

skype:kbrown01

mailto:kevin.brown@xportability.com kevin.brown@xportability.com

From: adaptifyDesigns [mailto:notifications@github.com] Sent: Thursday, February 23, 2017 1:54 AM To: Xportability/css-to-pdf css-to-pdf@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: [Xportability/css-to-pdf] page-break rules not respected (#57)

First of all, thanks for this script. It's definitely the easiest client-side pdf generator I've found.

I've been having trouble getting the pdf to respect my page-break rules.

For example, I have sections of content that are structured like the following:

`

Section Title

All the section content goes here. Mostly paragraph text, etc.

`

The goal with this is to avoid page breaks directly after a section title because it's unsightly and jarring for the reader.

But even when doubling up on the page break rules, my pdfs are still breaking directly after section titles.

At first I just had the page break rules in my stylesheet. Then I moved them into the @media print {...} section of my stylesheet. And when that still didn't work, I finally wrote them inline directly on the elements, as seen above, but it still isn't working.

In the js console output, when I search for inline page-break-... there are no such inline css rules applied to any of the elements.

Are the rules getting ignored or stripped for some reason?

Any suggestions?

Thank you in advance for your time and any assistance you can provide.

Cheers!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Xportability/css-to-pdf/issues/57 , or mute the thread https://github.com/notifications/unsubscribe-auth/AAsJo0mOjtZPUk5_Hqn7_HXuxNC2c3xPks5rfVdJgaJpZM4MJwd- . https://github.com/notifications/beacon/AAsJo8TJqKK81vh_3xox1efYCSgai0YUks5rfVdJgaJpZM4MJwd-.gif

adaptifyDesigns commented 7 years ago

Got it! Awesome.

Thank you very much :-)