Html Conditional PageBreak - html

I have html page that generate report it contains sections and sub-sections.
Code has many tables and sub tables and div tags.
I want to apply page break when any section heading reach the end of the page.
Specifically "don't want heading at the end of the page while printing"

If you want to use specific page break, when printing, you can set this with CSS like the following :
CSS :
#media print {
.page-break { display: block; page-break-before: always; }
}
HTML :
<!-- any content -->
<div class='page-break'></div>
By doing this you'll manually break the page at this tag.

Related

At the time of priniting page is breaking in 2 page but first page has blank space

I had created a bill format in HTML and when I am viewing it in browser it viewed perfectly but when I am trying to print it is breaking in 2 pages. I am attaching my html code here for reference:-
I had uploaded code on jsfiddle and here is the link of the code
https://jsfiddle.net/rohitarya/oyucgz4k/1/
That is because your table doesn't fit on A4 format. Try to make less paddings and make a font smaller. It could help you.
To add line breaker you could make CSS class for example linebreaker or any you would like:
#media print {
.linebreak { page-break-before: always; }
}
Then just add an empty DIV with this class where you need to make a line break:
<div class="linebreak"> </div>

print each Div in a separate page [duplicate]

I am planning price list available for clients online and I was thinking about simple very long page or div container with some anchor links aside to help jump to different products.
However in case someone wants to print off just price list with certain products I don't want all the pages to print off but only current one.
Is there any print breaking character or tag?
Just in case someone has better idea all I want to achieve is having price list in html to change it in one place but still be able to convert separate product price lists into PDF files for emailing purposes of particular product.
Use this CSS:
#media print
{
.page-break { display:block; page-break-before:always; }
}
and then cite this in your HTML where you want the page to break:
<div class="page-break"></div>
And there you go :)
As per w3schools, you can also do the following:
#media print {
.page {page-break-after: always;}
}
and then, in your HTML:
<div class="page">
<!-- Page Contents -->
</div>
Or, if you have a footer under every page (for example for page numbering):
#media print {
footer {page-break-after: always;}
}

Print site logo just on first page (#media print )

I need to create print version of website, and as I mention in title I need to display site logo just on first page. For example, if I print home page, and I get 5 pages, logo should be displayed just on first page.
is it possible with #media print ?
What I've tried so far but does not work
#media print {
#top-menu,
#main-navigation-sticky-wrapper,
#action-bar,
.teaser-cda,
.pre-footer,
.footer,
.post-footer,
.header .logo {
display: none;
}
#page:first {
.header .logo { display:block }
}
The correct syntax (according to MDN) for first page is:
#page :first {
/* .... */
}
You don't have a space between the two components. Be wary, however, as compatibility for #page :first is not well-defined.
It might not even be necessary though. I don't think block-level elements get repeated on every page, so you might just need to ensure that the logo is displayed in #media print { ... }.
You will also want to check the element and it's container elements to ensure that none of them have position: fixed as that may also cause the element to repeat on each printed page.
#page rule is a CSS at-rule used to modify different aspects of a printed page property. It targets and modifies only the page's dimensions, page orientation, and margins.
It can't have css class inside.
#page :first {...} it just allows you to add these previous styles on the first page but you can't also add a class inside.

html - verify that each div will be on separated print page

I have many divs that proposed to be printed - on different pages.
How can I make sure that when the user is clicking the print button, each div will be on a different page?
Thanks!
You can use the page-break-after attribute in the print media query. The advantage is, that you don't have to change the size of your divs, it just makes sure that the page break will be after the div.
#media print {
div {
page-break-after: always;
}
}
More information about page-break-after on MDN.
In css, there is a media query you can use to specifically format your web page for when you want to print it:
#media print {
/* insert your style declarations here */
div {
page-break-after: always; /* ensures the next will we appear on new page */
}
}
You can use this media query to make each div fill up an entire page when the user decides to print. You can use this to modify things like removing the navbar when the user decides to print.
On the other hand, to avoid direct breaks after a certain element use page-break-after: avoid;
You can also for the use to print in a certain format that you want to specify using the follow:
#page {
size: A4; /* or A4 landscape or A5 */
}

Ensure contents print on separate pages

I have a cover letter and resume together in seperate divs on one html web page.
When I try print preview half of my resume is on the cover letter page.
Is there any way to ensure that the two divs print on seperate pages?
You can use the following CSS...
#cover-letter {
page-break-after: always;
}