Save completed PDF with signature back to server using PdfViewer control?

Using ASP.NET Core and the Javascript PdfViewer control with Handwritten signature, is it possible to send the signed PDF back to the server so that it can be saved on the server? Can I get the filled form data and send it to a custom endpoint?

The documentation and samples only appear to show downloading PDF to the client or exporting form data back to the client using predefined endpoints.

1 Reply 1 reply marked as answer

VS Vasugi Sivajothi Syncfusion Team May 31, 2021 11:14 AM UTC

Hi webwizgordon, 
 
Thank you for contacting Syncfusion support. 
 
 
We can save the PDF document with Handwritten signature and form field data in the server side by using SaveDocument method and we can access the web action method in the client side by using the ServerActionSettings API.  
 
Please refer to the below sample and code snippet. 
 
Code Snippet for client side: 
 
<button onclick="save()">SaveDocument</button> 
 
function save() { 
        var pdfViewer = document.getElementById('pdfviewer1').ej2_instances[0]; 
        pdfViewer.serverActionSettings.download = "SaveDocument"; 
        pdfViewer.download(); 
        pdfViewer.serverActionSettings.download = "Download"; 
    } 
 
 
Code Snippet for server side: 
 
 
[AcceptVerbs("Post")] 
        [HttpPost] 
        [Route("api/[controller]/SaveDocument")] 
        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); 
        } 
 
 
 
Note: In the provided sample, we have a button (SaveDocument). On button-click, the newly created method (SaveDocument) in the PDFViewerController.cs file is invoked, and then the document is saved to the project location. 
 
 
Kindly try this and let us know if you have any concerns about this. 
 
Regards, 
Vasugi. 


Marked as answer
Loader.
Up arrow icon