Thanks for tracking the request. I commented on the GitHub issue and will keep track of it there!
colinhemphill
@colinhemphill
Posts made by colinhemphill
-
RE: Rendering PDF using chrome-pdf results in large file size
-
Rendering PDF using chrome-pdf results in large file size
I am generating a PDF in Node.js using the jsreport Chrome-PDF recipe. I load an external HTML file and use that as the template for the report, and then pipe the generated report back to the browser. My setup looks like this:
await jsReport.init() try { const out = await jsReport.render({ template: { content: html, engine: 'handlebars', recipe: 'chrome-pdf', chrome: { format: 'Letter', printBackground: true, marginTop: '0.25in', marginRight: '0.5in', marginBottom: '0.25in', marginLeft: '0.5in' } }, data: { myData: myData } }) return out.stream.pipe(res) } catch(err) { return res.status(500).send(err) }
The PDF loads in the browser and looks great! However, when I save the report, the file comes out to roughly 25 MB. There are a few images in the rendered PDF, but this is obviously way larger than it needs to b e.
I can take the file and run it through a service like Smallpdf or Acrobat, and the file comes out to under 200 KB. Is there a way that I can reduce the initial file size before streaming it to the client? I'd like to avoid my clients having to use external software each time they generate a report, and I would also like to avoid having to use a third-party API to do the compression at a fee.