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 {"-h", argFlag, &printHelp, 0,
52 "print usage information"},
53 {"-help", argFlag, &printHelp, 0,
54 "print usage information"},
58 int main(int argc, char *argv[]) {
67 ok = parseArgs(argDesc, &argc, argv);
68 if (!ok || argc < 2 || argc > 3 || printHelp) {
69 fprintf(stderr, "pdftops version %s\n", xpdfVersion);
70 fprintf(stderr, "%s\n", xpdfCopyright);
71 printUsage("pdftops", "<PDF-file> [<PS-file>]", argDesc);
74 if (doForm && psOutLevel1) {
75 fprintf(stderr, "Error: forms are only available with Level 2 output.\n");
78 fileName = new GString(argv[1]);
84 initParams(xpdfConfigFile);
88 doc = new PDFDoc(fileName);
92 // construct PostScript file name
94 psFileName = new GString(argv[2]);
96 p = fileName->getCString() + fileName->getLength() - 4;
97 if (!strcmp(p, ".pdf") || !strcmp(p, ".PDF"))
98 psFileName = new GString(fileName->getCString(),
99 fileName->getLength() - 4);
101 psFileName = fileName->copy();
102 psFileName->append(".ps");
108 if (lastPage < 1 || lastPage > doc->getNumPages())
109 lastPage = doc->getNumPages();
111 lastPage = firstPage;
113 // write PostScript file
114 if (doc->okToPrint()) {
115 psOut = new PSOutputDev(psFileName->getCString(), doc->getCatalog(),
116 firstPage, lastPage, !noEmbedFonts, doForm);
118 doc->displayPages(psOut, firstPage, lastPage, 72, 0);
127 // check for memory leaks
128 Object::memCheck(errFile);