pdfConvertRegionToBitmap

Convert a rectangular region to a bitmap in memory.
// Windows int pdfConvertRegionToBitmap(PDFHandle pdf, int page, int regionX, int regionY, int regionW, int regionH, double dpi, int color, BITMAPINFOHEADER *dibHdr, char **bits) // Linux, Mac OS X int pdfConvertRegionToBitmap(PDFHandle pdf, int page, int regionX, int regionY, int regionW, int regionH, double dpi, int color, PDFImageHeader *imgHdr, char **bits)
This function converts a rectangular region of a PDF page to a bitmap in memory.

The rectangular region is specified by the x,y coordinates of its upper-left corner and its width and height - in bitmap coordinates, not PDF coordinates. That is, if the whole-page bitmap would have been 1000 pixels wide and 2000 pixels high, and you request a region with (x,y) = (0,0) and (w,h) = (1000,500), the resulting bitmap will be the top fourth of the page.

In the Windows DLL version, this function fills in a BITMAPINFOHEADER struct; in the Linux and Mac OS X versions, it fills in a PDFImageHeader structure.

On all platforms, the other arguments are:

The pdfImageDevNToRGB mode produces RGB output like pdfImageRGB, but does the rasterization in DeviceN (CMYK + spot colors) so overprint previews will be more accurate.

The pdfImageGrayToMono mode does the rasterization in 8-bit grayscale and converts to 1-bit monochrome at the end. This is useful for files that use transparency – because 1-bit monochrome mode doesn't support transparency.

On Windows, the data returned in bits is stored in bottom-up (upside-down) format, with each line padded to a multiple of 32 bits (standard Windows bitmap format).

On Linux and OS X, the data returned in bits is stored in top-down format, with no line padding. The PDFImageHeader struct contains the following fields:

The pdfConvertPageToBitmap function returns pdfOk if successful, otherwise an error code.

The caller is responsible for freeing the bits pointer after using it, by calling pdfFreeMemory.

C (Windows):
BITMAPINFOHEADER hdr; char *bits; /* convert the top part of page 5 to a 72 dpi color bitmap */ pdfConvertRegionToBitmap(pdf, 5, 0, 0, 1000, 500, 72, pdfImageRGB, &hdr, &bits); ... pdfFreeMemory(bits);
C (Linux, OS X):
PDFImageHeader hdr; char *bits; /* convert the top part of page 5 to a 72 dpi color bitmap */ pdfConvertRegionToBitmap(pdf, 5, 0, 0, 1000, 500, 72, pdfImageRGB, &hdr, &bits); ... pdfFreeMemory(bits);
pdfWritePageBitmap
pdfConvertPageToBitmap
pdfConvertPageToBitmap2
pdfConvertRegionToBitmap2