BoldDesk®Customer service software offering ticketing, live chat, and omnichannel support, starting at $49/mo. for 10 agents. Try it for free.
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Headers" value="accept, maxdataserviceversion, origin, x-requested-with, dataserviceversion,content-type" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer> |
GlobalConfiguration.Configuration.Routes.MapHttpRoute(
name: "PdfViewerApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional });
protected void Application_BeginRequest()
{
if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS")
{
Response.End();
Response.Flush();
}
} |
Hi Junaid,Thank you for contacting Syncfusion support.We have reproduced the reported issue while creating the PDF Viewer using the documentation link in our end. However we have created and shared the PDF Viewer web service and angular sample for your reference.Web Service Link:Angular Sample Link: https://stackblitz.com/edit/angular-xntzhf-vmhbub?file=app.component.htmlAnd, we suggest to configure the CORS Policy in web config file and update the global configuration in Global.asax file. Please refer to the below code snippetConfigure the CORS policy in the web config file:
Set the Global configuration in the Global.asax file:
GlobalConfiguration.Configuration.Routes.MapHttpRoute(name: "PdfViewerApi",routeTemplate: "api/{controller}/{action}/{id}",defaults: new { id = RouteParameter.Optional });protected void Application_BeginRequest(){if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS"){Response.End();Response.Flush();}}Kindly try this and revert to us with more details if you have any concerns. We will refresh the UG documentation on March 3rd weekly NuGet release.Regards,Dhivya.
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Headers" value="accept, maxdataserviceversion, origin, x-requested-with, dataserviceversion,content-type" />
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer> |
The issue is based on NewtonSoft.Json not being used as this is an optional extra for .net core.
Further to this the system requires PascalCase, whereas camelCase is the default resolver.
So, in order to have this work, the following is required within the Startup.ConfigureServices function :
services.AddControllers().AddNewtonsoftJson(options => {
// Use the default property (Pascal) casing
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
Once that is done then 'Web Services' are seen to be listening.
Please note that this has NOTHING to do with CORS policy and everything to do with not allowing different JSON configurations, i.e. the default Json service being System.Text.Json and further to this, the outputted Json must be in PascalCase, so either you need to do this globally, within the AddNewtonsoftJson call, or change the output format before submitting the Json
I do understand that previously Pascal Case was the default, however for a while camelCase has been the default, as has System.Text.Json instead of NewtonsoftJson.
Why wouldn't this have been changed in SyncFusion to allow simpler implementation of the PDF Viewer.
I have already verified that I am able to load up a document on the server side using camelCase, however in order to furnish the data to the control the output itself has to be PascalCase
So decided that although I have no issue with using NewtonSoft I wasn't happy with setting the default json ContractResolver to use PascalCase instead of camelCase.
With that in mind, I enabled NewtonSoft within the the Startup.ConfigureServices routine by using the following:
services.AddControllers().AddNewtonsoftJson();
thereafter within the PdfViewerController I created a private routine to return the Json as required:
private IActionResult json (object response) {
return Json(response, new Newtonsoft.Json.JsonSerializerSettings {
ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver()
});
}
And then in all the other routines, where SyncFusion was passing back Json,
i.e: return Content(JsonConvert.SerializeObject(jsonResult));
I changed it to use the new private json routine:
return json(new PdfRenderer(cache).GetPage(jsonObject));
With that in mind, please note that I am not passing back Content where the content has been serialised into Json, I am rather using the routines provided by .net core Controllers to have the system serialise as required, simply passing in the serialisation options.
All is working now, and I have the benefit of all other Json responses still being in camelCase as expected based on standardisation.
I am not clear, then I have added the cs file so that it may be looked at.
Good day, please note that my issue was not resolved in it's entirely.
I would still get intermittent failures stating that the API was not listening, or some documents would not load correctly, specifically documents that have landscape pages with images in them.
After much analysis and testing, I found that the most stable way to use this control was to change the PdfViewerController load function to not use the logic that you provided, but rather load the document myself into a byte array and then load up the document via a stream from that byte array,
Then instead of allowing the control to specify when to load itself, I changed the app to call the load myself from JavaScript when required, and also set the serviceUrl before calling the load instead of directly on the control itself.
This was the only way to get the control to work in a stable manner.
PLEASE NOTE
Simply changing the Load endpoint within the PdfViewerController was not sufficient to consistently remove the "Web-service is not listening" message.
I literally had to manage when to load the PDF Document via JavaScript calling the load function.
Although I could not debug the load function, I found that when I allowed the control to load itself, the Load endpoint was called, and data was returned correctly, however the RenderPdfPages endpoint would then no be called.
Once changed to the JavaScript manual load, then I found that the Load endpoint would be called, and subsequently so would the RenderPdfPages endpoint.
Here is an example of the load function that I am calling. Note that within this function I am setting the serviceUrl programmatically from a dataset value and passing the Id of the Pdf Document to the load function based on how we store the PDF's on the server.
load: function () {
var pdfElement = document.getElementById("ej2-pdf-viewer");
var pdfViewer = pdfElement.ej2_instances[0];
pdfViewer.serviceUrl = pdfElement.dataset.serviceuri;
pdfViewer.load(pdfElement.dataset.itemid);
}
hi syncfusion team i have an issue when run pdfviewer in my local host its working pdf load successfully but i host my website in server then pdfviewer not working why ....... and i found a message webservice not listening please start web service , please support me what a issue
If the Pdfium assembly is available in this path C:\Pdfium\x64 or D:\Pdfium\x86, the reference path should be PdfRenderer.ReferencePath = "C:/";
The parent folder has to be provided as the path in the ReferencePath API.
Note: Provide this path in the Load method of the PDFViewerController.cs
PdfRenderer PdfRenderer = new PdfRenderer();
PdfRenderer.ReferencePath = @"C:/"; |
|
Note: You need to refer the ParentFolder up to x64/x86 folder.
PdfRenderer.ReferencePath = _hostingEnvironment.ContentRootPath + \\Pdfium\\; |
madam the solution you gave was successful but a new issue is coming webservice is not listening please start web service how can solve it..?
if I do the same thing on local server then pdf load successfully ,how can start webservice asp.net mvc
Document Reference pointer does not exist in the cache this erorr show console
madam an error coming
Document Reference pointer does not exist in the cache this error show console
catche error
Good day Atul,
That error is quite common. If you are looking to simply display a PDF then I would suggest you use an iFrame or an Embed.
I have been trying for months to get the SyncFusion PDF Viewer working, and in Production it 8 out of 10 times provides me with the " Web-service is not listening" issue.
I truly would like to get this working consistently as I use other SyncFusion components and would like to keep my toolset consistent, but having no lock with this component.
I have tested with other PDF Management components for JavaScript and Blazor, and those work without issue, however the cost of the other services are exorbitant.
madam how can set connection string in IDatabase
i found a message this when set memory cache
No connection is available to service this operation: GET PDF_INFOSYb6CdyKTdpLm0beysR9VA==; An existing connection was forcibly closed by the remote host; IOCP: (Busy=0,Free=1000,Min=4,Max=1000), WORKER: (Busy=1,Free=8190,Min=4,Max=8191), Local-CPU: n/a
public string redisconnectonstring = "xxxx ,syncTimeout=100000";
|
keys *
flushall |
hi madam i follow all step connection problem resolve but even now
"Document Reference pointer does not exist in the cache" issue not resolve
Good day,
This would not be the case, The production environment that we loaded it on to was a simple physical server at a client site, there was no load balancing in place.
Upon testing I noticed that even on my dev machine, when the "debugger" was not attached the same issue would occur.
The point is moot though, I have had to remove the SyncFusion PDF Viewer from the solution that I was providing, and have gone another route.