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

Import byte stream

Hello,

It is possible to directly read a byte stream in the PDF viewer?

Regards

j.Nord

7 Replies

SA Sabari Anand Senthamarai Kannan Syncfusion Team July 18, 2016 08:37 AM UTC

Hi Jürgen, 
 
Thanks for your interest in Syncfusion products. 
 
Yes, byte streams can be loaded in to the PDF viewer control to display the PDF document. The code snippet for loading the PDF file as a byte stream in the PDF viewer is given below, 
 
Code snippet: 
PdfViewerHelper helper = new PdfViewerHelper(); 
MemoryStream stream = new MemoryStream(File.ReadAllBytes(Helper.GetFilePath("F# Succinctly.pdf"))); 
helper.Load(stream); 
 
A sample which illustrates loading PDF document using byte stream into PDF viewer is available in the following link. 
 
 
Regards, 
Sabari Anand


JN jnord July 18, 2016 12:46 PM UTC

Hi Sabari,

the solution can't work. In javascript is not a command "memorystream". And the sample works with a file. We get a base64String or a byteStream from the server (c# Generic handler  .ashx) and would load it in the viewer. But it doesn't work. We have no file.

It is possible to load the base64String or a byteStream from a server (ajax request) into the pdf viewer?

Regards

j.nord


SA Sabari Anand Senthamarai Kannan Syncfusion Team July 19, 2016 01:20 PM UTC

Hi Jürgen, 
 
Sorry for the inconvenience caused. 
 
The code snippet provided in the previous update is to be implemented in PdfViewerController in WebApi(server side). 
 
Yes, it is possible to load base64 string to the PDF Viewer control in the client side. We have created a sample which illustrates the loading of PDF document as base64 string into the PDF Viewer. The sample is available in the following link, 
http://www.syncfusion.com/downloads/support/forum/125017/ze/Sample1345948333 
 
Working with the sample: 
·       When the sample is ran, a web page is displayed with a dropdown list containing document names from the Data folder.  
·       When a value in the dropdown list is selected, the ‘change’ event is triggered. At the change event handler, an AJAX request is fired to the “GetFileStream” action method of PdfViewerController. 
·       At the “GetFileStream” method, the file path is got from the value in the dropdown list. Then the FileStream is created using the file path. The stream is stored in a memory stream. Then it is converted to byte array. From the byte array, the base64 string is created and returned to the client side. 
·       After the success of the AJAX request, the control is initialized and the base64 string is applied to load API of the PdfViewer control.  
  
Please let us know if you have any concerns. 
 
Regards, 
Sabari Anand


JN jnord July 20, 2016 02:58 PM UTC

Hi Sabari,

so it can't work. We get with the ajax command in the "sucess:" the data.

We then pass the data in the Load command and then we get "a split error". Whether binary or base64.

Why the service is called within the sucess again?
. $ ("# Container") ejPdfViewer ({ServiceUrl: '../api/PdfViewer'});

That's not logical.

Why can not store a Base64 or Binarischen value simply in obj.load(binaryFile or base64 string)?

Regards

j.nord


SA Sabari Anand Senthamarai Kannan Syncfusion Team July 21, 2016 11:50 AM UTC

Hi Jürgen, 
 
Thank you for your update. 
 
We have created a new incident under your account for your queries in your last update. We request you to follow the new incident for further updates. You can log in to our support system using the following link, 
 
 
Regards, 
Sabari Anand


JA Jainish September 20, 2016 08:58 AM UTC

This is very useful post. why this type of functionality you didn't add in your main document ?

Thanks


SA Sabari Anand Senthamarai Kannan Syncfusion Team September 21, 2016 12:26 PM UTC

Hi Jainish, 
 
Thank you for using Syncfusion products. 
 
The various methods to load a PDF document in the PDF Viewer control at the server is available in the following documentation link, 
 
 
Please let us know your requirements in viewing the PDF document using the PDF viewer control. So that it will be helpful for us to fulfill your requirements. 
 
Regards, 
Sabari Anand

Loader.
Up arrow icon