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. (Last updated on: June 24, 2019).
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 Aug 4,2020 11:47 AM UTC ASP.NET MVC - EJ 2 5
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 



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