Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert html to pdf - page break splits text

I tried to generate a PDF-file from a HTML/CSS-document by using the api of pdflayer.com. So far so good. everything worked fine. But there is one issue. If there is a page break, a line sometimes gets split like in the photo:

split line

is there a way to get rid of this issue? I also tried html2pdfrocket.com it is the same there.

The text is placed within this html-construct:

<html>
 <body>
  <div class="overall">
   <div class="content">
    <div class="wrapper">
     <div class="article">
      Text
like image 435
Bernhard Avatar asked Jan 22 '19 12:01

Bernhard


3 Answers

I found out that there exists a problem with compiling the content inside of multiple divs. CSS-rules did not affect the behaviour of the issue.

So I had an idea and what I made was to generate a "raw-html-output". In this html document is only

<html>
 <head>
  <style>
   The only necessary css-rules.
  </style>
 </head>
 <body>
  Some text here.
 </body>
</html>

Nothing more.

The API grabs the data from the simplyfied html-file and compiles them well.

like image 130
Bernhard Avatar answered Oct 01 '22 11:10

Bernhard


i think the best solution would to prevent a break inside a paragraph on print. Something like this:

@media print and (min-width:700px) {
    /* you can change the selector to whatever you need */
    .article {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
like image 40
LuisBento Avatar answered Oct 01 '22 10:10

LuisBento


If you use firefox, open the html doc with it and install the add-on named PDF Mage. Just click the icon to convert the page to PDF. It always works for me without any problems.

Viele Grüße

like image 30
David Avatar answered Oct 01 '22 11:10

David