The CSS3 Paged Media spec was born broken on some fundamental things like counter resets, then effectively abandoned in 2013, so some complex print-specific requirements like fully customizable page numbering just don't happen without additional tooling. Accessible tagged PDFs are still a struggle, and I think only Weasyprint readily supports them among free or open-source options (and only since around September).
<?php
$pagenum = 1;
$pagenum++;
print("Page: $pagenum");
?>
As far as pagination is concerned I wrap each page in this tag
<page size="A4"> </page>
with this css:-page[size = 'A4'] { height: 29.7cm; width: 21cm; page-break-before: always; }
page[size = 'A4'][layout = 'portrait'] {
height: 21cm;
width: 29.7cm;
}
So that's the incredibly complex and challenging problem of pagination solved.And fortunately html does layout too.
if (rowcount > 100) newpage();
But lets use an entirely new, esoteric PDF specific layout language instead and we wont call that the "hard part".
Actually to be fair it obviously depends on the situation. If you are churning out large volumes of PDFs then it might make sense to get the efficiency with a PDF-specific language. But HTML -> PDF definitely has its place too and is not as hard to work with as people are claiming.
1: https://www.w3.org/Style/CSS/Tracker/issues/334
2: https://github.com/w3c/csswg-drafts/issues/4760
3: https://github.com/Kozea/WeasyPrint/issues/93#issuecomment-4...
<?php
$pagenum = 1;
$pagenum++;
print("Page: $pagenum");
?>
These are all things that good page layout software can deal with easily.
HTML to pdf is also pretty slow and unreliable when you want a table of contents or an index with page numbers. On a fast machine, a 200 page PDF can take several minutes to generate. PrinceXML is the only software I’ve tried that does a good job of it. For very simple documents (no CSS, limited Unicode) HTMLDoc is pretty good and very fast.
Content matters for row height, as does fonts, styling, etc. Footers, too. The number of footnotes (thus the height of the footer) can depend on the page content, too.
Maybe there's an image in there, or some sort of specially styled content that makes the line height larger than normal.
You have to be able to render the row to know the final dimensions, to be able to make a call whether it should go on that page or the next. If you don't, then you end up with one page actually rendering over into a second page.
I've heard good things about https://github.com/Kozea/WeasyPrint in Python.