Hello everyone and thanks for your help in advance. I am learning iText 7 and am creating an application that pulls a webpage from a URL and converts it to PDF. I've got the very basic pieces working, i.e. grabbing the page, converting it to PDF, and writing it to disk. What I want to accomplish next is to add headers and footers as well as Page x of y. I've tried:
@media print {
@page {
size: 8.5in 5.5in portrait;
margin-left: 0.5cm;
margin-right: 0.5cm;
margin-bottom: .5cm;
padding-bottom: 3.5cm;
background: #FFF;
}
thead { display: table-header-group; }
tfoot { display: table-footer-group; }
}
which seems to place the header and footer on each page, although the last page of the document has the footer placed after where the last element appears (not ideal). Since I'm grabbing a page, I'm not really sure how to add the page number and count. So my question is how to tackle this, i.e. should I just stick with the media query, or should I generate the PDF, the loop through using some type of handler to insert the headers and footers (or should I do this upon creation of the initial document). I now there are some tutorials on paging, but not combined with converting a webpage, so I am confused (maybe needlessly) about how to proceed. Any help would be appreciated.
I tried:
@media print {
@page {
size: 8.5in 5.5in portrait;
margin-left: 0.5cm;
margin-right: 0.5cm;
margin-bottom: .5cm;
padding-bottom: 3.5cm;
background: #FFF;
@bottom-right {
content: "Page " counter(page) " of " counter(pages);
}
}
thead { display: table-header-group; }
tfoot { display: table-footer-group; }
}
but the page number does not display, either on the HTML or converted PDF. I needed to use:thead { display: table-header-group; }
tfoot { display: table-footer-group; }
to force the header and footer to display on each page. Obviously I'm not handling this correctly, but don't know what to try next.
`
enter code here