We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Submit pdfviewer button on razor page via javascript

Is there an example of submitting the content of the pdfviewer via javascript from a link on a razor page?  I am having trouble submitting an ajax request where the "[FromBody] Dictionary<string, string> jsonObject" parameter isn't null, which I'm sure is because I'm not passing it properly, but I can't seem to find any examples on how to do that.

To provide a bit more detail, if you use the following in javascript:
     var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0];
     pdfViewer.download();

It will call this method in the razor page code and populate the jsonObject properly:
     public IActionResult OnPostDownload([FromBody] Dictionary<string, string> jsonObject) {
            PdfRenderer pdfviewer = new PdfRenderer(_cache);
            string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject);
            return Content(documentBase);
     }

What I would like to do is post the pdfviewer data to a new method that does something else:
     public IActionResult OnPostSomethineElse([FromBody] Dictionary<string, string> jsonObject) {
          //-- Do something else
     }

Any help would be greatly appreciated!

6 Replies

AA Akshaya Arivoli Syncfusion Team December 13, 2019 09:25 AM UTC

Hi Megan, 

Thank you for contacting Syncfusion support. 

We can achieve your requirement using serverActionSettings API available in PDF Viewer, using that you can call your own custom action method. We have created sample for the same and shared in the following location,   


In the above sample, clicking on Download button will call the OnPostSomethineElse() with jsonObject, where you can perform your operations. Clicking on Download icon in the default toolbar will download the PDF document in client. We can also disable the download icon using EnableDownload API available in PDF Viewer  

Please try this and revert us with the more details about your requirement and use case scenario if you have any concerns on this. These details will be helpful for us to investigate further and assist you better. 

Regards, 
Akshaya 



MC MCDC December 13, 2019 05:02 PM UTC

That is almost exactly what I am looking for, thank you!  I am able to process the file the way I want by resetting the download action, but I want to then reload the document since I have made some changes to it.  If I try something like the following, it loads the file before the SomethingElse action finishes.
$(document).on("click", "#btn", function () {
        var documentPath = $("#DocumentPath").val();
        var pdfViewer = document.getElementById('pdfviewer').ej2_instances[0];
        pdfViewer.serverActionSettings.download = "SomethingElse";
        pdfViewer.download();
        pdfViewer.serverActionSettings.download = "Download";
        pdfViewer.load(documentPath);
    });

How would I reload the document after the download/SomethingElse action is complete?



AA Akshaya Arivoli Syncfusion Team December 16, 2019 10:23 AM UTC

Hi Megan, 
 
Thank you for your update. 
  
We can achieve your requirement by saving the modified document in the server side in Download/SomethingElse action method. Then we can load the same using the load() API available in the PDF Viewer. Since the Download and Load action methods are asynchronous, so Load() method will called before the Download() action completes, so the PDF document will not be available sometimes in the mentioned path location. We have provided time delay to load the PDF document using load() API after download action. We have created sample for the same and shared in the below location, 
  
  
We can also load the PDF document in the downloadEnd event too. But we are facing issues in triggering the DownloadEnd event when the PDF document is saved in the server instead of download from the client. We will analyze further on it and update you with more details on December 18th, 2019. 
  
Please try this and revert us with more details if you have any concerns on this. 
  
Regards, 
Akshaya 



AA Akshaya Arivoli Syncfusion Team December 18, 2019 08:44 AM UTC

Hi Megan, 

We have validated the issue “downloadEnd event is not triggered when PDF document is saved in sever” and logged the defect reported for the same. The fix for the issue will be included in our upcoming weekly NuGet release on January 8th, 2010. You can track the status of the bug using the below feedback link, 


Regards, 
Akshaya 



MC MCDC December 19, 2019 03:49 PM UTC

Thank you


MS Mohan Selvaraj Syncfusion Team January 17, 2020 09:44 AM UTC

Hi Megan, 

We have resolved the reported issue and it is included in our latest weekly NuGet release. Kindly upgrade to that version to resolve the issue.  
   



Regards, 
Mohan S 


Loader.
Live Chat Icon For mobile
Up arrow icon