Page breaking the pdf so it doesn't split data or cut it off

848 views
Skip to first unread message

Jeff McBride

unread,
Nov 18, 2015, 2:55:40 PM11/18/15
to jsreport
Is there a way to tell phantom pdf or wkhtmltopdf to page break in such a way that content doesn't get split apart or part of the content renders on one page and part on the other?  Some of my text get's cut in half and served on two different pages.  I'm using jsrender and iterating through the array using a 
{{for}}{{/for}}

command.

Jeff McBride

unread,
Nov 18, 2015, 3:57:39 PM11/18/15
to jsreport
So I can use 
style="page-break-inside: avoid!important; display: block!important;"
inline with wkhtmltopdf but not with phantompdf.  Nor can I stick the styles in an external sheet and reference them.  Not sure why that is, but it seems to be working.

Jeff McBride

unread,
Nov 18, 2015, 5:19:38 PM11/18/15
to jsreport
So I found out that you HAVE to hardcode this inline.  You cannot programmitcally (with JS) add the styles nor can the styles be in a class or id from a style sheet you reference.  Hard part about that is, I'm hiding a div if there's no data to fill it and displaying the div if there is.  Because I have to use
display: block!important;
(and I have to include the !important), it makes the div show regardless of what my JavaScript tells it to do.  Also, if I use visibility instead of display to hide the div, the element would still be on the page taking up space and I obviously don't want that.  Maybe someone can see what I'm doing wrong?

Jeff McBride

unread,
Nov 18, 2015, 6:10:44 PM11/18/15
to jsreport
So now it seems that the 
style="page-break-inside: avoid!important;"
isn't actually doing anything.  I put a 
<div class="clear">&nbsp;</div>
between the data lines and apparently it also helps (probably because of the size of the font) to not cut the text in half from one page to another.  I tested this with multiple data in the different fields and it seems to be working just fine.

Reply all
Reply to author
Forward
0 new messages