Using the pdf Viewer with an asmx web service instead of an API controller

im trying to figure out how to implement the pdf viewer using an asmx web service instead of an API controller but i cannot seem to get it to work. is it even possible to use something other than an API controller with the pdf viewer control?


9 Replies

VS Vasugi Sivajothi Syncfusion Team August 2, 2021 11:56 AM UTC

Hi Andrew, 
 
Thank you for contacting Syncfusion support. 
 
We will check the feasibility of PDF Viewer with an ASMX web service and provide further details on August 4, 2021. 
 
Regards, 
Vasugi. 



VS Vasugi Sivajothi Syncfusion Team August 5, 2021 07:21 AM UTC

Hi Andrew,  

Thank you for your patience. 

We tried creating the web service in ASMX but the PDF Viewer is not working in it. Could you please share the exact use case scenario to prefer ASMX instead of an API controller? This will be helpful to investigate further and provide the solution at the earliest.  

However, we have shared the documentation for the web service by using the API controller. Please refer to the below documentation.  

Web service: 
Core: 





Regards, 
Vasugi. 



AN Andrew replied to Vasugi Sivajothi August 5, 2021 05:26 PM UTC

we use asmx for web services. I've also tried using an api controller in a test solution but i cannot get that to work either. I followed the documentation "how to" page but it doesn't work. also the example that you can download at the bottom of this page (https://ej2.syncfusion.com/javascript/documentation/pdfviewer/how-to/create-pdfviewer-service/) doesn't work. it doesn't have any csproj files. Is there an example project that has the projects files included?



AN Andrew August 5, 2021 07:21 PM UTC

Update: I'm trying to get the pdf viewer control to work with an api controller. I was having issues getting it to work but it turns out I was using the wrong url to the api. But now I'm getting an error in the page that says " Web-service is not listening. PDF Viewer depends on web-service for all it's features. Please start the web service to continue." also, i need to be able to load a different pdf from a different location. not sure how to do that. i could share the example solution i created to test the control if that would make it easier to figure out how to get it working.


thanks.



VS Vasugi Sivajothi Syncfusion Team August 6, 2021 10:12 AM UTC

Hi Andrew, 

We suspect that the reported issue “web service is not listening” due to web service is not referred to properly in your application. Kindly upgrade the same version for both client and server.  
 
You can load the document using the open icon in the default toolbar or programmatically using the load API. We have shared the sample for your reference, please refer to the below code snippet and sample. However, we will update the sample in the documentation and let you know once it is refreshed. Sorry for the inconvenience. 

Code Snippet to load document from server location: 

viewer.load('PDF_Succinctly.pdf', null); 

Note: We need to place the PDF documents in the server location 

Code Snippet to load document as base64 stirng: 

Viewer.load(“data:application/pdf;base64,…..”,null); 


PDF viewer control processes the PDF document on the server-side and sends the processed PDF data to the client using the web service to render the PDF document and for further operations in PDF viewer. So, run the web service and provide that URL in the client-side application for futher processing. 


Kindly try this and let us know if the issue resolves or not. If not, please share the version, console error details, and network tab details while loading the document. This will be helpful to investigate further and provide the solution at the earliest. 

Regards, 
Vasugi. 



AN Andrew August 6, 2021 04:18 PM UTC

I don't think those solutions will work as I am using Javascript​ not Typescript. I think I may have finally gotten it working by changing the routeTemplate in the webApiConfig file. also, with the custom toolbar is there a prefix icon (ex: e-pv-open-document for the open button) for a save button? I want to be able to load the pdf from another location when loading the viewer and save it from the viewer.



VS Vasugi Sivajothi Syncfusion Team August 9, 2021 12:08 PM UTC

Hi Andrew, 
 
Please find the details. 
 
Query 
Details 
I don't think those solutions will work as I am using Javascript​ not Typescript. I think I may have finally gotten it working by changing the routeTemplate in the webApiConfig file.  
 
Thank you for the update. We have shared the javascript sample for your reference. Please refer to the below link. 
 
 
 
 
also, with the custom toolbar is there a prefix icon (ex: e-pv-open-document for the open button) for a save button? I want to be able to load the pdf from another location when loading the viewer and save it from the viewer. 
 
 
You can add the icon to the custom toolbar using below code snippet. 
 
Code Snippet: 
 
 
.e-pv-save-document::before { 
      content: '\e735'; 
      font-family: 'e-icons'; 
    } 
 
 
You can load the document from various locations using the open icon in the toolbar and you can download the document using a download icon in the toolbar. Please refer to the below sample. 
 
We have shared the code Snippet and sample to save the PDF document in the server location. Please refer to the below code snippet and sample. 
 
Code Snippet for client-side: 
 
 
viewer.serverActionSettings.download = 'SaveDocument'; 
  viewer.download(); 
  viewer.serverActionSettings.download = 'Download'; 
 
 
Code Snippet for server-side: 
 
 
public object SaveDocument(Dictionary<string, string> jsonObject) 
        { 
            PdfRenderer pdfviewer = new PdfRenderer(); 
            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 = HttpContext.Current.Request.PhysicalApplicationPath; 
                System.IO.File.WriteAllBytes(path + "/Files/Output.pdf", byteArray); 
            } 
            return GetPlainText(string.Empty); 
        } 
 
 
 
 
 

 
Documentation: 
 
 
 
 
 
Kindly try this and let us know if you have any concerns about this. 
 
Regards, 
Vasugi. 




AN Andrew August 9, 2021 07:09 PM UTC

ok. I was able to get things working however there is still a JavaScript error I am getting in the ej2-pdfviewer.min.js file and I don't know why. its not causing anything to break but its still odd that there's an error. undefined property error.PNG 



VS Vasugi Sivajothi Syncfusion Team August 10, 2021 10:00 AM UTC

Hi Andrew, 

We have tried to reproduce the reported issue with the provided details in the sample, which is provided in our previous update, but we were unable to reproduce it. 
 
  
 
Could you please let us know that in which scenario you have reproduced the issue? Please revert to us with a modified sample to replicate the issue on our end if you have any concerns about this. This will be helpful to investigate further and provide the solution at the earliest. 
 
Regards, 
Vasugi. 


Loader.
Up arrow icon