Free Support Forum - aspose.com

Opening PDF from memory Stream

I am using Aspose.Pdf.Kit.dll version – 2.6.4.3

I am working on windows application in C# .

I have PDFs stored in database in byte array format.

Now what I want is to display the PDF to the user directly from the byte array
without writing those byte array anywhere on the system.

I have used following piece of code :

Byte[] objB = (Byte[])pdfDt.Rows[0][1];

MemoryStream mStream = new MemoryStream(objB);

Aspose.Pdf.Kit.PdfViewer pv = new Aspose.Pdf.Kit.PdfViewer();
pv.OpenPdfFile(mStream);



But it neither gives any error nor displays the PDF.

Can anyone help me out of this.


Thanks in advance

Hi,

Simply calling the OpenPdfFile function will not display the file. You need to call the DecodeAllPages or DecodePage function and use the Bitmap returned to display that page.

Thanks.

Thanks for the reply.

I have tried with following code. But got stuck as I could not understand what to do further.

Byte[] objB = (Byte[])pdfDt.Rows[0][1];
MemoryStream mStream = new MemoryStream(objB);
Aspose.Pdf.Kit.PdfViewer pv = new Aspose.Pdf.Kit.PdfViewer();
pv.OpenPdfFile(mStream);
Bitmap[] objP = pv.DecodeAllPages();
pv.ClosePdfFile();



I will be highly thankfull if you could please give me the proper piece of code to resolve my issues.


Requirements are as follows :

1. PDFs stored in byte array format in database.
2. The file must be opened on a button click with Acrobat Reader.
3. The file will not be written anywhere on any physical location on the system.
4. The file will display pages from second page onwards of the original file.
5. User must be able to select any text in the opened PDF file.
6. User must be able to save the file if user opts for saving the file.




Thanks in advance

Hi,

Your requirments of 2 and 3 are in conflict with one another. If you use Acrobat Reader to open the file then you must have the file on the file system as Acrobat Reader doesn't support opening file from memory. If you use Aspose.Pdf.Kit to open the file then you can open it from memory but requirements 5 and 6 can't be fullfilled.

Thanks.