NodeJS with Puppeteer: how to set the margins of each pages (or scale all of them to fit the magins)?

Viewed 3835

I tried to just use below setting but turn out the header and footer positions will be changed. Please advise.

await page.pdf({
    path: FILENAME,
    format: 'A4',
    margin: {
        top: "0px",
        right: "0px",
        bottom: "0px",
        left: "0px"
    },
    printBackground: true // required for photos otherwise blank
});
1 Answers

try preferCSSPageSize: true in page.pdf options. This allows you to specify the margin's for page in the CSS and it will take priority. **place CSS **

<style>
    @page 
{ 
    size: A4 portrait;
    margin:0; 
}
</style>
Related