- Home
- Forum
- JavaScript - EJ 2
- Unable to load pdf by passing in base64 from server-side
Unable to load pdf by passing in base64 from server-side
Hi Team,
With regards to the Javascript(ES5) initialization of PDF Viewer, is there a possibility to render the pdf document by passing in the base64 string of the document from the server-side code.
This is how I just initialized the pdf viewer (client-side code),
byte[] imageBytes = System.IO.File.ReadAllBytes(System.IO.Path.Combine(data.path));
With regards to the Javascript(ES5) initialization of PDF Viewer, is there a possibility to render the pdf document by passing in the base64 string of the document from the server-side code.
I have referred to the below link already and followed the same procedure to load the pdf
https://www.syncfusion.com/kb/10331/how-to-load-the-pdf-document-as-base64-string-in-pdf-viewer
and yet I am getting the following error on initial load of the page,
https://www.syncfusion.com/kb/10331/how-to-load-the-pdf-document-as-base64-string-in-pdf-viewer
and yet I am getting the following error on initial load of the page,
client-side error is found.
Please check the custom headers provided in the AjaxRequestSettings property and web action methods in the ServerActionSettings property.
Please check the custom headers provided in the AjaxRequestSettings property and web action methods in the ServerActionSettings property.
This is how I just initialized the pdf viewer (client-side code),
<div id="pdfViewer"></div>
<script>
var viewer = new ej.pdfviewer.PdfViewer({
<script>
var viewer = new ej.pdfviewer.PdfViewer({
documentPath: "data:application/pdf;base64," + data.ImageBase64,
});
viewer.appendTo('#pdfViewer');
viewer.appendTo('#pdfViewer');
</script>
This is how I am getting my byte array from server-side,
byte[] imageBytes = System.IO.File.ReadAllBytes(System.IO.Path.Combine(data.path));
string imageBase64 = Convert.ToBase64String(imageBytes);
return imageBase64;
return imageBase64;
I have confirmed that the base64 string is valid by opening it in a iframe.
Thank you
Thank you
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
AA
Akshaya Arivoli
Syncfusion Team
June 5, 2020 11:43 AM UTC
Hi Uthej ,
Thank you for contacting Syncfusion support.
Based on the provided details we found that the serviceUrl property of the PDF Viewer is not provided. 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. We have created simple sample and shared the same in the below link,
Please refer to the below link to create PDF Viewer Web Service project,
Please try it and revert us with more details and the modified sample if you are still facing the issue. These details will be helpful for us to investigate further and assist you better.
Regards,
Akshaya
Marked as answer
UG
Uthej Gattu
June 5, 2020 12:06 PM UTC
Hi Akshaya,
Thanks for the help!
It is working fine once I added the serviceUrl property as 'https://ej2services.syncfusion.com/production/web-services/api/pdfviewer'. But I am not sure whether I need to use the Syncfusions's url since I am not using any server-side methods to load the PDF in my code.
If possible could you elaborate on the necessity of using the serviceUrl for every instance of the pdfViewer?
Can I just use the serviceUrl provided by you as a global constant and use it where ever I try to instantiate the pdf viewer component!? Will there be any problem with doing so?
Thanks & Regards,
Uthej Gattu
Thanks for the help!
It is working fine once I added the serviceUrl property as 'https://ej2services.syncfusion.com/production/web-services/api/pdfviewer'. But I am not sure whether I need to use the Syncfusions's url since I am not using any server-side methods to load the PDF in my code.
If possible could you elaborate on the necessity of using the serviceUrl for every instance of the pdfViewer?
Can I just use the serviceUrl provided by you as a global constant and use it where ever I try to instantiate the pdf viewer component!? Will there be any problem with doing so?
Thanks & Regards,
Uthej Gattu
MS
Mohan Selvaraj
Syncfusion Team
June 8, 2020 07:14 AM UTC
Hi Uthej ,
|
But I am not sure whether I need to use the Syncfusions's url since I am not using any server-side methods to load the PDF in my code. |
Our PDF Viewer control is both server and the client side oriented. So the serviceURL is required for rendering the PDF Pages in our PDF Viewer control. We request you to create the service URL from your side using the steps provided in the following link,
Since , our service URL is exposed only for demo purpose.
Note: Create the web service as provided in the above link and run the Service and copy the (localhost:xxx) and use the same in the serviceUrl PDF Viewer property in PDF Viewer sample. |
|
If possible could you elaborate on the necessity of using the serviceUrl for every instance of the pdfViewer? |
The serviceURL is required for rendering the PDF page in our PDF Viewer control. The PDF document or base64 string which is loaded in the client side will sent the request to the server side(with the help of the url which has provided in the serviceURL property)and we will process the data in our server side and will return the response to the client side with the details for rendering the PDF pages. |
|
Can I just use the serviceUrl provided by you as a global constant and use it where ever I try to instantiate the pdf viewer component!? Will there be any problem with doing so? |
Yes, you can use this as the global constant and can provide the same to the serviceUrl property on instantiate the pdf viewer component. |
Regards,
Mohan S
SIGN IN To post a reply.
- 3 Replies
- 3 Participants
- Marked answer
-
UG Uthej Gattu
- Jun 4, 2020 11:51 PM UTC
- Jun 8, 2020 07:14 AM UTC