PDFDraw vs PDFRasterizer Performance

Q:

Is there a speed difference between PDFDraw and PDFRasterizer?

If so, how much approximately? (I know it will be different for each PDF, but is it a small difference like 3-5% or is it potentially a big difference such as 50% in some scenarios).

I don’t see any examples of PDFRasterizer usage so I have not yet tested it myself.

A:

PDFDraw uses PDFRasterizer internally. The only difference is that PDFDraw allocates a buffer, initializes it, passes it on to PDFRasterizer for rendering, and might do some post-processing work. Since the pre-processing and post-processing work is pretty much negligible compared to the rendering part, the difference is so too.

PDFRasterizer is provided to a user for fine controls. For example, if you want to render a PDF page into a huge image, you can use PDFRasterizer to render a patch one at time and piece them together yourself. PDFDraw doesn’t support this and it might throw an exception in this case due to out of memory exception.

A possible use case for PDFRasterizer:

PDF::Page l_page = m_PdfDoc->GetPage(inPage);

double l_wTest = (double)inSize / l_page.GetPageWidth();

double l_hTest = (double)inSize / l_page.GetPageHeight();

double l_scale = l_wTest;

if(l_hTest < l_scale) l_scale = l_hTest;

Common::Matrix2D mtx(l_scale, 0, 0, l_scale, 0, 0);

PDF::Rect bbox(l_page.GetMediaBox());

bbox.Normalize();

int width = int(bbox.Width() * l_scale);

int height = int(bbox.Height() * l_scale);

int comps = 4;

int stride = ((width * comps + 3) / 4) * 4;

int l_size = height * stride;

unsigned char *buf = new unsigned char[l_size];

memset(buf, 0xFF, l_size);

PDF::PDFRasterizer rast;

rast.Rasterize(l_page, buf, width, height, stride, comps, false, mtx);