How do I convert a PDF page to a Bitmap on Windows Phone 8 / WinRT?

Q: How do I convert a PDF page to a Bitmap on Windows Phone 8 / WinRT?

A:

On Windows Phone, here’s an example of what you can do:

private async void DoPDFDraw(PDFDoc doc, int pagenum)

{

PDFDraw pdfDraw = new PDFDraw();

pdfDraw.SetImageSize(200, 200);

RawBitmap bitmap = await pdfDraw.GetRawBitmapAsync(doc.GetPage(pagenum));

}

This RawBitMap has a buffer that contains the image data, as well as some properties for with and height and so on.

Note that we are about to release a newer version of the Windows Phone 8 (WP8) SDK, so shortly there will be more powerful options (similar to those on WinRT) that you can use.

On WinRT, you can do the following:

private async void DoPDFDraw(PDFDoc doc, int pagenum)

{

PDFDraw pdfDraw = new PDFDraw();

pdfDraw.SetImageSize(200, 200);

PDFPage mPage = doc.GetPage(pagenum);

BitmapSource bmp = await pdfDraw.GetBitmapAsync(mPage);

IMG.Source = bmp; // Where IMG is a UI image element.

}