Set template page size for all templates



  • Hi, we run several servers that service different geographic regions. They all offer multiple reports that run off the same set of templates (using chrome-pdf)

    The main issue is that for the USA server, these report templates need to be set to US letter, but the other servers use A4.

    Is there a way to set this page size centrally within a server instance? At the moment what I need to do is go into each template and switch them from A4 to US Letter and back again.



  • You can do this using jsreport custom script
    https://jsreport.net/learn/scripts

    You can use, for example, an environment variable and change the paper size dynamically based on that.

    const process = require('process')
    function beforeRender(req, res) {
       const myEnv = process.env.MY_ENV
       if (myEnv === 'foo') {
          req.template.chrome.format = 'A4'
       }
    }
    


  • Hi Jan, just a note that I finally implemented this and it works well, thanks :)

    I have a related question but will open up as a new topic


Log in to reply
 

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