Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to avoid extra blank page at end while printing?

Tags:

css

printing

I'm using a CSS property,

If I use page-break-after: always; => It prints an extra blank page before

If I use page-break-before: always; => It prints an extra blank page after. How to avoid this?

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> <style type="text/css"> .print{     page-break-after: always;  } </style> <script type="text/javascript"> window.print(); </script> </head> <body> <div class="print">fd</div> <div class="print">fdfd</div> </body> </html> 
like image 631
Angelin Nadar Avatar asked Oct 21 '11 07:10

Angelin Nadar


People also ask

Why does my printer print a blank page at the end?

There are numerous possible causes for a printer that's randomly producing blanks. The most common ones are empty ink cartridges, improper cartridge installation, and congested nozzles. Driver and software issues can sometimes cause this problem as well.

Why is word adding a blank page when printing?

If you have a landscape section in amongst your portrait pages, and there's only enough content to fit on a single landscape page, then the back of that page will print as a blank page. Again, if you're printing double-sided, this is what you want to happen, but it's disconcerting when you're printing single-sided.


2 Answers

Have you tried this?

@media print {     html, body {         height: 99%;         } } 
like image 56
giannis.epp Avatar answered Sep 27 '22 22:09

giannis.epp


You could maybe add

.print:last-child {      page-break-after: auto; } 

so the last print element will not get the extra page break.

Do note that the :last-child selector is not supported in IE8, if you're targetting that wretch of a browser.

like image 24
AKX Avatar answered Sep 27 '22 22:09

AKX