1 //========================================================================
5 // Copyright 1996 Derek B. Noonburg
7 //========================================================================
13 #include "parseargs.h"
24 #include "PSOutputDev.h"
29 static int firstPage = 1;
30 static int lastPage = 0;
31 static GBool noEmbedFonts = gFalse;
32 static GBool doForm = gFalse;
33 static char userPassword[33] = "";
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 {"-paperw", argInt, &paperWidth, 0,
43 "paper width, in points"},
44 {"-paperh", argInt, &paperHeight, 0,
45 "paper height, in points"},
46 {"-level1", argFlag, &psOutLevel1, 0,
47 "generate Level 1 PostScript"},
48 {"-level1sep", argFlag, &psOutLevel1Sep, 0,
49 "generate Level 1 separable PostScript"},
50 {"-eps", argFlag, &psOutEPS, 0,
51 "generate Encapsulated PostScript (EPS)"},
53 {"-opi", argFlag, &psOutOPI, 0,
54 "generate OPI comments"},
56 {"-noemb", argFlag, &noEmbedFonts, 0,
57 "don't embed Type 1 fonts"},
58 {"-form", argFlag, &doForm, 0,
59 "generate a PostScript form"},
60 {"-upw", argString, userPassword, sizeof(userPassword),
61 "user password (for encrypted files)"},
62 {"-q", argFlag, &errQuiet, 0,
63 "don't print any messages or errors"},
64 {"-v", argFlag, &printVersion, 0,
65 "print copyright and version info"},
66 {"-h", argFlag, &printHelp, 0,
67 "print usage information"},
68 {"-help", argFlag, &printHelp, 0,
69 "print usage information"},
73 int main(int argc, char *argv[]) {
83 ok = parseArgs(argDesc, &argc, argv);
84 if (!ok || argc < 2 || argc > 3 || printVersion || printHelp) {
85 fprintf(stderr, "pdftops version %s\n", xpdfVersion);
86 fprintf(stderr, "%s\n", xpdfCopyright);
88 printUsage("pdftops", "<PDF-file> [<PS-file>]", argDesc);
92 if (psOutLevel1 && psOutLevel1Sep) {
93 fprintf(stderr, "Error: use -level1 or -level1sep, not both.\n");
96 if (doForm && (psOutLevel1 || psOutLevel1Sep)) {
97 fprintf(stderr, "Error: forms are only available with Level 2 output.\n");
100 fileName = new GString(argv[1]);
106 initParams(xpdfConfigFile);
110 if (userPassword[0]) {
111 userPW = new GString(userPassword);
115 doc = new PDFDoc(fileName, userPW);
123 // check for print permission
124 if (!doc->okToPrint()) {
125 error(-1, "Printing this document is not allowed.");
129 // construct PostScript file name
131 psFileName = new GString(argv[2]);
133 p = fileName->getCString() + fileName->getLength() - 4;
134 if (!strcmp(p, ".pdf") || !strcmp(p, ".PDF"))
135 psFileName = new GString(fileName->getCString(),
136 fileName->getLength() - 4);
138 psFileName = fileName->copy();
139 psFileName->append(psOutEPS ? ".eps" : ".ps");
145 if (lastPage < 1 || lastPage > doc->getNumPages())
146 lastPage = doc->getNumPages();
148 lastPage = firstPage;
150 // check for multi-page EPS
151 if (psOutEPS && firstPage != lastPage) {
152 error(-1, "EPS files can only contain one page.");
156 // write PostScript file
157 psOut = new PSOutputDev(psFileName->getCString(), doc->getCatalog(),
158 firstPage, lastPage, !noEmbedFonts, doForm);
160 doc->displayPages(psOut, firstPage, lastPage, 72, 0, gFalse);
170 // check for memory leaks
171 Object::memCheck(stderr);