PDF Utils: How to modify reports used for pdf utils on execution



  • Hi all, I need a way to add/remove some reports dynamically using pdf-utils, based on some computation on data (chrome recipe). For example, if in datas that came from an application there's a particular option, i need to add a report on prepend/append.

    I've tried a solution involving a script on beforeRenderer, that change req.template.pdfOperations based on data:

    
    function beforeRender (req, res, done) {
    ...
    var operations = [];
    if(<something>) {
    //Add a report
            operations.push({
                "type": "append",
                "templateShortid": "xxxxx",
                "mergeToFront": false,
                "renderForEveryPage": false,
                "mergeWholeDocument": false
            });
        }
    ...
    req.template.pdfOperations = operations;
        
    done();
    

    On the first run, everything it's ok; the problem is on the following run, because my first run configuration has been saved on template, and so it's useless to change req.template.pdfOperations on the run as the previous one is still ongoing, discarding my changes and producing unwanted results.

    In fact, If I refresh the studio, i can now see my template configuration having report appended in pdf-utils windows, according to my first execution (initially it has nothing).

    I've tried some cleansing on an afterRenderer, but without success.

    There's a way to avoid the change of my initial configuration? Or there's another way to modify dynamically the pdf-utils list?

    Thanks.



  • In fact, If I refresh the studio, i can now see my template configuration having report appended

    I think this was a bug which was quickly hotfixed. Please update jsreport. The change through script should not be persisted in any way of course.

    On the first run, everything it's ok; the problem is on the following run,

    I think you should just exit the script for the "child" requests that are generated because of the pdf utils.

    function beforeRender(req, res, done) {
        //filter out script execution for child nested requests like pdf utils, child templates and headers
        if (req.context.isChildRequest)
          return done();
    
        //your script
        done();
    }
    


  • Mmhh there's something strange.
    I've try to replicate on the playground https://playground.jsreport.net/w/dfiorentin/KuHWJU0z and it works correctly. However, if I use the same on my configuration, the utils has been overwritten.

    My package list is the following:

    {
      "name": "jsreport-server",
      "dependencies": {
        "jsreport": "2.3.0",
        "jsreport-chrome-pdf": "1.2.2",
        "jsreport-pdf-utils": "1.2.1",
        "jsreport-studio": "2.3.3"
      },
      "main": "server.js"
    }
    

    So this should be the last jsreportversion (i've done another npm install again just now).

    About my jsreport configuration, I've tried to remove all of template's options in search of the problem, but I still have the issue, even with the following configuration:

    {
      "certificate": {
        "key": "certificates/jsreport.net.key",
        "cert": "certificates/jsreport.net.cert"
      },
      "httpPort": 3001,
      "license-key": "----",
      "store": {
        "provider": "fs"
      },
      "extensions": {
        "authentication": {
          "cookieSession": {
            "secret": "---"
          },
          "admin": {
            "username": "---",
            "password": "---"
          }
        }
      }
    }
    

    Am I missing something?



  • Some new information that could help: we save report in fileSystem and not in DB, can be related to this the problem?
    Another thing: I noticed that if I run the report, reload the page and reopen the template, the report has the parameters of the util modified. If I turn off and on jsreport again, the configuration of the template returns to the original one. Is there any caching system that creates conflict?


  • administrators

    can you put this in a github repository? so we can try to replicate the same problem in our environtment, also specify which report is causing the issue so we can run it and test it. thanks


  • administrators

    let's continue the conversation on this github issue, we will post the resolution here once it is clarified what is happening


Log in to reply
 

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