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

PDF Viewer is not working

Hi,

PDF Viewer is not correctly working. It result on a modal with error message. What's wrong?





14 Replies

KK Karthik Krishnaraj Syncfusion Team January 18, 2019 02:27 PM UTC

Hi Maico, 
 
Greetings from Syncfusion, 
 
We have analyzed the provided query “PDF Viewer is not correctly working” and we suspect that the issue is due to incorrect mapping of Serviceurl in your project. We need to add the controller name at the end of the localhost for accessing the data from the client to the server. Please find the below example. 
 
 
WebAPI Controller: 
 
@Html.EJS().PdfViewer("pdfviewer").ServiceUrl(“http://localhost /api/PdfViewer/”)  
 
In “api/pdfViewer” where pdfviewer refers to the name of the webAPIController (api/webAPIControllername) 
 
(or) 
 
MVC Controller: 
@Html.EJS().PdfViewer("pdfviewer").ServiceUrl(“http://localhost /PdfViewer/”)  
 
In “/pdfViewer” where pdfviewer refers to the name of the MVCController (MVCcontrollername) 
 
 
//where localhost=http://192.168.0162:81 according to the provided snippet 
 
Note: Please use the webAPIControllername/ MVCcontrollername name as per you have provided in your hosted webservice. 
 
 
 
 
We have created the simple MVC sample, please download the sample from the below link. 
 
 
 
In the provided sample we have  both MVC controller and webAPI PDF Viewer controller for accessing the data form the client to the server, so you can refer any one of them in the serviceurl ,Kindly refer the below code snippet. 
 
WebAPI Controller: 
 
        @Html.EJS().PdfViewer("pdfviewer").ServiceUrl(VirtualPathUtility.ToAbsolute("~/api/PdfViewer/")).DocumentPath("PDF_Succinctly.pdf").Render() 
 
 
 
 
MVC Controller: 
 
        @Html.EJS().PdfViewer("pdfviewer").ServiceUrl(VirtualPathUtility.ToAbsolute("~/PdfViewer/")).DocumentPath("PDF_Succinctly.pdf").Render() 
 
 
 
Regards, 
Karthik. 



BV Bharat Vasant August 1, 2020 10:50 AM UTC

I have similar issue. 
I have 2 Areas. 1. API (rest api provided by may .NET core application) and 2. Console (web application with razor pages).

I have added PDF viewer as below...

It's giving the same error.  ejs2 ASP .NET Core documentation https://ej2.syncfusion.com/aspnetcore/documentation/pdfviewer/getting-started/ talks nothing about serviceURL and actions that must be present in the controller...

Also, there is not API reference in above documentation.


AA Akshaya Arivoli Syncfusion Team August 3, 2020 12:38 PM UTC

Hi Bharat  

Thank you for contacting Syncfusion support. 

We have created simple PDF Viewer sample in ASP.NET Core and shared the same in the below link, 


our PDF Viewer control is both server and the client side oriented. PDF viewer control processes the PDF document in the server side(developed with .NET environment) and send the processed PDF data to the client using the Web service to render the PDF document and for further operations in PDF viewer. So we need to map the controller using the serviceUrl property of the PDF Viewer. 

We can also use our PDF Viewer in Razor pages, please refer to the below link for more details, 




Please try it and revert us with more details about your requirement and sample, if you need any further assistance. These details will be helpful for us to investigate further and assist you better.  


Regards, 
Akshaya  



BV Bharat Vasant August 3, 2020 12:42 PM UTC

1. On investigating further, I found that, one of my middleware has

await _antiforgery.ValidateRequestAsync(context);

The call to PdfViewer action 'Load' causes exception at the above line.  Thus, I want to know how to pass antiforgery token along with PefViewer actions.

2. Also, I have downloaded .NET 4.6.1 sample and it's posting proper object in jsonObject

          public ActionResult Load(jsonObjects jsonObject)

but in ASP.NET Core 3.1, its able to reach controller after commenting antiforgery token check, but jsonObject is null 

            public IActionResult Load([FromBody] Dictionary<string, string> jsonObject)          <== jsonObject is null.
  


AA Akshaya Arivoli Syncfusion Team August 4, 2020 11:47 AM UTC

Hi Bharat , 

Thank you for your update. 

Query 
Details  
On investigating further, I found that, one of my middleware has 

await _antiforgery.ValidateRequestAsync(context); 

The call to PdfViewer action 'Load' causes exception at the above line.  Thus, I want to know how to pass antiforgery token along with PefViewer actions. 

We can include the Authorization token in the PDF Viewer AJAX request using the ajaxRequest headers properties available in AjaxRequestSettings and it will be included in every AJAX request send from PDF Viewer. 
Also, I have downloaded .NET 4.6.1 sample and it's posting proper object in jsonObject 

          public ActionResult Load(jsonObjects jsonObject) 

but in ASP.NET Core 3.1, its able to reach controller after commenting antiforgery token check, but jsonObject is null  

            public IActionResult Load([FromBody] Dictionary<string, string> jsonObject)          <== jsonObject is null. 
   

Based on the provided details we suspect that NewtsonSoft.Json is not configured properly so the errors occurs.So kindly configure it in your .core 3.1 project as below. 
Prior to ASP.NET Core 3.0, the default JSON formatters implemented using the Newtonsoft.Json package. In ASP.NET Core 3.0 or later, the default JSON formatters are based on System.Text.Json. Support for Newtonsoft.Json based formatters and features is available by installing the Microsoft.AspNetCore.Mvc.NewtonsoftJson NuGet package and configuring it in Startup.ConfigureServices. 
 
public void ConfigureServices(IServiceCollection services) 
        { 
            services.AddControllersWithViews(); 
            services.AddMemoryCache(); 
            services.AddControllers().AddNewtonsoftJson(options => 
            { 
                // Use the default property (Pascal) casing 
                options.SerializerSettings.ContractResolver = new DefaultContractResolver(); 
            }); 
        } 
 
  1. Kindly provide the CDN links with version
  2. Update the PdfViewerController code as provided in the previous sample
Please try it and if you are still facing the issue , revert us with the modified sample in which the issue could be reproduced. Also confirm us whether you are using the PDF Viewer in ASP.Net Core MVC or Razor pages.  
 



Regards, 
Akshaya 




LO Lorne January 9, 2021 07:13 PM UTC

I have also created an ASP.Net Core Razor Pages application, as per instructions here and the PDFViewer control works beautifully.  However, because of another dependency  in my program, I have to use the System.Text.Json package instead of the NewtonSoftJson package.  After I change my startup.cs file from this

services.AddControllers().AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.Converters.Add(new StringEnumConverter());
            }); 

