Atalasoft / web-document-viewer-demo

Atalasoft DotImage Web Document Viewer demo application
http://atalasoft-viewer-demo.azurewebsites.net/
10 stars 15 forks source link

Saving Image Changes Corrupts File #15

Open aramka opened 7 years ago

aramka commented 7 years ago

I initialize my viewer like this

// Initialize Web Viewing
        var viewer = new Atalasoft.Controls.WebDocumentViewer({
            parent: $('.atala-document-container'),
            toolbarparent: $('.atala-document-toolbar'),
            serverurl: this.documentViewerDocumentHandlerUrl,
            savepath: this.documentViewerChangedImageSavePath,
            allowannotations: true
        });

        // Initialize Thumbnail Viewer
        var thumbs = new Atalasoft.Controls.WebDocumentThumbnailer({
            parent: $('.atala-document-thumbnailer'),
            serverurl: this.documentViewerDocumentHandlerUrl,
            viewer: viewer
        });

        thumbs.bind('error', function (event) {
            console.log('error');
            console.log(event.name);
            console.log(event.message);
        });

        thumbs.bind('documentloaded', function (event) {
            console.log('documentloaded');
            console.log(event);
        });

        viewer.bind('annotationcreated', (event) => { this.annotationCreated(event); });
        viewer.bind('annotationdeleted ', (page, index) => { this.annotationDeleted(page, index); });

the savepath is initially set to '~\'

Then, at a later time, I open a document like this

viewer.config.savepath = '~/Save';
thumbs.openUrl('~/Save/Invoice.pdf');

Im trying to save to the same file that was loaded. The document and thumbnails load successfully. Also, the save button is shown on the toolbar. However, when I add any annotation and click save the file on the server is corrupted, contains zero bytes.

I expect the file to be written and the annotation xmp file to also be written.

How can I save back to the same file that was loaded?

aramka commented 7 years ago

I was able to get an error in the console by setting the showerrors on the viewer config to true.

ERROR DocumentSaveError: The process cannot access the file 'C:\Users\andrewr\Development\AtalasoftWebDocumentViewer\AtalasoftWebDocumentViewer\Save\Invoice.pdf' because it is being used by another process.

I believe the server WebDocumentRequestHandler is holding a lock on the file and therefore changes cannot be saved.

Is saving changes to the same that was loaded supported?

gennady-ermakov commented 7 years ago

Hi @aramka, Nope, it's not supported - original document is not loaded into memory on the server during viewing or saving, it's accessed on demand. So to read it before saving it should be in place. Saving to the default folder on the server is most basic scenario. You could subscribe to the server DocumentSave event and provide the stream(s) to write output into or override the output file location on the server. Or just keep up with basic scenario, but save to the different folder or with different name.

aramka commented 7 years ago

If I provide the streams on the server to point to the original file then I still get the error because the server has a lock on the file.

The default scenario does not work. I do not want multiple versions of a file on the server. I need all changes to be saved to the same file.

Why does the server have a lock on the file? Is there any way to release the lock on the file?

gennady-ermakov commented 7 years ago

@aramka it locks the original file because it's reading the content of it during save. otherwise it could blow memory. consider if you have 2GB tiff for 1000 pages. to override it control would have to load it in memory or backup somewhere before save. Do you modifying the file in your solution? maybe you don't need to save the file itself and only want to save the annotations?

aramka commented 7 years ago

I need saving of the file and the annotations. The user makes changes to annotations and rotates the document. I need to save changes to both annotations and document.