I have encountered a challenge with exporting a multipage HTML document to PDF using headless Google Chrome / Chromium from the command line. The issue arises when Chrome automatically adds headers and footers during the "printing" process. Although some have suggested using @page {margin: 0}
in CSS to remove them, this solution only seems to work for a limited number of pages, resulting in a footer appearing on the last page of the example.
While there is an NPM package available that supports header-free exports, it comes at the cost of taking approximately 30% more time than utilizing headless Chrome directly. Additionally, implementing NPM and the package on our company's servers would be necessary.
If anyone has insights on how to hide Google Chrome's default headers and footers during headless PDF-export using CSS or settings adjustments, I would greatly appreciate any guidance shared.
In the absence of an alternative solution, I opted for the NPM package. While it has proven to be effective and reliable thus far, it does require additional time compared to using headless Chrome alone, so this aspect should be taken into consideration.