Application crashes while creating for particular PDF document

Ashok Kumar Viswanathan 71 Reputation points

We have been using the PdfDocument ([][1]) API to access the PDF pages and we will convert the pdf pages into Image, to view the page content in our application. We are facing exception while creating for particular PDF document.

Kindly check the issue and let us know,

Code Snippet to replicate:

private async void BtnLoadFile_Click(object sender, RoutedEventArgs e)
FileOpenPicker picker = new FileOpenPicker();
var pdfFile = await picker.PickSingleFileAsync();
if (pdfFile != null)
var result = pdfFile.OpenAsync(FileAccessMode.Read);
IRandomAccessStream randomStream = result.AsTask().Result;
if (randomStream != null)
IAsyncOperation<global::Windows.Data.Pdf.PdfDocument> result1;
result1 = global::Windows.Data.Pdf.PdfDocument.LoadFromStreamAsync(randomStream);
Windows.Data.Pdf.PdfDocument _pdfDocument = result1.GetResults();
result = null;

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,325 questions
Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Roy Li - MSFT 32,731 Reputation points Microsoft Vendor


    Welcome to Microsoft Q&A!

    After testing, we could confirm that this issue is related to that specific PDF file you shared. When testing other standard PDF files, your code works correctly. The behavior you mentioned only happens when handling that specific PDF file. Then, for test purposes, I opened your PDF file in a browser and printed it as a new standard PDF file. Your code could open the newly generated PDF file correctly. So, this behavior is related to the PDF file that you are using. And the solution is that you might need to convert the target PDF file into a standard PDF file first via other ways like using a browser.

    Thank you.

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments