miyakogi / pyppeteer

Headless chrome/chromium automation library (unofficial port of puppeteer)
Other
3.56k stars 372 forks source link

Remove background for PDF export. #188

Open vindolin opened 5 years ago

vindolin commented 5 years ago

When I export a pdf, the resulting file always has an opaque background.

This is problematic when one wants to combine the exported pdf with an existing background/header/footer in another pdf via pdftk.

For the node version there's an ugly workaround that uses page._emulationManager._client for setting the background to transparent.

GoogleChrome/puppeteer#2545

await page.emulateMedia('screen');
await page._emulationManager._client.send(
  'Emulation.setDefaultBackgroundColorOverride',
  { color: { r: 0, g: 0, b: 0, a: 0 } }
);
await page.pdf({
    path: 'transparent.pdf',
    printBackground: true,
    displayHeaderFooter: true // White background comes back after setting this
});

Can this be done with pyppeteer?

catmando commented 5 years ago

We also need this functionality

jplevene commented 5 years ago

Can confirm, but this looks like it is a Chrome issue. This means that PDFs generated with headless Chrome can't have watermarks added or merged properly into other documents with watermarks or backgrounds.