pdfConvertPageToBitmap
Convert a page to a bitmap in memory.
// Windows
int pdfConvertPageToBitmap(PDFHandle pdf, int page, double dpi, int color,
BITMAPINFOHEADER *dibHdr, char **bits)
// Linux, Mac OS X
int pdfConvertPageToBitmap(PDFHandle pdf, int page, double dpi, int color,
PDFImageHeader *imgHdr, char **bits)
This function converts a PDF page to a bitmap in memory. 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:
page
= page numberdpi
= resolution (dots per inch)color
= color setting - one of:pdfImageMono
: 1-bit monochromepdfImageGray
: 8-bit grayscalepdfImageRGB
: 8-bit RGBpdfImageDevNToRGB
: 8-bit RGB, rasterized in DeviceN and then converted to RGBpdfImageGrayToMono
: 1-bit monochrome, rasterized in 8-bit grayscale and then converted to 1-bit
bits
= pointer to the returned bitmap data
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:
width
= image widthheight
= image heightcolor
= the color argument passed topdfConvertPageToBitmap
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 page 5 to a 72 dpi color bitmap */
pdfConvertPageToBitmap(pdf, 5, 72, pdfImageRGB, &hdr, &bits);
...
pdfFreeMemory(bits);
C (Linux, OS X):
PDFImageHeader hdr;
char *bits;
/* convert page 5 to a 72 dpi color bitmap */
pdfConvertPageToBitmap(pdf, 5, 72, pdfImageRGB, &hdr, &bits);
...
pdfFreeMemory(bits);