Saving Annotated Documents

Discussions about DocuVieware integration in GdPicture.NET.
Post Reply
wedmondson
Posts: 10
Joined: Tue Aug 04, 2020 12:04 am

Saving Annotated Documents

Post by wedmondson » Thu Sep 10, 2020 3:47 am

I am not sure the best way to get access to the document's byte array after annotations have been saved. I feel like I am missing a core concept.

(for context I need the documents byte stream in order to save it to blob storage but I also need it done in a context where I can get access to other relevant data like database ids)

I am using the sample MVC sample project.

I could either do the work client side in the browser or using c# in the controller.

Client Side
The problem with the client side is the JavaScript library does not give access to the saved file's byte array. The Save method in 'docuvieware-min.js' called by the DocuViewareControl generated UI simply takes the FileResult from the MVC controller's save action and set's it to 'window.location'. I could override this but since it is an internal method it stands the chance of being overwritten with future Docuvieware software updates. My expectation would be that the 'onDocumentSaved' event would provide a data object with the updated file details in it but it does not.

Code: Select all

//I wish I had access to the file object as part of the response
window.location = a.appControllerPath + "/save" + (a.useIdInRoot ? "/1" : "") + "?sessionID=" + this.ajax.sessionID + "&fileName=" + encodeURIComponent(b) + "&format=" + d + "&pageRange=" + (e ? e : "*");
...
if (a.callbacks.onDocumentSaved)
    a.callbacks.onDocumentSaved(); //I would expect onDocumentSaved passes back the result of the save action
 
Server Side
The problem with server side is I have no context about any of the document's meta data. In particular, what database record it is related to. When a document is annotated and saved I need to verify access rights, update a database record, then save the document to storage. I do not see a way of passing additional data with the save command so that I could do this operations from within the action. If I could pass the database id along with the save request I would have everything I needed to complete the operation.

Code: Select all

//I do not see a way of passing in or accessing any data other than what is directly supplied by the Docuvieware libraries
 public IActionResult Save(string sessionID, string fileName, string format, string pageRange)
        {
            DocuViewareControllerActionsHandler.save(sessionID, ref fileName, format, pageRange, false, out HttpStatusCode statusCode, out string reasonPhrase, out byte[] content, out string contentType);

wedmondson
Posts: 10
Joined: Tue Aug 04, 2020 12:04 am

Re: Saving Annotated Documents

Post by wedmondson » Wed Sep 16, 2020 3:46 pm

I have found two possible solutions. I do not know if there is a better one.

Override Save Click
In this option I intercept the JavaScript click event on the save button and provide my own logic

Code: Select all

document.getElementById('docuViewerControl').control.SaveDialog_Click = function() {
                console.log('save clicked');
                //Do custom save work here
            }
Create My Own Save Button
Create my own save button that reads the session ID from AJAX context and builds a POST request to the imaging controller to a custom action that accepts additional parameters. Currently, I would have to put this save button outside of the DocuVieware control as an independent button. is there a way to add a custom button to the DocuVieware header button row?

User avatar
Fabio
Posts: 29
Joined: Thu Aug 27, 2020 9:57 am

Re: Saving Annotated Documents

Post by Fabio » Mon Sep 21, 2020 7:16 pm

Hello,

The best solution is to develop a custom button, the other will work but it not follows the best practices.

If you wanna add a button on the top bar, you can use this method: https://www.docuvieware.com/guides/aspn ... utton.html

You can also set it like this:

Code: Select all

var control = new System.Web.UI.HtmlControls.HtmlGenericControl("svg");
control.Attributes["width"] = "100%";
control.Attributes["height"] = "100%";
control.Attributes["viewBox"] = "0 0 16 16";
control.InnerHtml = "<path d='M16 6.204l-5.528-0.803-2.472-5.009-2.472 5.009-5.528 0.803 4 3.899-0.944 5.505 4.944-2.599 4.944 2.599-0.944-5.505 4-3.899z'></path>";
docuVieware.AddCustomToolbarButton("Test", "test", control, "console.log('hello world')");
docuVieware.RenderControl(Output);
Hope it helps.

Fabio de Rose
Solution Engineer

wedmondson
Posts: 10
Joined: Tue Aug 04, 2020 12:04 am

Re: Saving Annotated Documents

Post by wedmondson » Tue Sep 22, 2020 8:43 pm

This is perfect. Thanks Fabio.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest