[UWP] application creashes at RenderToStreamAsync while converting pdf page to stream.

Radhika 46 Reputation points
2022-07-01T06:03:41.15+00:00

I am working on a UWP (cpp/winrt) project where the user selects the pdf file and the pages of the file are converted to images using PdfDocument API through the loop. Mostly all the files are getting converted to images except few files. The issue occurs at the method RenderToStreamAsync which converts the pdf page to the stream-

PdfPage page = pdfDocument.GetPage(Page_Number);  
InMemoryRandomAccessStream stream;  
co_await page.RenderToStreamAsync(stream);  

For some pdf files, the application crashes at this (RenderToStreamAsync) method.
The error is as follows:

D3D11: Removing Device.
D3D11: Removing Device.
Exception thrown at 0x00007FFD134A4FD9 in ###.exe: Microsoft C++ exception: _com_error at memory location 0x0000003C214FA838.
Exception thrown at 0x00007FFD134A4FD9 in ###.exe: Microsoft C++ exception: _com_error at memory location 0x0000003C214FB048.
D3D11: Removing Device.
Exception thrown at 0x00007FFD134A4FD9 in ###.exe: Microsoft C++ exception: _com_error at memory location 0x0000003C214FA838.
Exception thrown at 0x00007FFD134A4FD9 in ###.exe: Microsoft C++ exception: _com_error at memory location 0x0000003C214FB048.
Exception thrown at 0x00007FFD134A4FD9 (KernelBase.dll) in ###.exe: WinRT originate error - 0x8899000C : 'There has been a presentation error that may be recoverable. The caller needs to recreate, rerender the entire frame, and reattempt present.'.
Exception thrown at 0x00007FFD134A4FD9 in ###.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x0000003C20AFB208.

I tried putting the line which is giving issue inside the try-catch block, but the application still crashes.
Is there any work around to skip the page which is causing the issue while converting to the stream, by handling the exception occurring because of RenderToStreamAsync method and to prevent the application from crashing?

Working environment: Windows 10, Visual Studio - 16.11.15

Any help would be appriciated.

Universal Windows Platform (UWP)
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,544 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,856 Reputation points
    2022-07-04T13:46:00.503+00:00

    Hello,
    Welcome to Microsoft Q&A!

    It looks same problem as Castorix31 mentiond above, and our team member has replied it. please try to convert the target PDF file into a standard PDF file first via other ways like using a browser.
    For UWP side, there is no api could convert it as standard pdf format, you may need to try general desktop api.

    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.