Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define page breaks when printing html? [duplicate]

I have a application made with Delphi 2006 which prints with QuickReport. Due to many bugs, I will rebuild this section of the software , generating the report in HTML and then send it to printer through some component. My question is, How/Can I tell when printer should break into a new page with HTML? Some tag or event on printing component for HTML?

like image 741
NaN Avatar asked Jan 21 '14 21:01

NaN


People also ask

Can I force a page-break in HTML printing?

We can add a page break tag with style "page-break-after: always" at the point where we want to introduce the pagebreak in the html page.

How do you deal with page breaks when printing large in HTML?

To fix this just change it to page-break-after:auto. It will break correctly and not create an extra blank page. Save this answer.

How do you insert a page-break after always?

Note: The page-break-after property cannot be used on absolutely positioned elements or an empty <div> element. Syntax: page-break-after: auto|always|avoid|left|right|initial|inherit; Default Value : Its default value is auto.


1 Answers

You can add page breaks for printing with a little bit of CSS.

CSS:

@media all {
.page-break { display: none; }
}

@media print {
.page-break { display: block; page-break-before: always; }
}

HTML: Use a div element with the page-break class where you want insert your breaks

<div class="page-break"></div>

Example:

<div>Some content BEFORE the page break</div>
<div class="page-break"></div>
<div>Some content AFTER the page break</div>
<div class="page-break"></div>
<div> ... More content after another page break ... </div>
like image 82
EStafford Avatar answered Oct 23 '22 06:10

EStafford