Render Docx to PDF without assigned template



  • To save setting up a new docker to handle file conversion, we are wondering if we can use JSReports to handle the conversion from docx to pdf. We have already proved that we can use unoconv to take the docx and get the PDF that we want. Now we are trying to do it from our .NET app by passing in the docx file to the template and getting it to do the unoconv for us. We are failing at getting it to pass in the whole template. We have verified that the byte array and memory stream are valid. We made the assumption that we need to base64 encode it. When trying to pass the encoding type, it errors that it's a read-only property.

    Here is the pseudo-code for what we do:
    Create a template in JSReports but don't put set the Docx, enabled Unoconv and output to PDF
    Load the template via OData to .NET Code
    Load the Docx from external source and set it using the follwoing:

    	testDocx = new Docx() {
    		TemplateAsset = new Asset()
    		{
    			Content = {MyBase64String}
    		}
    	};
    	conversionTemplate.Docx = testDocx;
    

    Then call RenderAsync() passing in the template and NULL for data with the correct options.

    I get this error:
    Report "word" render failed.

    Error while executing docx recipe. end of central directory record signature not found
    Error: Error while executing docx recipe. end of central directory record signature not found
    at module.exports (/app-rprt/node_modules/@jsreport/jsreport-core/lib/shared/createError.js:10:13)
    at WorkerReporter.createError (/app-rprt/node_modules/@jsreport/jsreport-core/lib/shared/reporter.js:47:12)
    at /app-rprt/node_modules/@jsreport/jsreport-docx/lib/processDocx.js:93:20
    at async module.exports (/app-rprt/node_modules/@jsreport/jsreport-docx/lib/recipe.js:38:28)
    at async invokeRender (/app-rprt/node_modules/@jsreport/jsreport-core/lib/worker/render/render.js:95:5)
    at async WorkerReporter._render (/app-rprt/node_modules/@jsreport/jsreport-core/lib/worker/render/render.js:147:7)
    at async /app-rprt/node_modules/@jsreport/jsreport-core/lib/worker/reporter.js:179:19
    at async Domain.<anonymous> (/app-rprt/node_modules/@jsreport/advanced-workers/lib/workerHandler.js:141:19)
    caused by: Error: end of central directory record signature not found
    at /app-rprt/node_modules/yauzl/index.js:187:14
    at Immediate.<anonymous> (/app-rprt/node_modules/yauzl/index.js:624:38)
    at processImmediate (node:internal/timers:464:21)
    at process.topLevelDomainCallback (node:domain:152:15)
    at process.callbackTrampoline (node:internal/async_hooks:128:24)

    Any assistance in being able to pass a full template content over and have it unoconv to pdf would be much appreciated. It seems that if it doesn't have a ShortId to work with, it fails.



  • Could you try to add the encoding as well?

    TemplateAsset = new Asset()
    		{
    			Content = {MyBase64String},
                            Encoding = "base64"                        
    		}
    


  • I will give that a try again today. I tried it last time and i got an error about a Set not being allowed on a read only or something like that. I will get you the exact error message though.



  • I don't know i did wrong the other day, but adding Encoding to it worked!

    Thanks...we can now use JSReports for document conversion of Docx to PDF!!


Log in to reply
 

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