question

AshokKumarViswanathan-4530 avatar image
0 Votes"
AshokKumarViswanathan-4530 asked RoyLi-MSFT commented

Application crashes while creating windows.data.pdf.pdfdocument for particular PDF document

We have been using the PdfDocument ([windows.data.pdf.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 windows.data.pdf.pdfdocument for particular PDF document.

Kindly check the issue and let us know,

https://drive.google.com/file/d/19n_eLBm1huV3KKEFDgHZhIg_rsoBy4NF/view?usp=sharing

Code Snippet to replicate:

private async void BtnLoadFile_Click(object sender, RoutedEventArgs e)
{
FileOpenPicker picker = new FileOpenPicker();
picker.FileTypeFilter.Add(".pdf");
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);
result1.AsTask().Wait();
Windows.Data.Pdf.PdfDocument _pdfDocument = result1.GetResults();
result = null;
}
}
}

dotnet-xamarinwindows-uwp
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@AshokKumarViswanathan-4530 Any updates about this issue?

0 Votes 0 ·

1 Answer

RoyLi-MSFT avatar image
0 Votes"
RoyLi-MSFT answered

Hello,

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.