1 //========================================================================
5 // Copyright 2003 Glyph & Cog, LLC
7 //========================================================================
11 #include "parseargs.h"
14 #include "GlobalParams.h"
17 #include "SplashBitmap.h"
19 #include "SplashOutputDev.h"
20 #include "xpdfconfig.h"
22 static int firstPage = 1;
23 static int lastPage = 0;
24 static int resolution = 150;
25 static GBool mono = gFalse;
26 static GBool gray = gFalse;
27 static char enableT1libStr[16] = "";
28 static char enableFreeTypeStr[16] = "";
29 static char antialiasStr[16] = "";
30 static char ownerPassword[33] = "";
31 static char userPassword[33] = "";
32 static GBool quiet = gFalse;
33 static char cfgFileName[256] = "";
34 static GBool printVersion = gFalse;
35 static GBool printHelp = gFalse;
37 static ArgDesc argDesc[] = {
38 {"-f", argInt, &firstPage, 0,
39 "first page to print"},
40 {"-l", argInt, &lastPage, 0,
41 "last page to print"},
42 {"-r", argInt, &resolution, 0,
43 "resolution, in DPI (default is 150)"},
44 {"-mono", argFlag, &mono, 0,
45 "generate a monochrome PBM file"},
46 {"-gray", argFlag, &gray, 0,
47 "generate a grayscale PGM file"},
49 {"-t1lib", argString, enableT1libStr, sizeof(enableT1libStr),
50 "enable t1lib font rasterizer: yes, no"},
52 #if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
53 {"-freetype", argString, enableFreeTypeStr, sizeof(enableFreeTypeStr),
54 "enable FreeType font rasterizer: yes, no"},
56 {"-aa", argString, antialiasStr, sizeof(antialiasStr),
57 "enable font anti-aliasing: yes, no"},
58 {"-opw", argString, ownerPassword, sizeof(ownerPassword),
59 "owner password (for encrypted files)"},
60 {"-upw", argString, userPassword, sizeof(userPassword),
61 "user password (for encrypted files)"},
62 {"-q", argFlag, &quiet, 0,
63 "don't print any messages or errors"},
64 {"-cfg", argString, cfgFileName, sizeof(cfgFileName),
65 "configuration file to use in place of .xpdfrc"},
66 {"-v", argFlag, &printVersion, 0,
67 "print copyright and version info"},
68 {"-h", argFlag, &printHelp, 0,
69 "print usage information"},
70 {"-help", argFlag, &printHelp, 0,
71 "print usage information"},
72 {"--help", argFlag, &printHelp, 0,
73 "print usage information"},
74 {"-?", argFlag, &printHelp, 0,
75 "print usage information"},
79 int main(int argc, char *argv[]) {
84 GString *ownerPW, *userPW;
85 SplashColor paperColor;
86 SplashOutputDev *splashOut;
94 ok = parseArgs(argDesc, &argc, argv);
98 if (!ok || argc != 3 || printVersion || printHelp) {
99 fprintf(stderr, "pdftoppm version %s\n", xpdfVersion);
100 fprintf(stderr, "%s\n", xpdfCopyright);
102 printUsage("pdftoppm", "<PDF-file> <PPM-root>", argDesc);
106 fileName = new GString(argv[1]);
110 globalParams = new GlobalParams(cfgFileName);
111 globalParams->setupBaseFonts(NULL);
112 if (enableT1libStr[0]) {
113 if (!globalParams->setEnableT1lib(enableT1libStr)) {
114 fprintf(stderr, "Bad '-t1lib' value on command line\n");
117 if (enableFreeTypeStr[0]) {
118 if (!globalParams->setEnableFreeType(enableFreeTypeStr)) {
119 fprintf(stderr, "Bad '-freetype' value on command line\n");
122 if (antialiasStr[0]) {
123 if (!globalParams->setAntialias(antialiasStr)) {
124 fprintf(stderr, "Bad '-aa' value on command line\n");
128 globalParams->setErrQuiet(quiet);
132 if (ownerPassword[0]) {
133 ownerPW = new GString(ownerPassword);
137 if (userPassword[0]) {
138 userPW = new GString(userPassword);
142 doc = new PDFDoc(fileName, ownerPW, userPW);
157 if (lastPage < 1 || lastPage > doc->getNumPages())
158 lastPage = doc->getNumPages();
161 paperColor.rgb8 = splashMakeRGB8(255, 255, 255);
162 splashOut = new SplashOutputDev(mono ? splashModeMono1 :
163 gray ? splashModeMono8 :
166 splashOut->startDoc(doc->getXRef());
167 for (pg = firstPage; pg <= lastPage; ++pg) {
168 doc->displayPage(splashOut, pg, resolution, resolution, 0, gTrue, gFalse);
169 sprintf(ppmFile, "%.*s-%06d.%s",
170 (int)sizeof(ppmFile) - 32, ppmRoot, pg,
171 mono ? "pbm" : gray ? "pgm" : "ppm");
172 splashOut->getBitmap()->writePNMFile(ppmFile);
184 // check for memory leaks
185 Object::memCheck(stderr);