]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/pdfimages.cc
Lots of cvsignores
[evince.git] / pdf / xpdf / pdfimages.cc
1 //========================================================================
2 //
3 // pdfimages.cc
4 //
5 // Copyright 1998 Derek B. Noonburg
6 //
7 //========================================================================
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <stddef.h>
12 #include <string.h>
13 #include "parseargs.h"
14 #include "GString.h"
15 #include "gmem.h"
16 #include "Object.h"
17 #include "Stream.h"
18 #include "Array.h"
19 #include "Dict.h"
20 #include "XRef.h"
21 #include "Catalog.h"
22 #include "Page.h"
23 #include "PDFDoc.h"
24 #include "ImageOutputDev.h"
25 #include "Params.h"
26 #include "Error.h"
27 #include "config.h"
28
29 static int firstPage = 1;
30 static int lastPage = 0;
31 static GBool dumpJPEG = gFalse;
32 GBool printCommands = gFalse;
33 static GBool printHelp = gFalse;
34
35 static ArgDesc argDesc[] = {
36   {"-f",      argInt,      &firstPage,     0,
37    "first page to convert"},
38   {"-l",      argInt,      &lastPage,      0,
39    "last page to convert"},
40   {"-j",      argFlag,     &dumpJPEG,      0,
41    "write JPEG images as JPEG files"},
42   {"-h",      argFlag,     &printHelp,     0,
43    "print usage information"},
44   {"-help",   argFlag,     &printHelp,     0,
45    "print usage information"},
46   {NULL}
47 };
48
49 int main(int argc, char *argv[]) {
50   PDFDoc *doc;
51   GString *fileName;
52   char *imgRoot;
53   ImageOutputDev *imgOut;
54   GBool ok;
55
56   // parse args
57   ok = parseArgs(argDesc, &argc, argv);
58   if (!ok || argc != 3 || printHelp) {
59     fprintf(stderr, "pdfimages version %s\n", xpdfVersion);
60     fprintf(stderr, "%s\n", xpdfCopyright);
61     printUsage("pdfimages", "<PDF-file> <image-root>", argDesc);
62     exit(1);
63   }
64   fileName = new GString(argv[1]);
65   imgRoot = argv[2];
66
67   // init error file
68   errorInit();
69
70   // read config file
71   initParams(xpdfConfigFile);
72
73   // open PDF file
74   xref = NULL;
75   doc = new PDFDoc(fileName);
76   if (!doc->isOk())
77     exit(1);
78
79   // get page range
80   if (firstPage < 1)
81     firstPage = 1;
82   if (lastPage < 1 || lastPage > doc->getNumPages())
83     lastPage = doc->getNumPages();
84
85   // write image files
86   imgOut = new ImageOutputDev(imgRoot, dumpJPEG);
87   if (imgOut->isOk())
88     doc->displayPages(imgOut, firstPage, lastPage, 72, 0);
89   delete imgOut;
90
91   // clean up
92   delete doc;
93   freeParams();
94
95   // check for memory leaks
96   Object::memCheck(errFile);
97   gMemReport(errFile);
98
99   return 0;
100 }