Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

knp_snappy page break in generated PDF

I'm working on Symfony2 project to generate PDF from HTML view. Following is from config.yml

knp_snappy:
pdf:
    enabled:    true
    binary:     /path/to/my/wkhtmltopdf
    options:
        no-stop-slow-scripts: ~
        enable-javascript: ~
        use-xserver: ~
        page-size: A4
        dpi: 300

Now I want to know if the DIV is overlapping on the page edges, if so add a page break before DIV. It is currently displaying as follow.

enter image description here

I've tried to get the height of DIVs and compare it with height of page, but it didn't work.

Is there any solution to know when DIV is overlapping or auto breaking the page when something is overlapping ?

like image 699
Alok Patel Avatar asked Oct 08 '15 10:10

Alok Patel


2 Answers

Try to add style "page-break-inside" to your div:

<div style="page-break-inside: avoid;">
    ... content ...
</div>

wkhtmltopdf uses webkit engine. This fact allows you to use styles to control the looks of your PDF.

like image 160
dmnptr Avatar answered Sep 24 '22 09:09

dmnptr


I use Bootstrap for layout styling. To do page breaks works only (for me):

<p style="page-break-after: always;"/>
<br/>
like image 24
Damian Avatar answered Sep 26 '22 09:09

Damian