Make sure pdf is ok before send to client



  • Hello, I create a jsreport server on linux. But currently it has an error displaying the font as below
    0_1710918893262_upload-621e7066-0df3-4e0f-8c0b-91a6eddc02d6
    the correct is: "Xác nhận"

    But I deploy it in many different services so I don't want to change all that code. So I want to do something after jsreport generates PDF like below:
    0_1710920230129_upload-e404dc24-7fa4-4b20-a109-d054c9021f3a

    I wonder if there is a way to override the jsreport.render function so that it adds a check before returning it. If there is an error, then recreate it. Or another way that you suggest?

    P/s:
    Because it's happen randomly so i use this way



  • Can't you install the fonts on the particular servers? With something like

    apt install -y fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst 
    

    I wonder if there is a way to override the jsreport.render function so that it adds a check before returning it.

    The easiest would be to add the custom jsreport script and afterRender hook that will check whats needed and run the render again.
    https://playground.jsreport.net/w/anon/E1fuYNgc



  • Hello.

    Case wrong font:

    I copy folder with files like below into linux and install font. In jsreport.config.json i set:
    "pdf": {
    "fontDirectory": "/root_etc/fonts/"
    },

    0_1711683689173_upload-e80361b7-1d22-49b4-8ce4-01417d2f1718

    Most of the times it works fine. But sometimes the system load is exceptionally high. The font will be wrong.


    Case rerender i use it but not work:

    const jsreport = require('jsreport')()
    async function afterRender (req, res) {
    	
    	console.log("----------------------------- HELP...")
        // do some checks if res.content is ok
        if (req.data.counter > 10) {
    	console.log("----------------------------- XXXX...")
            return
        }
            
        const r = await jsreport.render({
            template: { ...req.template },
            data: { ...req.data, counter: (req.data.counter || 0) + 1 }
        })
        res.content = r.content  
    }
    if (process.env.JSREPORT_CLI) {
      // export jsreport instance to make it possible to use jsreport-cli
      module.exports = jsreport
    } else {
    	console.log("INIT!")
      jsreport.init().then(() => {
        // running
      }).catch((e) => {
        // error during startup
        console.error(e.stack)
        process.exit(1)
      })
    }
    

Log in to reply
 

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