import WebpageToPdf from 'webpage-to-pdf';
(async () => {
const wtp = new WebpageToPdf();
await wtp.init({
parallelRequests:3,
shareCookies: true
});
wtp.convertPageToPdf('https://www.google.com');
wtp.convertPageToPdf('https://github.com/bhups-83/webpage-to-pdf/blob/main/README.md',
{
'referer': 'https://github.com'
}
);
await wtp.saveAllPagesToPdf("./output.pdf");
})();
On windows, there is a bug with shipped chrome. Current workaround is to pass --no-sandbox
args to the underlying puppeteer library, which in turn passes it to chrome.
import WebpageToPdf from 'webpage-to-pdf';
(async () => {
const wtp = new WebpageToPdf();
await wtp.init({
parallelRequests:1,
options: {
headless: true,
timeout: 0,
args: ["--no-sandbox"],
}});
wtp.convertPageToPdf('https://www.google.com');
wtp.convertPageToPdf('https://www.google.com');
await wtp.saveAllPagesToPdf("./output.pdf");
})();