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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

PDF Viewer is not working

Thread ID:

Created:

Updated:

Platform:

Replies:

142077 Jan 17,2019 01:19 PM UTC Jan 18,2021 04:40 PM UTC ASP.NET MVC - EJ 2 11
loading
Tags: PDF Viewer
Maico Schmitz
Asked On January 17, 2019 01:19 PM UTC

Hi,

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





Karthik Krishnaraj [Syncfusion]
Replied On 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. 


Bharat Vasant
Replied On 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.

Akshaya Arivoli [Syncfusion]
Replied On 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  


Bharat Vasant
Replied On 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.
  

Akshaya Arivoli [Syncfusion]
Replied On 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 



Lorne
Replied On 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.


Akshaya Arivoli [Syncfusion]
Replied On 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  


Mohan Selvaraj [Syncfusion]
Replied On 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 



Lorne
Replied On January 13, 2021 09:06 PM UTC

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

Mohan Selvaraj [Syncfusion]
Replied On 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  


Vasugi Sivajothi [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon