Generate PDF Document From docx templates directly



  • Hi John,

    Can you help me if there is way by which we can generate pdf document by providing Docx template and Data as Input to JsReport.

    I have seen the existing feature of JsReport where we initially convert docx into html template and then we can generate pdf using JsReport with chrome-pdf recipe.

    But I need to skip this intermediate step of converting docx to html template so that I can generate pdf from docx directly.

    Thanks & Regards
    Zahid Khan



  • Hi,

    we have the docx recipe now part of jsreport. It can product docx reports based on the docx templates.
    https://jsreport.net/learn/docx

    Additionally, there is the custom jsreport extension that can convert docx reports into the pdf.
    https://jsreport.net/learn/unoconv



  • Hi Jan,

    I have installed the unoconv extension on my server from https://jsreport.net/learn/unoconv and tried to generate pdf from docx template and jason data using docx recipe and handlebar engine. I am getting the below error

    TypeError: Cannot read property 'getElementsByTagName' of undefined
    at module.exports (C:\jsreportapp\node_modules\jsreport-docx\lib\postprocess\style.js:40:26)
    at module.exports (C:\jsreportapp\node_modules\jsreport-docx\lib\postprocess\postprocess.js:6:3)
    at Object.execute (C:\jsreportapp\node_modules\jsreport-docx\lib\recipe.js:70:9)

    When I enable unoconv to generate pdf I got above error but when I disabled unoconv then docx report generated successfully.

    Kindly help me if I am missing some configuration.

    Thanks
    Zahid Khan



  • Would you be able to share your entities' export zip?





  • Sorry for the above message I am not able to upload the export.zip. It's seem's I don't have permission.
    By the way I am using default example of docx.cv which is there on JsReport Playground.



  • My apologies. I've tested the unoconv with docx recipe and there was really a bug you mentioned.
    It is now fixed in jsreport-unoconv@0.3.0. Please install it using

    npm i jsreport-unoconv@0.3.0 --save
    


  • Thanks @jan_blaha will install the latest version of unoconv package😊.



  • Hi Jan,

    I had updated the latest package of unoconv@0.3.0 and I was able to successfully generate the pdf from docx template and data using docx recipe.
    
    Pdf generation using unoconv is not full proof. Sometime it throw the below error =>
     
    2019-11-14T06:35:21.085Z - warn: Error when processing render request Timeout 
    error during executing script Error: Timeout error during executing script
    at Timeout._onTimeout (C:\jsreportapp\node_modules\script-manager\lib\manager-servers.js:164:25)
    at ontimeout (timers.js:436:11)
    at tryOnTimeout (timers.js:300:5)
    at unrefdHandle (timers.js:520:7)
    at Timer.processTimers (timers.js:222:12).
    
    
    
    After this whenever I am trying to generate any report (docx to docx , docx to pdf, html-pdf, html-docx,etc.), server throws below error =>
    
    2019-11-14T06:35:41.932Z - debug: Base url not specified, skipping its injection.
    2019-11-14T06:35:41.933Z - debug: Rendering engine handlebars
    2019-11-14T06:35:41.973Z - warn: Error when processing render request Bad request Error: Bad request
    at IncomingMessage.<anonymous> (C:\jsreportapp\node_modules\script-manager\lib\worker-servers.js:228:25)
    at IncomingMessage.emit (events.js:203:15)
    at IncomingMessage.EventEmitter.emit (domain.js:466:23)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    
    For every request afterwards jsreport server throws the above error.
    
    Then I have to restart the jsreport server every time when I am getting above error after then only I am able to generate documents.
    
    Kindly share your thoughts.
    
    Zahid Khan.


  • Hi Jan,
    One more important thing I forget to mention here I am generating the large document around 1000 page pdf from 1 page docx template with large json data resulting report should be more than 1000 pages.

    I think this would be the reason why it's taking time becuase first it would convert the docx report from docx template and data, Then it would convert it into pdf using unoconv extension.

    My timeout in jsreport configuration is

    "scripts": {
    "timeout": 40000,
    "strategy": "http-server"
    },
    "templatingEngines": {
    "timeout": 10000,
    "strategy": "http-server"
    },
    "chrome": {
    "timeout": 40000
    }

    Suggest me if I need to increase the timeout here or something else I need to do.

    Thanks,
    Zahid



  • For every request afterwards jsreport server throws the above error.
    Then I have to restart the jsreport server every time when I am getting above error after then only I am able to generate documents.

    This is the regression issue only present for http-server strategy.
    It is fixed in jsreport 2.6.1

    The right timeout to increase is this one. It isn't obvious, we will fix it in the upcoming release and provide general render timeout instead.

    "templatingEngines": {
      "timeout": 60000,
      "strategy": "http-server"
    }
    


  • Thanks @jan_blaha I had increased timeout to 20000 ms now I am able to generate 1000 plus report pdf, from docx template and data using unoconv.

    "templatingEngines": {
    "timeout": 60000,
    "strategy": "http-server"
    }

    Will install the latest version of jsreport 2.6.1 and then try to use above configuration.

    Thanks for all your help. You guys are doing really a good job, please continue with the good work :-)

    Thanks,
    Zahid


Log in to reply
 

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