4 ms·
There's a good matrix of feature support at https://print-css.rocks/lessons https://print-css.rocks/lessons for all the things HTML-to-PDF engines can (and can'
by trynewideas 4y ago
There's a good matrix of feature support at https://print-css.rocks/lessons https://print-css.rocks/lessons for all the things HTML-to-PDF engines can (and can't) do.
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).
- lazyeye 4y agoHere's some PHP code to handle page numbering :- <?php $pagenum = 1; $pagenum++; print("Page: $pagenum"); ?>
- recursive 4y agoThat prints "Page: 2". It doesn't appear anything related to pagination or layout.
- lazyeye 4y agoWell obviously you'd have that code on each page. So thats the incredibly complex and challenging page numbering problem solved. 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.
- recursive 4y agoYou're just pushing complexity around. Now you have to figure out how much content you can put on each page before you have to make a new one. The reason it seemed so easy is that you just deferred the hard part.
- lazyeye 4y agoNope. What you call the "hard part" is 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.
- recursive 4y agoYou did it again. What's a row? Are you telling me that 100 of them will fit on any page, regardless of font size or margins?
- lazyeye 4y agoWhy would you be randomly changing the font-size or margin? Surely that would be known in advance?
- recursive 4y agoSometimes they might be. But even if you know the font size of the headers, the contents, and the bulleted lists, you still won't know where the paragraphs wrap, unless you also require a fixed-width font, and don't allow any of the word lengths to change. But then we probably wouldn't be calling it a "modern library for PDF generation".