2 Converts a pdf page to a jpeg.
4 Copyright (c) 2010 Matthias Kramm
5 Copyright (c) 1998-2009 Derek Noonburg
7 Swftools is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Swftools is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with swftools; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
23 #include "parseargs.h"
26 #include "GlobalParams.h"
29 #include "SplashBitmap.h"
31 #include "SplashOutputDev.h"
37 static int resolution = 150;
38 static int quality = 95;
39 static char ownerPassword[33] = "";
40 static char userPassword[33] = "";
41 static char cfgFileName[256] = "";
42 static GBool printVersion = gFalse;
43 static GBool printHelp = gFalse;
44 static char output[256] = "output.jpg";
46 static ArgDesc argDesc[] = {
47 {"-p", argInt, &page, 0,
48 "first page to print"},
49 {"-r", argInt, &resolution, 0,
50 "resolution, in DPI (default is 150)"},
51 {"-q", argInt, &quality, 0,
52 "jpeg conversion quality"},
53 {"-w", argInt, &width, 0,
54 "zoom to this width"},
55 {"-o", argString, &output, sizeof(output),
56 "resolution, in DPI (default is 150)"},
57 {"-opw", argString, ownerPassword, sizeof(ownerPassword),
58 "owner password (for encrypted files)"},
59 {"-upw", argString, userPassword, sizeof(userPassword),
60 "user password (for encrypted files)"},
61 {"-cfg", argString, cfgFileName, sizeof(cfgFileName),
62 "configuration file to use in place of .xpdfrc"},
63 {"-v", argFlag, &printVersion, 0,
64 "print copyright and version info"},
65 {"-h", argFlag, &printHelp, 0,
66 "print usage information"},
67 {"-help", argFlag, &printHelp, 0,
68 "print usage information"},
69 {"--help", argFlag, &printHelp, 0,
70 "print usage information"},
71 {"-?", argFlag, &printHelp, 0,
72 "print usage information"},
76 int main(int argc, char *argv[]) {
79 GString *ownerPW, *userPW;
80 SplashColor paperColor;
81 SplashOutputDev *splashOut;
89 ok = parseArgs(argDesc, &argc, argv);
91 if (!ok || argc != 2 || printVersion || printHelp) {
92 fprintf(stderr, "pdf2jpeg version %s\n", xpdfVersion);
93 fprintf(stderr, "%s\n", xpdfCopyright);
95 printUsage("pdf2jpeg", "<PDF-file> -o <jpegfile>", argDesc);
99 fileName = new GString(argv[1]);
102 globalParams = new GlobalParams(cfgFileName);
103 globalParams->setupBaseFonts(NULL);
106 if (ownerPassword[0]) {
107 ownerPW = new GString(ownerPassword);
111 if (userPassword[0]) {
112 userPW = new GString(userPassword);
116 doc = new PDFDoc(fileName, ownerPW, userPW);
128 paperColor[0] = paperColor[1] = paperColor[2] = 0xff;
129 splashOut = new SplashOutputDev(splashModeRGB8, 1, gFalse, paperColor);
131 splashOut->startDoc(doc->getXRef());
133 if(page>=1 && page<=doc->getNumPages()) {
134 double r = resolution;
136 int old_width = doc->getPageCropWidth(page);
137 r = 72.0*width/old_width;
139 doc->displayPage(splashOut, page, r, r, 0, gFalse, gTrue, gFalse);
140 SplashBitmap*bitmap = splashOut->getBitmap();
142 Guchar*rgb = bitmap->getDataPtr();
143 int width = bitmap->getWidth();
144 int height = bitmap->getHeight();
145 jpeg_save(rgb, width, height, quality, output);
158 // check for memory leaks
159 Object::memCheck(stderr);