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 GBool printCommands = gFalse;
34 static GBool printHelp = gFalse;
36 static ArgDesc argDesc[] = {
37 {"-f", argInt, &firstPage, 0,
38 "first page to print"},
39 {"-l", argInt, &lastPage, 0,
40 "last page to print"},
41 {"-paperw", argInt, &paperWidth, 0,
42 "paper width, in points"},
43 {"-paperh", argInt, &paperHeight, 0,
44 "paper height, in points"},
45 {"-level1", argFlag, &psOutLevel1, 0,
46 "generate Level 1 PostScript"},
47 {"-noemb", argFlag, &noEmbedFonts, 0,
48 "don't embed Type 1 fonts"},
49 {"-form", argFlag, &doForm, 0,
50 "generate a PostScript form"},
51 {"-q", argFlag, &errQuiet, 0,
52 "don't print any messages or errors"},
53 {"-h", argFlag, &printHelp, 0,
54 "print usage information"},
55 {"-help", argFlag, &printHelp, 0,
56 "print usage information"},
60 int main(int argc, char *argv[]) {
70 ok = parseArgs(argDesc, &argc, argv);
71 if (!ok || argc < 2 || argc > 3 || printHelp) {
72 fprintf(stderr, "pdftops version %s\n", xpdfVersion);
73 fprintf(stderr, "%s\n", xpdfCopyright);
74 printUsage("pdftops", "<PDF-file> [<PS-file>]", argDesc);
77 if (doForm && psOutLevel1) {
78 fprintf(stderr, "Error: forms are only available with Level 2 output.\n");
81 fileName = new GString(argv[1]);
87 initParams(xpdfConfigFile);
91 doc = new PDFDoc(new FileStream (fileOpen (fileName)), fileName);
96 // check for print permission
97 if (!doc->okToPrint()) {
98 error(-1, "Printing this document is not allowed.");
102 // construct PostScript file name
104 psFileName = new GString(argv[2]);
106 p = fileName->getCString() + fileName->getLength() - 4;
107 if (!strcmp(p, ".pdf") || !strcmp(p, ".PDF"))
108 psFileName = new GString(fileName->getCString(),
109 fileName->getLength() - 4);
111 psFileName = fileName->copy();
112 psFileName->append(".ps");
118 if (lastPage < 1 || lastPage > doc->getNumPages())
119 lastPage = doc->getNumPages();
121 lastPage = firstPage;
123 // write PostScript file
124 psOut = new PSOutputDev(psFileName->getCString(), doc->getCatalog(),
125 firstPage, lastPage, !noEmbedFonts, doForm);
127 doc->displayPages(psOut, firstPage, lastPage, 72, 0);
137 // check for memory leaks
138 Object::memCheck(stderr);