westmonroe / pdf-puppeteer

A simple NPM package to convert HTML to PDF for Node applications by using Puppeteer
BSD 3-Clause "New" or "Revised" License
123 stars 27 forks source link

HTML background image not rendered #44

Closed beabri closed 3 years ago

beabri commented 3 years ago

Hi everyone,

my HTML content has a base64 background image which is not rendered at all. The CSS rule is this:

html {
       zoom: 1;
       background-image: url('data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAABkAAD/4QPtaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjYtYzE0MCA3OS4xNjA0NTEsIDIwMTcvMDUvMDYtMDE6MDg6MjEgICAgICAgICI......');
       background-repeat: no-repeat;
       background-size: cover;
       width:595px;
       height:839px;
}

I read that using puppeteer library the issue can be solved this way (from https://github.com/puppeteer/puppeteer/blob/main/docs/api.md#pagepdfoptions):

image

But how can we set this using your "convertHTMLToPDF" function?

beabri commented 3 years ago

Inserting "printBackground: true" as page option did the job.