Going around 'Media box not found' exception when rasterizing a PDF.

Q:

I'm getting the following error when I call pdfDraw.DrawInRect. What
is causing it?

Exception:
             Message: Media box not found.
             Function : PDFTRON::PDF::Page::GetMediaBox
---

A:

It seems that the PDF you want to rasterize is corrupt (because the
page is missing MediaBox property, which is required accoring to PDF
spec).

To go around this call SetMediaBox() on the page before
rasterization/printing. For example.

// C#
Page page = ...
page.SetMediaBox(new PDF.Rect(0, 0, 612, 792));
...
pdfdraw.DrawInRect(page, ...);

// in C++
Page page = ...
page.SetMediaBox(Rect(0, 0, 612, 792));
...
pdfdraw.DrawInRect(page, ...);