]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/pdftopbm.cc
disable font embedding hack introduced on 2002-12-09 to fix build with
[evince.git] / pdf / xpdf / pdftopbm.cc
1 //========================================================================
2 //
3 // pdftopbm.cc
4 //
5 // Copyright 1998-2002 Glyph & Cog, LLC
6 //
7 //========================================================================
8
9 #include <aconf.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <stddef.h>
13 #include <string.h>
14 #include "parseargs.h"
15 #include "GString.h"
16 #include "gmem.h"
17 #include "GlobalParams.h"
18 #include "Object.h"
19 #include "Stream.h"
20 #include "Array.h"
21 #include "Dict.h"
22 #include "XRef.h"
23 #include "Catalog.h"
24 #include "Page.h"
25 #include "PDFDoc.h"
26 #include "PBMOutputDev.h"
27 #include "Error.h"
28 #include "config.h"
29
30 static int firstPage = 1;
31 static int lastPage = 0;
32 static int resolution = 150;
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;
39
40 static ArgDesc argDesc[] = {
41   {"-f",      argInt,      &firstPage,     0,
42    "first page to print"},
43   {"-l",      argInt,      &lastPage,      0,
44    "last page to print"},
45   {"-r",      argInt,      &resolution,    0,
46    "resolution, in DPI (default is 150)"},
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"},
65   {NULL}
66 };
67
68 int main(int argc, char *argv[]) {
69   PDFDoc *doc;
70   GString *fileName;
71   char *pbmRoot;
72   GString *ownerPW, *userPW;
73   PBMOutputDev *pbmOut;
74   GBool ok;
75
76   // parse args
77   ok = parseArgs(argDesc, &argc, argv);
78   if (!ok || argc != 3 || printVersion || printHelp) {
79     fprintf(stderr, "pdftopbm version %s\n", xpdfVersion);
80     fprintf(stderr, "%s\n", xpdfCopyright);
81     if (!printVersion) {
82       printUsage("pdftopbm", "<PDF-file> <PBM-root>", argDesc);
83     }
84     exit(1);
85   }
86   fileName = new GString(argv[1]);
87   pbmRoot = argv[2];
88
89   // read config file
90   globalParams = new GlobalParams(cfgFileName);
91   if (quiet) {
92     globalParams->setErrQuiet(quiet);
93   }
94
95   // open PDF file
96   if (ownerPassword[0]) {
97     ownerPW = new GString(ownerPassword);
98   } else {
99     ownerPW = NULL;
100   }
101   if (userPassword[0]) {
102     userPW = new GString(userPassword);
103   } else {
104     userPW = NULL;
105   }
106   doc = new PDFDoc(fileName, ownerPW, userPW);
107   if (userPW) {
108     delete userPW;
109   }
110   if (ownerPW) {
111     delete ownerPW;
112   }
113   if (!doc->isOk()) {
114     goto err;
115   }
116
117   // get page range
118   if (firstPage < 1)
119     firstPage = 1;
120   if (lastPage < 1 || lastPage > doc->getNumPages())
121     lastPage = doc->getNumPages();
122
123   // write PBM files
124   pbmOut = PBMOutputDev::makePBMOutputDev(NULL, pbmRoot);
125   pbmOut->startDoc(doc->getXRef());
126   doc->displayPages(pbmOut, firstPage, lastPage, resolution, 0, gFalse);
127   PBMOutputDev::killPBMOutputDev(pbmOut);
128
129   // clean up
130  err:
131   delete doc;
132   delete globalParams;
133
134   // check for memory leaks
135   Object::memCheck(stderr);
136   gMemReport(stderr);
137
138   return 0;
139 }