Phantom pdf footer problems



  • I have two problems.

    1. I want to load moment in footer in order to show the generated date with the correct offset for each client.
      So I added moment script from cdn source provided in https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment.js
      But it doesn't work.
      I think it needs to prefetch the library somehow. Is there a way to use npm module "timezone" instead?? I tried but didn't work.

    2. Also I want to take the date format provided by the client in the data. So I have the following sample data:
      {
      "filters": {
      "dateFormat": "yy-dd-mm",
      "timezone": "10800"
      }
      }

    But when I try to read "dateFormat" for some reason it crashes. However the "timezone" is read correctly.

    I have created a test example https://playground.jsreport.net/studio/workspace/rkAYJZNG-/2 with some code commented out in the footer in order not to crash.
    If you uncomment the line with code "return {{:filters.dateFormat}}"
    nothing is returned.

    How can I fix those??



  • phantomjs doesn't allow async request to the resources, but you can use asset to store the whole script and inline it in footer.

    Another option, which sounds better to me, is to use handlebars helpers to work with moment. You can call require('moment') in helpers and use it to format your data from there.



  • Thank you. Any ideas for the second question?



  • I didn't get it, it is not crashing for me if I un-comment the return. Anyway I guess the problem will likely go away if you use the helpers to format the date.



  • So if you uncomment
    return {{:filters.dateFormat}} and comment
    return {{:filters.timezone}};

    does it print "yy-dd-mm" at the footer??

    It's not an easy task to change from jsrender to handlebars because I have created many functions that are common between my templates that have to be duplicated and changed also. So, if possible, I have to find a solution using jsrender.



    1. The jsrender instead of the handlebars doesn't matter. You can write custom jsrender helper as well.

    2. You need to use return as this. I believe you find out why if you think it through.
      return '{{:filters.dateFormat}}'



  • Thank you very much for your time.


Log in to reply
 

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