How do I I rasterize PDF page to WPF bitmap?

Q: A quick question regarding the rasterizer in the PDFNet , are there
any plans to allow direct rasterization to WPF bitmaps? At the present
I’m having to take the GDI+ bitmap, create a WPF bitmap of the same
dimensions and then copy the pixel data from the GDI+ bitmap to the
WPF bitmap.

The following is the code I’m currently using:
private void DisplayCurrentPage()
using (PDF.PDFDraw draw = new pdftron.PDF.PDFDraw())

using (System.Drawing.Bitmap gdiBitmap = draw.GetBitmap
System.Drawing.Imaging.PixelFormat srcPixelFormat =

WriteableBitmap wpfBitmap = new WriteableBitmap
(gdiBitmap.Width, gdiBitmap.Height, gdiBitmap.HorizontalResolution,

gdiBitmap.VerticalResolution, PixelFormats.Bgr24, null);

System.Drawing.Imaging.BitmapData bitmapData =
gdiBitmap.LockBits(new System.Drawing.Rectangle
(0, 0, gdiBitmap.Width, gdiBitmap.Height),

System.Drawing.Imaging.ImageLockMode.ReadOnly, srcPixelFormat);

wpfBitmap.WritePixels(new Int32Rect(0, 0,
gdiBitmap.Width, gdiBitmap.Height), bitmapData.Scan0,
bitmapData.Stride *
bitmapData.Height, bitmapData.Stride);


imagePdfPage.Source = wpfBitmap;


A: An extended version of PDFNet with WPF extensions will be released
in the near future. In the meantime you could convert GDI+ bitmaps to
WPF bitmaps as shown in the above code snippet. You may want to make
sure that the pixel format for the WPF bitmap matches the pixel format
of input GDI+ bitmap. Another approach (though probably a bit less
efficient) is to export PDF to a PNG (using pdfdraw.Export(…)) and
then load the image in a WPF bitmap.