Docx file preview with JSreport and Docxtemplater



  • Hi! I'm trying to implement functionality to upload docx file template, fill that file with data and render its preview on the front end but constantly getting errors. Using Vue 3 and Express.

    This is what i'm sending from the front end . Basically making base64 string from the docx file before sending.

    			template = {
    				...template,
    				docxtemplater: {
    					templateAsset: {
    						content: await fileToBase64(docxTemplate),
    						encoding: 'base64'
    					}
    				}
    			}
    

    And this is what i'm doing with file in the back end

                 const { content, meta: { contentType, fileExtension }  } = await jsr.render(req.body)
    

    On this part i'm getting the following error: Error: Can't find end of central directory : is this a zip file ?.

    Whats going on? Is there any live example when i can see how is this should be implemented? The existing demos don't give any clue how to achieve such results. Thanks!


  • administrators

    hi! do you have some logs to share? perhaps there is a stack trace there so it points to the exact line of code it fails.

    it is likely failing to recognize your docx file template as a valid docx (which is basically a zip file with a .docx extension).

    what is exactly docxTemplate here? how do you get it? where does it come from? what is the implementation of fileToBase64, it seems the error is here, that the docx is not being serialized properly


Log in to reply
 

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