Am opening the PDF file as Image and displaying it in a flipview.
public async void OpenPDF(StorageFile file)
{
var pdfFile = await PdfDocument.LoadFromFileAsync(file);
if (pdfFile == null)
return;
for (uint i = 0; i < pdfFile.PageCount; i++)
{
StorageFolder tempFolder = ApplicationData.Current.LocalFolder;
StorageFile jpgFile = await tempFolder.CreateFileAsync(pdfFile + "-Page-" + i.ToString() + ".png", CreationCollisionOption.ReplaceExisting);
var pdfPage = pdfFile.GetPage(i);
if (jpgFile != null && pdfPage != null)
{
IRandomAccessStream randomStream = await jpgFile.OpenAsync(FileAccessMode.ReadWrite);
await pdfPage.RenderToStreamAsync(randomStream);
await randomStream.FlushAsync();
randomStream.Dispose();
pdfPage.Dispose();
}
PdfImages.Add(jpgFile.Path);
}
this.pdfViewer.ItemsSource = PdfImages;
}
I need to change the views(FitWidth,FitPage,100%) like windows 8.1 PDF viewer.
In windows 8.1 app I used Reader app and it will open the PDF side by side to app screen. But in UWP its not working like the same. So am looking for alternatives. Many PDF viewer is available, but all needs to be licensed. So is there any free source available?.
In UWP, you can display the PDF files content in the Image control, then you can set the Image.Stretch property to describe how an Image should be stretched to fill the destination rectangle. You can also adjust the layout to display the PDF file as you want. More details about display PDF files, please look into the PdfDocument sample.
Besides, here is a simple sample,
MainPage.xaml,
MainPage.xaml.cs,