16

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?

Jan Doggen
  • 8,799
  • 13
  • 70
  • 144
NaN
  • 8,596
  • 20
  • 79
  • 153

1 Answers1

41

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>
TLama
  • 75,147
  • 17
  • 214
  • 392
EStafford
  • 628
  • 6
  • 5
  • From https://developer.mozilla.org/en-US/docs/Web/CSS/page-break-after: "It won't apply on an empty
    that won't generate a box."
    – vitaly Jan 07 '19 at 08:37
  • THANK YOU. I have tried ~10 similar solutions before this and nothing was working. – HFBrowning Jul 26 '19 at 18:22