1 //========================================================================
5 // Copyright 2003 Glyph & Cog, LLC
7 //========================================================================
11 #include "parseargs.h"
14 #include "GlobalParams.h"
17 #include "SplashBitmap.h"
19 #include "SplashOutputDev.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 vectorAntialiasStr
[16] = "";
31 static char ownerPassword
[33] = "";
32 static char userPassword
[33] = "";
33 static GBool quiet
= gFalse
;
34 static char cfgFileName
[256] = "";
35 static GBool printVersion
= gFalse
;
36 static GBool printHelp
= gFalse
;
38 static ArgDesc argDesc
[] = {
39 {"-f", argInt
, &firstPage
, 0,
40 "first page to print"},
41 {"-l", argInt
, &lastPage
, 0,
42 "last page to print"},
43 {"-r", argInt
, &resolution
, 0,
44 "resolution, in DPI (default is 150)"},
45 {"-mono", argFlag
, &mono
, 0,
46 "generate a monochrome PBM file"},
47 {"-gray", argFlag
, &gray
, 0,
48 "generate a grayscale PGM file"},
50 {"-t1lib", argString
, enableT1libStr
, sizeof(enableT1libStr
),
51 "enable t1lib font rasterizer: yes, no"},
53 #if HAVE_FREETYPE_FREETYPE_H | HAVE_FREETYPE_H
54 {"-freetype", argString
, enableFreeTypeStr
, sizeof(enableFreeTypeStr
),
55 "enable FreeType font rasterizer: yes, no"},
57 {"-aa", argString
, antialiasStr
, sizeof(antialiasStr
),
58 "enable font anti-aliasing: yes, no"},
59 {"-aaVector", argString
, vectorAntialiasStr
, sizeof(vectorAntialiasStr
),
60 "enable vector anti-aliasing: yes, no"},
61 {"-opw", argString
, ownerPassword
, sizeof(ownerPassword
),
62 "owner password (for encrypted files)"},
63 {"-upw", argString
, userPassword
, sizeof(userPassword
),
64 "user password (for encrypted files)"},
65 {"-q", argFlag
, &quiet
, 0,
66 "don't print any messages or errors"},
67 {"-cfg", argString
, cfgFileName
, sizeof(cfgFileName
),
68 "configuration file to use in place of .xpdfrc"},
69 {"-v", argFlag
, &printVersion
, 0,
70 "print copyright and version info"},
71 {"-h", argFlag
, &printHelp
, 0,
72 "print usage information"},
73 {"-help", argFlag
, &printHelp
, 0,
74 "print usage information"},
75 {"--help", argFlag
, &printHelp
, 0,
76 "print usage information"},
77 {"-?", argFlag
, &printHelp
, 0,
78 "print usage information"},
82 int main(int argc
, char *argv
[]) {
87 GString
*ownerPW
, *userPW
;
88 SplashColor paperColor
;
89 SplashOutputDev
*splashOut
;
97 ok
= parseArgs(argDesc
, &argc
, argv
);
101 if (!ok
|| argc
!= 3 || printVersion
|| printHelp
) {
102 fprintf(stderr
, "pdftoppm version %s\n", xpdfVersion
);
103 fprintf(stderr
, "%s\n", xpdfCopyright
);
105 printUsage("pdftoppm", "<PDF-file> <PPM-root>", argDesc
);
109 fileName
= new GString(argv
[1]);
113 globalParams
= new GlobalParams(cfgFileName
);
114 globalParams
->setupBaseFonts(NULL
);
115 if (enableT1libStr
[0]) {
116 if (!globalParams
->setEnableT1lib(enableT1libStr
)) {
117 fprintf(stderr
, "Bad '-t1lib' value on command line\n");
120 if (enableFreeTypeStr
[0]) {
121 if (!globalParams
->setEnableFreeType(enableFreeTypeStr
)) {
122 fprintf(stderr
, "Bad '-freetype' value on command line\n");
125 if (antialiasStr
[0]) {
126 if (!globalParams
->setAntialias(antialiasStr
)) {
127 fprintf(stderr
, "Bad '-aa' value on command line\n");
130 if (vectorAntialiasStr
[0]) {
131 if (!globalParams
->setVectorAntialias(vectorAntialiasStr
)) {
132 fprintf(stderr
, "Bad '-aaVector' value on command line\n");
136 globalParams
->setErrQuiet(quiet
);
140 if (ownerPassword
[0]) {
141 ownerPW
= new GString(ownerPassword
);
145 if (userPassword
[0]) {
146 userPW
= new GString(userPassword
);
150 doc
= new PDFDoc(fileName
, ownerPW
, userPW
);
165 if (lastPage
< 1 || lastPage
> doc
->getNumPages())
166 lastPage
= doc
->getNumPages();
170 paperColor
[0] = 0xff;
171 splashOut
= new SplashOutputDev(splashModeMono1
, 1, gFalse
, paperColor
);
173 paperColor
[0] = 0xff;
174 splashOut
= new SplashOutputDev(splashModeMono8
, 1, gFalse
, paperColor
);
176 paperColor
[0] = paperColor
[1] = paperColor
[2] = 0xff;
177 splashOut
= new SplashOutputDev(splashModeRGB8
, 1, gFalse
, paperColor
);
179 splashOut
->startDoc(doc
->getXRef());
180 for (pg
= firstPage
; pg
<= lastPage
; ++pg
) {
181 doc
->displayPage(splashOut
, pg
, resolution
, resolution
, 0,
182 gFalse
, gTrue
, gFalse
);
183 sprintf(ppmFile
, "%.*s-%06d.%s",
184 (int)sizeof(ppmFile
) - 32, ppmRoot
, pg
,
185 mono
? "pbm" : gray
? "pgm" : "ppm");
186 splashOut
->getBitmap()->writePNMFile(ppmFile
);
198 // check for memory leaks
199 xObject::memCheck(stderr
);