How to Implement RenderPageToDeviceContext


  • I need to create an image (or a binary stream of image) of any single page in a PDF.

    And I need to use "RenderPageToDeviceContext" for this purpose as I came to know that its the better (and faster) way to do this kind of stuff. 

    But am just not able to get enough help online to use this method. 
    Can you please provide me any sample (or link to any sample page) to get this task done?

    Thanks in advance.
    Monday, May 5, 2014 9:51 AM

All replies

  • Why do you want to use RenderPageToDeviceContext?

    RenderPageToDeviceContext is used to render to a Direct2D context. You wouldn't typically use it in a C# app as there is no way provided to use D2D from C#. You would need to interop to Direct2D.

    To render PDF in Xaml you would use RenderToStreamAsync as demonstrated in the PDF viewer sample            

    Saturday, May 10, 2014 12:28 AM
  • Hello Rob Caplan,

    Thanks For Reply.

    Currently I am using the same way as you suggested to render pdf pages. In that I need to support zoom factor greater than 400% .But it is too slow. I want faster way to render Pdf Pages for that I refer this link and came to know that we have to use any method from “RenderPageToSurface” or “RenderPageToDeviceContext" for that I refer to this sample but when I apply my code for zoom, it gives following Exception while Debugging in Surface Tab:

    “System.OutOfMemoryException: Insufficient memory to continue the execution of the program.”

    Tuesday, May 13, 2014 5:19 AM
  • You will need to interop to Direct2D in C++ to use that. I'm not aware of any samples specifically on this, but if you start with a D2D interop sample song the PDF viewer should be fairly straightforward
    Tuesday, May 13, 2014 6:59 PM