I'm using this simple code to generate a pdf document from http://example.com/ but I keep getting a blank pdf generated ...
Am I missing something ?
const puppeteer = require('puppeteer');
puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] }).then(function (browser) {
browser.newPage().then(function (page) {
page
.goto('http://example.com/', { waitUntil:['domcontentloaded', 'networkidle0','load'] })
.then(page.pdf({ path: 'result.pdf', format: 'letter' }))
.then(() => {
browser.close();
})
})
})
I used the no-sandbox option because of kernel issues.
I'm using CentOS 7
I had to wait for the promise in page.goto().then ...
const puppeteer = require('puppeteer');
puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] }).then(function (browser) {
browser.newPage().then(function (page) {
page
.goto('https://www.example.com', { waitUntil: ['domcontentloaded', 'networkidle0', 'load'] }).then(function (response) {
// page.emulateMedia('screen')
page.pdf({ path: 'result.pdf', format: 'letter' })
.then(function (res) {
browser.close();
}).catch(function (e) {
browser.close();
})
})
})
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With