question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

page.pdf headerTemplate and footerTemplate. Certain CSS styles not working.

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: v1.3.0
  • Platform / OS version: Windows 7 Enterprise. Service Pack 1
  • URLs (if applicable):
  • Node.js version: v8.11.1

What steps will reproduce the problem?

We are in the process of migrating from phantomJs 1.9.x to use Chrome headless browser. The existing headers and footers contain block elements, float styles and a img tag. None of these are working in puppeteer. Are these not supported? The documentation states ‘valid HTML markup’. https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions

The example below contains h1 block element tags but they being displayed inline. The html works fine in a standard html page displayed in chrome.

Please include code that reproduces the issue.

const puppeteer = require('puppeteer');

var header = "<h1>H1 tag</h1><h2>H2 tag</h2><hr style='border-bottom: 2px solid #8c8b8b;' />";

(async () => {
    var browser = await puppeteer.launch();
    var page = await browser.newPage();
    await page.goto('http://www.example.com/', { waitUntil: ['domcontentloaded', 'networkidle0'] });

    await page.pdf({
        path: 'sample.pdf',
        landscape: false,
        displayHeaderFooter: true,
        headerTemplate: header,
        margin: {
            top: '100px',
            bottom: '10px',
            right: '20px',
            left: '20px'
        }
    });

    await browser.close();
})();

What is the expected result? The header renders in the same way as the Html does in a web page. The H1 and HR tags behave as block elements.

What happens instead? All the elements appear in a single line as though they are inline elements.

I’ve attached a HTML page containing the sample. sample.zip

Thanks,

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

7reactions
DavidKisielcommented, Apr 17, 2018

Thanks for the answer, that’ll explain it.
As PhantomJs did support the above example could this be a future feature. So the supporting of full HTML in the header and footer templates?

6reactions
ItsTarikcommented, Jun 2, 2018

any response to @DavidKisiel proposal before closing the issue ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

puppeteer header and footertemplate doesnt work
Please try the following templates: headerTemplate: '<span style="font-size: 30px; width: 200px; height: 200px; background-color: black; ...
Read more >
Using the Puppeteer Header Template with Images and Styles
Learn how to use Puppeteer header templates and how we customized them with our service to make it easier and more feature rich....
Read more >
IPdfOptions | PhantomJsCloud.com API Documentation
//full api request JSON example showing use of header template { url: ... Note: page css is not available to this template, so...
Read more >
Set background image and/or color in Header and Footer in ...
Footer layout: [pageNumber / totalPages] footerTemplate=' <style type="text/css"> .footer-background {
Read more >
PDF Gotchas with Headless Chrome - Nathan Friend
page.pdf({ headerTemplate: '<h1>This is the header! ... Because of this, the CSS styles that apply to the content won't apply to the header ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found