phantomPDF Reference error



  • When using PhantomPDF, my html has a script tag with a function in it, the phantomJS engine is unable to see the function that is clearly vailable to html.
    However it does not seem to have a problem with javascrip that has been linked by URL.

    Does phantomPDF not support inline javascript within the template?



  • ReferenceError: Can't find variable: ExecuteSubReport
    +5614 file:///C%3A%5CTFS%5CCIMProduction%5CLegerMetrics-PROD%5CReportingEngine.Render%5Cdata%5Ctemp%5C34c2bba0-c404-11e7-a398-c7135b702ef0html.html : 278

    where ExecuteReport is in a script tag in the body and is seen fine by the html recipe


  • administrators

    Does phantomPDF not support inline javascript within the template?

    yes, it does. you are doing something like this, right?

    can you share the code that is working only in html recipe but not in phantom pdf.

    also just in case, remember that phantomjs does not support JS ES6, so having some ES6 in your template's js can lead to this problem too.



  • Hi,
    I solved the problem :-)

    The function i was referring to was dependent on Jquery for ajax calls, i was not waiting for the document to be ready within the phantomJS context.
    I wrapped the code in a document ready callback, as such:

    $(document).ready(function(){
    //function declaration here
    
    //function execution here
    
    });
    

    Now phantomJS sees the javascript as well as the jquery code.
    I tried having multiple document ready callbacks to cleanup the code, but that did not work because of what I assume is some sort of race condition between script loading. We have to remember that phantomJS bahaves as a rudimentary browser.


  • administrators

    glad that you found the solution 😃

    We have to remember that phantomJS bahaves as a rudimentary browser.

    haha i'm sure phantom will be a thing of the past, just wait a little more and we will have great news for you.



  • I will gladly beta test if you need it. your product has great potential.


  • administrators

    we are planning to replace phantom with chrome as the default engine for jsreport, here is the recipe ready for use (it requires node 8 btw) if you want to experiment. we are just waiting that Chrome headless mode become more stable and eventually to support pdf header and footer (unfortunately at this point phantomjs is the main engine that only support pdf header and footer natively) to make this the default.


Log in to reply
 

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