Hi there,
is there a possibility to add a save Button to the viewer to send the changed document back to the server?
Preferably I'd like to get the changes as they happen (adding / changing an annotation for example) to be sent back to the server instead of the whole document. This would prevent a condition where the last one that saves the documents gets all his changes into the document on the server side.
I'm using Angular on the frontend and a ASP.NET Core ApiController on the backend.
kind regards
Menico
|
public ActionResult SaveDocument([FromBody] Dictionary<string, string> jsonObject)
{
PdfRenderer pdfviewer = new PdfRenderer(_cache);
string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
string base64String = documentBase.Split(new string[] { "data:application/pdf;base64," }, StringSplitOptions.None)[1];
if (base64String != null || base64String != string.Empty)
{
byte[] byteArray = Convert.FromBase64String(base64String);
MemoryStream ms = new MemoryStream(byteArray);
var path = _hostingEnvironment.ContentRootPath;
System.IO.File.WriteAllBytes(path + "/ouptut.pdf", byteArray);
}
return Content(string.Empty);
}
|
Thanks for the answer. I'm currently testing it.
Is there a way to:
Got the first one.
But do I really have to create a custom toolbar with all the elements just to add one simple custom button?
Additionally the SaveDocument does not trigger the ajaxRequestSuccess / ajaxRequestFailure.
|
Query |
Details | |
|
Is there a way to:
Get rid of the openFile button.
Put the "saveDocument" button there instead.
Enable the saveDocument button only if there are pending changes to the document.
But do I really have to create a custom toolbar with all the elements just to add one simple custom button?
|
There is no direct support to add the items in the toolbar. However, you can add the items to the existing toolbar as a workaround using the created event after loading the PDF Viewer component. And using the toolbarItems property in the toolbarSettings property, you can hide the Open Icon present in the toolbar. We have shared the sample for your reference.
UG documentation: https://ej2.syncfusion.com/angular/documentation/pdfviewer/toolbar/
Code snippet to hide the open icon in the toolbar:
Kindly try this and let us know if you have any concerns about this.
| |
|
Additionally the SaveDocument does not trigger the ajaxRequestSuccess / ajaxRequestFailure.
|
PDF Viewer triggers the ajaxRequestSuccess or ajaxRequestFailure events for all the server action methods. Since an empty string is returned in the saveDocument() method the ajaxRequestSuccess event is not triggered. However, we can use the downloadEnd event to get the success message once the document is saved successfully.
Note: If we return the base64 string from the saveDocument method then the ajaxRequestSuccess event will be triggered, and the PDF document will be downloaded.
Code snippet for downloadEnd event:
Please revert to us, if you need further assistance.
|