I am getting the following error when I use the puppeteer for generating the PDF file,
Error: Protocol error (Runtime.callFunctionOn): Target closed. at Promise (C:\Users\Rakshith.Shivaram1.MEA\Documents\EY_SARGE_PROJECT\git\26-06-2020\puppeteer-proj\git\html2pdf-puppeteer\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:208:63) at new Promise () at CDPSession.send (C:\Users\Rakshith.Shivaram1.MEA\Documents\EY_SARGE_PROJECT\git\26-06-2020\puppeteer-proj\git\html2pdf-puppeteer\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:207:16) at ExecutionContext._evaluateInternal (C:\Users\Rakshith.Shivaram1.MEA\Documents\EY_SARGE_PROJECT\git\26-06-2020\puppeteer-proj\git\html2pdf-puppeteer\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:200:50) at ExecutionContext.evaluate (C:\Users\Rakshith.Shivaram1.MEA\Documents\EY_SARGE_PROJECT\git\26-06-2020\puppeteer-proj\git\html2pdf-puppeteer\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:106:27) at DOMWorld.evaluate (C:\Users\Rakshith.Shivaram1.MEA\Documents\EY_SARGE_PROJECT\git\26-06-2020\puppeteer-proj\git\html2pdf-puppeteer\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:79:24) at process._tickCallback (internal/process/next_tick.js:68:7)
using the below code for launching puppeteer
const browser = await puppeteer.launch({
pipe: true,
args: [
'--headless', '--disable-gpu', '--full-memory-crash-report', '--unlimited-storage',
'--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'
]
})
for setContent
with timeouts
await page.setContent(htmContent, { waitUntil: 'networkidle0', timeout: 80000 })
Please let me know is it possible to generate a large PDF file out of an HTML content?
The complete code for converting the Small HTML content to PDF file,
const browser = await puppeteer.launch({
// executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
headless: false,
pipe: true,
args: [
'--headless', '--disable-gpu', '--full-memory-crash-report', '--unlimited-storage',
'--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'
]
}).catch((el) => {
console.log('browser', el);
next(createError(el));
});
const page = await browser.newPage();
await page.setDefaultNavigationTimeout(0);
// await page.waitFor(80000);
await page.setRequestInterception(true);
page.on('request', interceptedRequest => {
interceptedRequest.continue();
});
const version = await page.browser().version();
console.log('chromium version', version);
// var buffer = new Buffer(htmContent);
// var bufferBase64 = buffer.toString('utf-8');
await page.setContent(htmContent,
{
waitUntil: 'load',
timeout: 0
}).catch((ep) => {
console.log('setContent', ep);
next(createError(ep));
});
// await page.setDefaultTimeout(0);
await page.waitFor(300000).then(async () => {
// page.emulateMediaType('print');
// const pdf = await page.pdf({ fullPage: true });
console.log('page.waitFor(300000) done');
page.on('load', () => console.log('Page loaded!'));
const pdf = await page.pdf({ fullPage: true });
await page.waitFor(300000).then(() => {
console.log('page.waitFor(300000) done');
res.set('Content-Type', 'application/pdf');
res.header("Access-Control-Allow-Origin", "*");
res.send(pdf);
});
});
// const pdf = await page.pdf({ fullPage: true });
// res.set('Content-Type', 'application/pdf');
// res.header("Access-Control-Allow-Origin", "*");
// res.send(pdf);
await browser.close().catch((eb) => {
console.log('browser.close', ep);
next(createError(eb));
});
});