Cannot remove headers and footers from pdf rendered by chrome --headless --print-to-pdf

2,376 views
Skip to first unread message

Shailendra Singh

unread,
May 16, 2018, 9:28:51 AM5/16/18
to headless-dev
Hi Team,

I am using chrome in headless mode to render html file in pdf format. The pdf is fine but it has the default headers and footers. I even tried adding below code to html file. It removes the headers and footers except from the last page of every multipage pdf. Why ? How should I resolve this? Is there any flag present to disable the headers and footers? Please also see the attach file rendered from chrome --headless --print-to-pdf option with below fix in html 

<style>

 
@page {
 margin
: 0;
 size
: A4 portrait;
 
}

</style>

Kindly help. Thanks
output1694.pdf

Eric Seckler

unread,
May 17, 2018, 4:14:21 AM5/17/18
to Shailendra Singh, headless-dev
You can use DevTools (e.g. via puppeteer) to issue Page.printToPDF, where you can specify whether headers/footers should be rendered. The command line flag (--print-to-pdf) always renders them.

--
You received this message because you are subscribed to the Google Groups "headless-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to headless-dev...@chromium.org.
To post to this group, send email to headle...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/headless-dev/b153514f-8da9-4334-a891-3679e9eb5c8a%40chromium.org.
Reply all
Reply to author
Forward
0 new messages