I have a PDF file stored in a database as a byte array. I'm reading the PDF byte array from my database back into my application.
Now, I'm trying to display the PDF with the RadPdfViewer but it is not working.
Here is my code:
byte[] pdfAsByteArray= File.ReadAllBytes(@"C:\Users\Username\Desktop\Testfile.pdf");
//Save "pdfAsByteArray" into database
//...
//Load pdf from database into byte[] variable "pdfAsByteArray"
using (var memoryStream = new MemoryStream(pdfAsByteArray))
{
this.PdfViewer.DocumentSource = new PdfDocumentSource(memoryStream);
}
when I execute the application I just get an empty PdfViewer.
Question: How do I set the DocumentSource the right way?
Question: How do I dispose the stream? (note that using
doesn't works)
Note: I wan't to avoid things like writing a temp file to disk
Edit:
I figured it out but I am not completely satisfied with this solution:
Not working:
using (var memoryStream = new MemoryStream(pdfAsByteArray))
{
this.PdfViewer.DocumentSource = new PdfDocumentSource(memoryStream);
}
Working:
var memoryStream = new MemoryStream(pdfAsByteArray);
this.PdfViewer.DocumentSource = new PdfDocumentSource(memoryStream);
I don't know how teleriks RadPdfViewer component works but I wan't to dispose the Stream.