Q: We call PdfNet from a C++ function which is called by a webservice
using ASP.Net technology.
PDFNet is used to rasterize at 1200 dpi a Pdf file.
In general this works fine. However, recently the rasterizer threw an
exception of type pdftron.Common.Exception. The message obtained using
pdftron.Common.Exception.GetMessage() is "Bad Allocation".
Any ideas what could be the problem?
A: Given that you are rasterizing at 1200 dpi it is not surprising
that you are running into memory allocation problems. Only a memory
buffer used to keep the rendered image for a letter page would be
close to 2 GB. If you would need to render slightly larger page (e.g.
as returned by page.GetCropBox()) the application would need to
allocate a memory buffer larger than 2GB and memory allocation
exception would be thrown.
If you need to rasterize PDF pages at very high DPI you may want to
a) Rasterize the page in stripes/tiles using
page.SetCropBox(stripe_bbox) to indicate the sub region of the page to
rasterize. For example, if the input page has a media box
[0,0,595,842] (tiger.pdf from PDFNet/Samples/TestFiles folder), you
could render the page at 2000 DPI (Dots Per Inch) in four stripes
(using 210.5 point increments along the Y axis) as follows:
This way you would effectively cut down on the memory requirements by
a factor of 4.
b) Use 64-bit version of PDFNet (http://www.pdftron.com/
downloads.html#PDFNETCPPSDK). On 64-bit platforms an application can
allocate more than 2GB of memory so you would be able to render larger
images. Still, for performance reasons it is probably a better idea to
implement the former approach.