How to insert page break in HTML, so wkhtmltopdf parses it?

So, basically I use wkhtmltopdf to convert a dynamic HTML report to PDF.

The report has a specific format, and I was asked to clone this format using HTML.

The problem I am facing is that I cannot simulate a 100% functional page break in html, so wkhtmltopdf can interpret it and send the content to another page.

I am trying to avoid methods for measuring page size and so.

TIA for any assistance provided.

EDIT: For now, I am emulating a page break using <br> , and it works. However, I still need to do some testing.

+31
source share
3 answers

Specify a CSS rule for the type of print medium. There are a number of properties that you can use to swap . The easiest way for me is to attach the page-break-before property to the class, as shown below.

In HTML:

 <p>Page 1, paragraph 1</p> <p class="new-page">Page 2, paragraph 1</p> <p>Page 2, paragraph 2</p> 

In CSS:

 @media print { .new-page { page-break-before: always; } } 
+44
source

When I use wkhtmltopdf , I work with the following classes:

 .keep-together { page-break-inside: avoid; } .break-before { page-break-before: always; } .break-after { page-break-after: always; } 

Therefore, I can force:

  • That the content of a particular container does not apply to two pages (if it corresponds to one page). When using the keep-together class, a page break is created in front of the container.
  • That page break is forced in front of a specific container.
  • That page break occurs after a specific container.

@media print did not work for me with wkhtmltopdf .

+36
source
 <div style = "display:block; clear:both; page-break-after:always;"></div> 

Just add this to your HTML

0
source

Source: https://habr.com/ru/post/1014650/


All Articles