Save DOCX template back to DOCX

Product: Webviewer SDK

Product Version: 10.2.3

Please give a brief summary of your issue: Can’t save merged DOCX template values back to DOCX

Please describe your issue and provide steps to reproduce it:

I’ve followed the guides and the several posts in this community asking to be able to merge DOCX template values and save this file back to DOCX format.

This doesn’t look like it’s possible or supported at all? This is very frustrating given that getFileData accepted a downloadType attribute as either pdf or office. It makes no sense to me why switching to office would suddenly get a non-annotated file.

Similarly, it doesn’t look like the Office Editing module supports editing a document created from template values.

Please provide a link to a minimal sample where the issue is reproducible:

Any of the demos

1 Like

Thank you for posting the incident to our forum. We will provide you with an update as soon as possible.

1 Like

Hi Zack,

Thank you for contacting us regarding Webviewer.

Could you elaborate more about “merging DOCX” template values? It would be helpful for us to investigate the issue, thank you.

1 Like

Hi Zack,

Please find the following code will help get a docx file back after performing docx templating.

        const doc = documentViewer.getDocument();
        const data = await doc.getFileData({
          downloadType: 'templateFilledOffice',
          officeOptions: {
            doTemplatePrep: true
          }
        });
        const arr = new Uint8Array(data);
        const blob = new Blob([arr], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' });
        saveAs(blob, 'template-filled.docx');
1 Like

This is great news, I’ll try this out soon.

Do I need to be on a specific version of the WebViewer?

1 Like

It was added as of 10.7 but some bugs were fixed since then and so the latest version 10.8 will have the best version of this feature

1 Like

hey,
i’ve also been looking for such implementation.
in which part of that code do i pass the data for the document placeholders?

could you give us an extended code fragment, how to implement this?

thanks in advance
Peter

1 Like

Hello pezi,

Check out this guide on templating for more info: Generate-docx-template | Apryse Documentation

Best regards,
Tyler

1 Like

Thanks for your reply. I get this to work, but i dont want to have a PDF filled with the JSON data, rather i want to be able to edit the docx, which is filled with JSON Data.

The only way i get it to work is, that i load the docx with all placeholders, have inputs for each placeholder and per button, the docx gets filled with the data, but output is still a PDF. If i use the ‘enableOfficeEditing: true’ flag, then it keeps the unfilled docx with placeholders.

Maybe i should fill the docx with the data and convert the data back to docx and then open the new file. but I don’t know how to do this. Also I dont know, if it would keep all formations of the lines. It would be much easier to put the JSON data directly into the docx. But it looks like that is not possible?

1 Like