-
Notifications
You must be signed in to change notification settings - Fork 5.7k
CSS not respected: page-break-after: always; Phantomjs 2.0 #13524
Comments
+1 |
+1, I'm for now using hack in javascipt to fit divs to page height |
+1 |
2 similar comments
+1 |
+1 |
+1 |
I am using 2.1.1 and "page-break-after: right" does not work. It is treated exactly like "page-break-after: always", which works fine. |
+1 |
+1 also having a ton of trouble making a reasonable PDF document of a page and having the page-break css styling apply. My solution so far has been to make PNG snapshots of our SVG charts (Highcharts), output them to the filesystem and then build a new local page in my phantomjs script. The page-break logic seems to work fine for actual images. However the scaling I need to do to fit it into a PDF makes it look not great and also the text and numbers is not selectable in the PDF (but it's a workaround that may help someone). |
try using 2.1 or above. it works I think. |
@ziyaaktas I'm using 2.1.1 and it doesn't seem to fix things for me. We do have a lot of javascript generated DOM so that may be causing troubles, but I haven't been able to find a combo of things (viewportSize, paperSize, zoom, dpi ...) that makes my rendering work. Getting closer but definitely not the same as the HTML representation from firefox or chrome in print mode. |
@samwise-nl We are also using 2.1.1 and experiencing this. Any updates on this one @ariya? |
+1 page-break-inside: avoid; not working on 2.1.1 |
+1 |
+1 page-break-inside:avoid not working for me in phantomJS, but works in Chrome print preview of same page. |
here is my workaround:
I am using 300mm because DIN A4 page is 297mm high. |
This feature is extremely important to make multi page documents well structured. |
+1 |
1 similar comment
+1 |
A (working) workaround for page-breaks: So PhantomJS has this bug which scales the page by 150% and requires you to scale it back to the desired size by applying a scaling factor of 0.666 (#12685). When applying this scaling factor to the entire page (e.g. via body {zoom: .666} or body {-webkit-transform: scale(.666); transform: scale(.666); -webkit-transform-origin: 0 0; transform-origin: 0 0;}), page-breaks stop working. Because of the scaling, it just inserts some space after / before the element that should be on the next page. How I got it to work is by applying zoom: .666 to all elements immediately below the body element and then fixing their width like so (I'm using section elements, but it should also just work with the general body > * selector): body > * {
width: 66.667%;
zoom: .666;
} |
I'm working on this issue in our PDF engine now since months.
Thanks go to drdla the 'zoom' was the working solution. But, just set it to the body this is enough! I'm pretty sure that it is factor 0.75. Because we print out tables with fixed size columns (e.g. 70mm) and I measured them on the printer. PS) Before I used "transform", which was also ok until we introduced "page-break". The "Transform" breaks the page size calculation inside phantomjs completly, the page breaks occure somewhere at 75%. Thanks go to drdla you saved my day. PPS) to get the right Header and Footer you need to do the same trick. And remember they cannot access other resources, do everything inline. PPPS) If someone has a hint for pagebreaks in table rows. |
Setting the element and parent to |
Has anyone given the new 2.5.0 beta build a test to see if the page-break rules are followed properly now? https://groups.google.com/forum/m/#!topic/phantomjs/AefOuwkgBh0 I'm trying to test my script but having other issues with it at the moment. |
Thanks @drdla and @andrebaresel , adding
to my container element fixed the scaling issue I was having with phantomjs rendering the page. :-) It was not necessary to use Although, it still doesn't honor the |
Thanks @drdla I changed your code a bit so that the final layout actually stays the same without being distorted:
After adding the snippet above, I added the snippet below to all elements that should be unbreakable.
|
+1 on |
Is this only happening on MAC? |
@btoda No, for me this consistently happens with PhantomJs 2.1.1 on macOS and Linux (Ubuntu). |
any updates on this? |
We fixed this issue by adding |
Due to our very limited maintenance capacity (see #14541 for more details), we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed. In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution! |
Hi, I am using Phantomjs 2.0 and still have problems with page breaks, I followed the suggestions in #10638 but none of them seems to be working for me. Also, do you still need to set page.paperSize in phantomjs script even when you are setting page breaks in the css stylesheets? I really appreciate it if somebody could help me. I am trying to generate pdf reports and this is the last bit of the puzzle! Thanks in advance.
The text was updated successfully, but these errors were encountered: