Szpadel / chrome-headless-render-pdf

223 stars 67 forks source link

Add support for "headerTemplate" and "footerTemplate" to be used in Chrome's printToPDF method #40

Closed Eitz closed 3 years ago

Eitz commented 6 years ago

Reference material is here:

https://chromedevtools.github.io/devtools-protocol/tot/Page#method-printToPDF

aurelienbobenrieth commented 3 years ago

Hello,

I've been trying to use your branch as a local package for one of my project. However I am not managing to make it work.

The footer template provided in your example only appear at the bottom of my very last page, and does not contain any number. Only the "/" is showing.

I have something like this (php) :

$bin = 'node ' . base_path() . '/node_modules/chrome-headless-render-pdf-canary/cli/chrome-headless-render-pdf.js --include-background --display-header-footer --footer-template \'<div class="footer"><span>Page </span><span class="pageNumber"></span><span> of </span><span class="totalPages"></span><style type="text/css">.footer {width:100%;border-top : solid 1px gray; padding-top : 2.5mm;}.pageNumber {color : red;font-size:5px;}</style></div>\' ' .$chrome.' --url file://' . $pathHTML . ' --pdf ' . $pathPDF;

Do you have an idea of what I am doing wrong ?

EDIT : This is driving me crazy. Actually it shows up on every pages (but hidden by some printed elements for some reason). But the main problem is that, the pageNumber are actually showing up UNLESS :

This is nonsense to me

EDIT 2 : Holy molly. I managed to make it work. My print CSS was for some reason conflicting with the generation it seems. I had to reset some things but it now seem to work. I removed every margin / padding property which were on my html/body and @page.

Eitz commented 3 years ago

Hey @aurelienbobenrieth, sorry, just saw your comment now. Yeah, the CSS for these pages is pretty crazy sometimes. Glad you were able to get it working.