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.


  • administrators

    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 guess chrome does not optimize the pdf for the kind of content you have, how many pages the pdf contain? we don't have anything like pdf compression yet, but it is a nice idea that we can explore.

    probably your pdf contain a lot of metadata generated by chrome and services like Smallpdf reduce the size significantly by removing them.

    i have opened an issue for this, you can keep track here. it will be helpful to have the same html that you are producing so we can test the same scenario and see the same reduction in size.



  • Thanks for tracking the request. I commented on the GitHub issue and will keep track of it there!



Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.