After watching the first 10 minutes of the video provided by Nate Diamond, PDF rendering is an easy task. This solution is for Windows 8.1 as PdfDocument and PdfPage are new to the version. Below it displays StorageFile(which is a .pdf file) into images and places them in the stack pane with vertical scrolling ( imagePanel).
private async void renderPdf(StorageFile file)
{
imagePanel.Children.Clear();
PdfDocument pdf = await PdfDocument.LoadFromFileAsync(file);
for (uint pageNum = 0; pageNum < pdf.PageCount; pageNum++)
{
PdfPage page = pdf.GetPage(pageNum);
InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream();
await page.RenderToStreamAsync(stream);
BitmapImage source = new BitmapImage();
source.SetSource(stream);
Image pdfPage = new Image();
pdfPage.HorizontalAlignment = HorizontalAlignment.Center;
pdfPage.VerticalAlignment = VerticalAlignment.Center;
pdfPage.Height = page.Size.Height;
pdfPage.Width = page.Size.Width;
pdfPage.Margin = new Thickness(0, 0, 0, 5);
pdfPage.Source = source;
imagePanel.Children.Add(pdfPage);
}
}
Asynchronous methods can also run as tasks if waiting is undesirable.
PdfDocument pdf = PdfDocument.LoadFromFileAsync(file).AsTask().Result;
source
share