I have a simple node js function which converts html string to PDF using the node js puppeteer
library. Im attempting to convert an index.html file which is 400++ KB in size. However, the resulting PDF I got was more than 150MB. Is there anything Im doing wrong?
const generatePDFromHTML = async (htmlString: string, outputPath?: string) => {
const browser = await puppeteer.launch({ headless: true, defaultViewport: { width: 1366, height: 768 }, args: ['--font-render-hinting=none'] });
const page = await browser.newPage();
await page.setContent(htmlString, { timeout: 0 });
const pdfOptions: puppeteer.PDFOptions = {
format: 'a3'
}
if (outputPath) {
pdfOptions.path = outputPath
}
const pdfBuffer = await page.pdf(pdfOptions);
await browser.close();
return pdfBuffer
}
I tried opening index.html in safari and use the CMD+P
command to save the html page as PDF and the resulting PDF is only 15MB in size. Im expecting Puppeteer to produce PDF of the same size