pdfSaveImageAsPGM
Save an image as a PGM file.
int pdfSaveImageAsPGM(PDFHandle pdf, int idx, char *pgmFileName)
This function saves the
idx
th image on the
page specified in the last call to pdfGetImages
as a PGM (portable
graymap) file. It returns 1 if successful, 0 if there was an error.
This function works for images (monochrome or color); it will fail on image masks.
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");
}
}