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.