]> www.fi.muni.cz Git - evince.git/blob - pdf/xpdf/pdfinfo.cc
Painful merge.
[evince.git] / pdf / xpdf / pdfinfo.cc
1 //========================================================================
2 //
3 // pdfinfo.cc
4 //
5 // Copyright 1998 Derek B. Noonburg
6 //
7 //========================================================================
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <stddef.h>
12 #include <string.h>
13 #include "parseargs.h"
14 #include "GString.h"
15 #include "gmem.h"
16 #include "Object.h"
17 #include "Stream.h"
18 #include "Array.h"
19 #include "Dict.h"
20 #include "XRef.h"
21 #include "Catalog.h"
22 #include "Page.h"
23 #include "PDFDoc.h"
24 #include "Params.h"
25 #include "Error.h"
26 #include "config.h"
27
28 GBool printCommands = gFalse;
29 static GBool printHelp = gFalse;
30
31 static ArgDesc argDesc[] = {
32   {"-h",      argFlag,     &printHelp,     0,
33    "print usage information"},
34   {"-help",   argFlag,     &printHelp,     0,
35    "print usage information"},
36   {NULL}
37 };
38
39 int main(int argc, char *argv[]) {
40   PDFDoc *doc;
41   GString *fileName;
42   Object info, obj;
43   char *s;
44   GBool ok;
45
46   // parse args
47   ok = parseArgs(argDesc, &argc, argv);
48   if (!ok || argc != 2 || printHelp) {
49     fprintf(stderr, "pdfinfo version %s\n", xpdfVersion);
50     fprintf(stderr, "%s\n", xpdfCopyright);
51     printUsage("pdfinfo", "<PDF-file>", argDesc);
52     exit(1);
53   }
54   fileName = new GString(argv[1]);
55
56   // init error file
57   errorInit();
58
59   // read config file
60   initParams(xpdfConfigFile);
61
62   // open PDF file
63   xref = NULL;
64   doc = new PDFDoc(fileName);
65   if (!doc->isOk())
66     exit(1);
67
68   // print doc info
69   doc->getDocInfo(&info);
70   if (info.isDict()) {
71     if (info.dictLookup("Title", &obj)->isString())
72       printf("Title:        %s\n", obj.getString()->getCString());
73     obj.free();
74     if (info.dictLookup("Subject", &obj)->isString())
75       printf("Subject:      %s\n", obj.getString()->getCString());
76     obj.free();
77     if (info.dictLookup("Keywords", &obj)->isString())
78       printf("Keywords:     %s\n", obj.getString()->getCString());
79     obj.free();
80     if (info.dictLookup("Author", &obj)->isString())
81       printf("Author:       %s\n", obj.getString()->getCString());
82     obj.free();
83     if (info.dictLookup("Creator", &obj)->isString())
84       printf("Creator:      %s\n", obj.getString()->getCString());
85     obj.free();
86     if (info.dictLookup("Producer", &obj)->isString())
87       printf("Producer:     %s\n", obj.getString()->getCString());
88     obj.free();
89     if (info.dictLookup("CreationDate", &obj)->isString()) {
90       s = obj.getString()->getCString();
91       if (s[0] == 'D' && s[1] == ':')
92         s += 2;
93       printf("CreationDate: %s\n", s);
94     }
95     obj.free();
96     if (info.dictLookup("ModDate", &obj)->isString()) {
97       s = obj.getString()->getCString();
98       if (s[0] == 'D' && s[1] == ':')
99         s += 2;
100       printf("ModDate:      %s\n", s);
101     }
102     obj.free();
103   }
104   info.free();
105
106   // print page count
107   printf("Pages:        %d\n", doc->getNumPages());
108
109   // print encryption info
110   printf("Encrypted:    ");
111   if (doc->isEncrypted()) {
112     printf("yes (print:%s copy:%s)\n",
113            doc->okToPrint() ? "yes" : "no",
114            doc->okToCopy() ? "yes" : "no");
115   } else {
116     printf("no\n");
117   }
118
119   // clean up
120   delete doc;
121   freeParams();
122
123   // check for memory leaks
124   Object::memCheck(stderr);
125   gMemReport(stderr);
126
127   return 0;
128 }