#include "config.h" #include #include #include #include #include #include "parseargs.h" #include "goo/GooString.h" #include "PDFDoc.h" static int firstPage = 0; static int lastPage = 0; static GBool printVersion = gFalse; static GBool printHelp = gFalse; static const ArgDesc argDesc[] = { {"-f", argInt, &firstPage, 0, "first page to extract"}, {"-l", argInt, &lastPage, 0, "last page to extract"}, {"-v", argFlag, &printVersion, 0, "print copyright and version info"}, {"-h", argFlag, &printHelp, 0, "print usage information"}, {"-help", argFlag, &printHelp, 0, "print usage information"}, {"--help", argFlag, &printHelp, 0, "print usage information"}, {"-?", argFlag, &printHelp, 0, "print usage information"}, {NULL} }; bool ExtractPages(const char * srcFileName, const char *destFileName) { char pathName[1024]; GooString *gfileName = new GooString(srcFileName); PDFDoc *doc = new PDFDoc(gfileName, NULL, NULL, NULL); if (firstPage == 0 && lastPage == 0) { firstPage = 1; lastPage = doc->getNumPages(); } if (lastPage == 0) lastPage = firstPage; if (firstPage == 0) firstPage = 1; for (int pageNo = firstPage; pageNo <= lastPage; pageNo++) { sprintf(pathName, destFileName, pageNo); if (!doc->ExtractPage(pathName, pageNo)) return false; } return true; } int main(int argc, char *argv[]) { Object info; GBool ok; int exitCode; exitCode = 99; // parse args ok = parseArgs(argDesc, &argc, argv); if (!ok || argc != 3 || printVersion || printHelp) { fprintf(stderr, "pdfextract version %s\n", PACKAGE_VERSION); fprintf(stderr, "%s\n", popplerCopyright); fprintf(stderr, "%s\n", xpdfCopyright); if (!printVersion) { printUsage("pdfextract", " ", argDesc); } if (printVersion || printHelp) exitCode = 0; goto err0; } ExtractPages(argv[1], argv[2]); err0: return exitCode; }