1 //========================================================================
5 // Copyright 1998-2002 Glyph & Cog, LLC
7 //========================================================================
14 #include "parseargs.h"
17 #include "GlobalParams.h"
26 #include "ImageOutputDev.h"
30 static int firstPage = 1;
31 static int lastPage = 0;
32 static GBool dumpJPEG = gFalse;
33 static char ownerPassword[33] = "";
34 static char userPassword[33] = "";
35 static GBool quiet = gFalse;
36 static char cfgFileName[256] = "";
37 static GBool printVersion = gFalse;
38 static GBool printHelp = gFalse;
40 static ArgDesc argDesc[] = {
41 {"-f", argInt, &firstPage, 0,
42 "first page to convert"},
43 {"-l", argInt, &lastPage, 0,
44 "last page to convert"},
45 {"-j", argFlag, &dumpJPEG, 0,
46 "write JPEG images as JPEG files"},
47 {"-opw", argString, ownerPassword, sizeof(ownerPassword),
48 "owner password (for encrypted files)"},
49 {"-upw", argString, userPassword, sizeof(userPassword),
50 "user password (for encrypted files)"},
51 {"-q", argFlag, &quiet, 0,
52 "don't print any messages or errors"},
53 {"-cfg", argString, cfgFileName, sizeof(cfgFileName),
54 "configuration file to use in place of .xpdfrc"},
55 {"-v", argFlag, &printVersion, 0,
56 "print copyright and version info"},
57 {"-h", argFlag, &printHelp, 0,
58 "print usage information"},
59 {"-help", argFlag, &printHelp, 0,
60 "print usage information"},
61 {"--help", argFlag, &printHelp, 0,
62 "print usage information"},
63 {"-?", argFlag, &printHelp, 0,
64 "print usage information"},
68 int main(int argc, char *argv[]) {
72 GString *ownerPW, *userPW;
73 ImageOutputDev *imgOut;
77 ok = parseArgs(argDesc, &argc, argv);
78 if (!ok || argc != 3 || printVersion || printHelp) {
79 fprintf(stderr, "pdfimages version %s\n", xpdfVersion);
80 fprintf(stderr, "%s\n", xpdfCopyright);
82 printUsage("pdfimages", "<PDF-file> <image-root>", argDesc);
86 fileName = new GString(argv[1]);
90 globalParams = new GlobalParams(cfgFileName);
92 globalParams->setErrQuiet(quiet);
96 if (ownerPassword[0]) {
97 ownerPW = new GString(ownerPassword);
101 if (userPassword[0]) {
102 userPW = new GString(userPassword);
106 doc = new PDFDoc(fileName, ownerPW, userPW);
117 // check for copy permission
118 if (!doc->okToCopy()) {
119 error(-1, "Copying of images from this document is not allowed.");
126 if (lastPage < 1 || lastPage > doc->getNumPages())
127 lastPage = doc->getNumPages();
130 imgOut = new ImageOutputDev(imgRoot, dumpJPEG);
132 doc->displayPages(imgOut, firstPage, lastPage, 72, 0, gFalse);
140 // check for memory leaks
141 Object::memCheck(stderr);