to this:

services.AddControllersWithViews()
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());

            });

I get the following error.

The load post handler returns the following: "JsonObject is null"

So my question is whether it is possible to use this control  with the System.Text.Json package rather than the Newtonsoft package?

Here is a linkto my project.



AA Akshaya Arivoli Syncfusion Team January 11, 2021 12:22 PM UTC

Hi Lorne, 

Thank you for your update. We were able to reproduce the reported behavior with the provided details, we will analyze further on this and update you with more details on January 13, 2021 

Regards, 
Akshaya  



MS Mohan Selvaraj Syncfusion Team January 13, 2021 02:02 PM UTC

Hi Lorne, 
We are currently checking on this with high priority , We will update the further details on January 18th 2020.  
Regards, 
Mohan S 




LO Lorne January 13, 2021 09:06 PM UTC

Thanks for the update, I'll be waiting to hear back from you.


MS Mohan Selvaraj Syncfusion Team January 14, 2021 04:29 AM UTC

Hi Lorne,  

Thanks for your update. 

As we mentioned in our previous update, We will update the further details on January 18th 2020.   

Regards,  
Mohan S  



VS Vasugi Sivajothi Syncfusion Team January 18, 2021 04:40 PM UTC

Hi Lorne, 
 
  
We need to construct the request parameter data items with in the class by providing the exact return type. So that the request data will be returned correctly in the cshml.cs page, We have also created the simple sample for the same, kindly download it from the below link. 
  
  
  
public IActionResult OnPostLoad([FromBody] jsonObjects responseData) 
        { 
PdfRenderer pdfviewer = new PdfRenderer(_cache); 
            MemoryStream stream = new MemoryStream(); 
            var jsonObject = JsonConverterstring(responseData);  // converted the class to type to Dictionary<string,string> type 
  
                  …………… 
} 
  public class jsonObjects 
    { 
  
        public string document { get; set; } 
        public string password { get; set; } 
        public int zoomFactor { get; set; } 
        public bool isFileName { get; set; } 
              ……… 
   } 
 
  
 
 
Note: Kindly refer the PDFViewer.cshtml.cs file in the sample. 
  
 
Regards, 
Vasugi 



MJ Marvin Jay April 13, 2022 08:55 AM UTC

Hi there,


I'm having the same issue. Problem with loading pdf, also showing Web-service is not listening.


Please see attached pdf files. These pdfs do not show also on your demo.

Here in google drive: https://drive.google.com/drive/folders/1PYjTe6QfvhJStdBemrkuySMlghhf7V5F?usp=sharing


Regards,

Marvin


Attachment: PDFs_7f5d6c2c.zip



VS Vasugi Sivajothi Syncfusion Team April 13, 2022 01:45 PM UTC

Hi Marvin,


We were able to reproduce the reported issue with the provided document. We will analyze further on this and update you with more details on April 19, 2022.


Regards,

Vasugi.



VS Vasugi Sivajothi Syncfusion Team April 19, 2022 03:50 PM UTC

Hi Marvin,


We can resolve the reported issue by providing the maxAllowedContentLength and request length on the web. config file. And need to increase the maximum length for serializing the large-sized JSON object. So, we have created a class LargeJsonValueProviderFactory and modified the code to increase the length for serialization
in the file Global.asax.cs. Kindly refer to the below code snippet and sample.


Code Snippet:

 

<httpRuntime targetFramework="4.7.2" maxRequestLength="2147483647" executionTimeout="1600" requestLengthDiskThreshold="2147483647" />

 

<requestLimits maxAllowedContentLength="2147483647" />

 


Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/GettingStarted_MVC2051814703


Kindly try this and let us know if this helps you.


Regards,

Vasugi


Loader.
Live Chat Icon For mobile
Up arrow icon