pdfSaveImageAsPBM
Save an image as a PBM file.
int pdfSaveImageAsPBM(PDFHandle pdf, int idx, char *pbmFileName)
This function saves the
idx
th image on the
page specified in the last call to pdfGetImages
as a PBM (portable
bitmap) file. It returns 1 if successful, 0 if there was an error.
This function only works for monochrome images and image masks; it will fail on grayscale and color images.
Typically, the PBM/PGM/PPM formats are used on Unix systems and the BMP format on Windows systems, but all formats are available in all versions of the XpdfImageExtract library.
C:
char *csName;
int nImgs, i, mask, colorSpace, w, h;
nImgs = pdfGetNumImages(pdf);
for (i = 0; i < nImgs; ++i) {
/* Save the image as a PBM, PGM, or PPM file */
pdfGetImageInfo(pdf, i, &mask, &colorSpace, &w, &h);
csName = pdfGetColorSpaceName(pdf, colorSpace);
if (mask) {
pdfSaveImageAsPBM(pdf, i, "image.pbm");
} else if (!strcmp(csName, "DeviceGray") ||
!strcmp(csName, "CalGray")) {
pdfSaveImageAsPGM(pdf, i, "image.pgm");
} else {
pdfSaveImageAsPPM(pdf, i, "image.ppm");
}
}