Webviewer docx - save document

Hi
I using WebViewer 10.3.0 to edit docx files. I load document docx from my own serwer. After edit docx i want to save changed document to loaded document on the serwer ( not a local computer). This mean i use :

initialDoc: ‘ocx/tmp/test.docx’

and a want save changest to ocx/tmp/test.docx .

How can i do this?

My code below :

var $j = jQuery.noConflict();
$j(document).ready(function () {
var obj = document.getElementById(‘viewer’);
WebViewer({
path: ‘WebViewer/lib’,

              initialDoc: 'ocx/tmp/test.docx', // You can also use documents on your server
             enableOfficeEditing: true,
          }, document.getElementById('viewer'))
          .then(instance => {
            const { documentViewer, annotationManager } = instance.Core;

             const Tools = instance.Core.Tools;
             const Annotations = instance.Core.Annotations;
              
              documentViewer.addEventListener('documentLoaded', () => {
                  
            });
          });
    });
1 Like

I find another solusion. Add custom button and write code to get edited docx file and convert it to base64 string. In this way i can send this file to server-side.

How get edited docx file. My code bellow :slight_smile:

}, document.getElementById(‘viewer’))
.then(instance => {

              const {UI, documentViewer, annotationManager } = instance.Core;

// my button
instance.UI.setHeaderItems(header => {
header.push({
type: ‘actionButton’,
img: ‘’,
onClick: () => {
// code to get edited docx file
}
});
});

              documentViewer.addEventListener('documentLoaded', () => {
                
            });
1 Like

Hi,

You can try the following code to download the file as a docx file:

instance.UI.downloadPdf({ downloadType: 'office' });

This is the guide for the related API:
https://docs.apryse.com/api/web/UI.html#.downloadPdf

Wanbo

1 Like

Hi Wanbo_Li

Thanks for replay.
Your idea is good way. But in additionaly i need get content of file in javascript. I need a way or function in what i get doxc file in bytes for example :

val fileInArrayBytesAfterChanges = instance.UI.anyfunction()

or directly in javascript. This means reading the contents of the downloaded to local storage docx file, but I think this is impossible due to security policy

1 Like

Hi,

Could you try using the following code?

const fileContent = await instance.UI.getDocumentViewer().getDocument().getFileData({downloadType: 'pdf'});

Thanks.

Wanbo

1 Like

i want to sent blob file in my api for save after changes so how can i achive this
my current code is
onClick: async () => {
// save the annotations
const xfdfString = await annotationManager.exportAnnotations({
widgets: false,
links: false,
//fields: false
});
console.log(“xfdfStringxfdf String”, xfdfString);
const doc = documentViewer.getDocument();
const data = await doc.getFileData({
// saves the document with annotations in it
xfdfString,
});
const arr = new Uint8Array(data);
const blob = new Blob([arr], { type: “text/plain” });
iwant blob as plain text to give it in my api request data

1 Like

You can either send the XFDF string or just the blob to your API.

Wanbo

1 Like