Headless PDF printing in Chrome: when the standard timeout isn't enough
tl;dr: use the node.js module html-pdf-chrome to print programmatically, not Chrome's built-in virtual-time-budget. See my print.js file for an example.
My CV is generated automatically from Birkbeck's online repository. It uses a system that basically generates a paginated version of the CV in the browser, using CSS regions technologies, then does a headless print via Chrome. All the source code is available for this.
The problem is that Chrome has an option to wait until the page has fully rendered before printing. If you Google it, you'll get the answer that you should use the –run-all-compositor-stages-before-draw and –virtual-time-budget=10000 flags.
However, these do not work in the case of my CSS regions work. Regardless of how high I set the virtual time budget, on ultra-fast hardware, Chrome truncated the PDF.
I finally found a new solution in the node.js module html-pdf-chrome. You can see how this is now called inside my print.js file but, essentially, this allows for a timed completion trigger before it sets off the print. Setting this to 5000ms was more than adequate for my purpose.
Headless PDF printing in Chrome: when the standard timeout isn't enough was originally published by Martin Paul Eve at eve.gd: Martin Paul Eve on October 18, 2021.
Files
10.59348_1tta7-hnj71.pdf
Files
(98.6 kB)
| Name | Size | Download all |
|---|---|---|
|
md5:8436dad3d06df7cd25bb88553bbcc95e
|
98.6 kB | Preview Download |
Additional details
Description
Identifiers
- GUID
- https://doi.org/10.59348/1tta7-hnj71
- URL
- https://eve.gd/2021/10/18/headless-pdf-printing-in-chrome-when-the-standard-timeout-isnt-enough/
Dates
- Issued
-
2021-10-17T00:00:00Z
- Updated
-
2021-10-17T23:00:00Z