1 //========================================================================
5 // Copyright 2003 Glyph & Cog, LLC
7 //========================================================================
10 #include <poppler-config.h>
12 #include "parseargs.h"
14 #include "goo/GooString.h"
15 #include "GlobalParams.h"
18 #include "splash/SplashBitmap.h"
19 #include "splash/Splash.h"
20 #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 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 GooString
*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 GooString(argv
[1]);
110 globalParams
= new GlobalParams(cfgFileName
);
111 if (enableT1libStr
[0]) {
112 if (!globalParams
->setEnableT1lib(enableT1libStr
)) {
113 fprintf(stderr
, "Bad '-t1lib' value on command line\n");
116 if (enableFreeTypeStr
[0]) {
117 if (!globalParams
->setEnableFreeType(enableFreeTypeStr
)) {
118 fprintf(stderr
, "Bad '-freetype' value on command line\n");
121 if (antialiasStr
[0]) {
122 if (!globalParams
->setAntialias(antialiasStr
)) {
123 fprintf(stderr
, "Bad '-aa' value on command line\n");
127 globalParams
->setErrQuiet(quiet
);
131 if (ownerPassword
[0]) {
132 ownerPW
= new GooString(ownerPassword
);
136 if (userPassword
[0]) {
137 userPW
= new GooString(userPassword
);
141 doc
= new PDFDoc(fileName
, ownerPW
, userPW
);
156 if (lastPage
< 1 || lastPage
> doc
->getNumPages())
157 lastPage
= doc
->getNumPages();
163 splashOut
= new SplashOutputDev(mono
? splashModeMono1
:
164 gray
? splashModeMono8
:
167 splashOut
->startDoc(doc
->getXRef());
168 for (pg
= firstPage
; pg
<= lastPage
; ++pg
) {
169 doc
->displayPage(splashOut
, pg
, resolution
, resolution
, 0, gTrue
, gFalse
, gFalse
);
170 sprintf(ppmFile
, "%.*s-%06d.%s",
171 (int)sizeof(ppmFile
) - 32, ppmRoot
, pg
,
172 mono
? "pbm" : gray
? "pgm" : "ppm");
173 splashOut
->getBitmap()->writePNMFile(ppmFile
);
185 // check for memory leaks
186 Object::memCheck(stderr
);