PDFRasterizer.Rasterize error


I get a System.NullReferenceException when I use
I tried the 2 overloads bellow, they throw the same error.
Is there something wrong with the way I assign the InPtr variable?
Debugging does not bring any relevant info.

PDFDraw.Export works perfectly, but I need to use PDFRasterizer.

Thanks in advance!

PDFDoc existing_doc = new PDFDoc("C:\\InputDoc.pdf");
Page page = existing_doc.GetPage(1);
PDFRasterizer pdfrasterizer = new
Matrix2D my_matrix = new Matrix2D(1, 0, 0, 1,0, 0);

int height = (int)page.GetPageHeight();
int width = (int)page.GetPageWidth();
int imgsize = height* width;
int[] image= new int[imgsize];
int comps = 4;
int stride = ((width * comps + 3) / 4) * 4;

IntPtr ip = Marshal.AllocCoTaskMem(height * stride);

//getting NullRef here
pdfrasterizer.Rasterize(page, ip, my_matrix *
                        new Rect(0, 0, width, height), 72);
pdfrasterizer.Rasterize(page, ip, my_matrix *
page.GetDefaultMatrix(true), null, 0);

Marshal.Copy(ip, image, 0, imgsize);

//do something here with the image

Is there are a reason why you are not using
pdftron.PDF.PDFDraw.GetBitmap() instead of PDFRasterizer?
PDFDraw is much simpler to use and PDFRasterizer has advanatages only
in very limited number of cases.

Indeed, pdftron.PDF.PDFDraw.GetBitmap() and pdftron.PDF.PDFDraw.Export() worked fine.

However, I want to try PDFRasterizer to see if it is faster.

For instance, PDFDraw.GetBitmap() took 140ms, I was wondering if PDFRasterizer.Rasterize() takes less time.

I am processing large documents, with tens of pages, and I try to optimize each processing stage.

Thanks in advance.

Under the hood PDFDraw is using PDFRasterizer so rendering will not be
any faster.