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[]) {
69 ok = parseArgs(argDesc, &argc, argv);
70 if (!ok || argc < 2 || argc > 3 || printHelp) {
71 fprintf(stderr, "pdftops version %s\n", xpdfVersion);
72 fprintf(stderr, "%s\n", xpdfCopyright);
73 printUsage("pdftops", "<PDF-file> [<PS-file>]", argDesc);
76 if (doForm && psOutLevel1) {
77 fprintf(stderr, "Error: forms are only available with Level 2 output.\n");
80 fileName = new GString(argv[1]);
86 initParams(xpdfConfigFile);
90 doc = new PDFDoc(bxpdfopen(fileName), fileName);
95 // check for print permission
96 if (!doc->okToPrint()) {
97 error(-1, "Printing this document is not allowed.");
101 // construct PostScript file name
103 psFileName = new GString(argv[2]);
105 p = fileName->getCString() + fileName->getLength() - 4;
106 if (!strcmp(p, ".pdf") || !strcmp(p, ".PDF"))
107 psFileName = new GString(fileName->getCString(),
108 fileName->getLength() - 4);
110 psFileName = fileName->copy();
111 psFileName->append(".ps");
117 if (lastPage < 1 || lastPage > doc->getNumPages())
118 lastPage = doc->getNumPages();
120 lastPage = firstPage;
122 // write PostScript file
123 psOut = new PSOutputDev(psFileName->getCString(), doc->getCatalog(),
124 firstPage, lastPage, !noEmbedFonts, doForm);
126 doc->displayPages(psOut, firstPage, lastPage, 72, 0);
136 // check for memory leaks
137 Object::memCheck(stderr);