Click here to Skip to main content
15,889,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In above comment, there was some mistakes. Sorry!!!
I read PDF content as byte[] and then I use above method. It doesn’t work.
But for the image (png, bmp, jpeg) byet[], it works properly
Why it doesn’t work for PDF byte[].
-------------------------------------------------------------------------------------
FileOpenPicker filepickerOpen = new FileOpenPicker();
filepickerOpen.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
filepickerOpen.ViewMode = PickerViewMode.Thumbnail;
filepickerOpen.FileTypeFilter.Clear();
filepickerOpen.FileTypeFilter.Add(".png");
filepickerOpen.FileTypeFilter.Add(".pdf");
StorageFile storage= await filepickerOpen.PickSingleFileAsync();

byte[] buffer = WindowsRuntimeBufferExtensions.ToArray(await FileIO.ReadBufferAsync(storage));
using (MemoryStream ms = new MemoryStream(buffer))
{
var ims = new InMemoryRandomAccessStream();
DataWriter dataWriter = new DataWriter(ims);
dataWriter.WriteBytes(buffer);
dataWriter.StoreAsync();
ims.Seek(0);
BitmapImage img = new BitmapImage();
img.SetSource(ims);
ImageDocument.Source = img;
}
-------------------------------------------------------------------------
Posted

A PDF file is not a simple byte array, it is a structured file consisting of different content elements. Go to the Adobe website and get a copy of the PDF documentation for further information.
 
Share this answer
 
As Richard already noted, A PDF file is not a simple byte array. This[^] article may shed some light on how you need to pursue this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900