1 //========================================================================
5 // Copyright 1998 Derek B. Noonburg
7 //========================================================================
13 #include "parseargs.h"
28 static void printInfoString(Dict *infoDict, char *key, char *fmt);
29 static void printInfoDate(Dict *infoDict, char *key, char *fmt);
31 static char userPassword[33] = "";
32 static GBool printVersion = gFalse;
33 static GBool printHelp = gFalse;
35 static ArgDesc argDesc[] = {
36 {"-upw", argString, userPassword, sizeof(userPassword),
37 "user password (for encrypted files)"},
38 {"-v", argFlag, &printVersion, 0,
39 "print copyright and version info"},
40 {"-h", argFlag, &printHelp, 0,
41 "print usage information"},
42 {"-help", argFlag, &printHelp, 0,
43 "print usage information"},
47 int main(int argc, char *argv[]) {
55 ok = parseArgs(argDesc, &argc, argv);
56 if (!ok || argc != 2 || printVersion || printHelp) {
57 fprintf(stderr, "pdfinfo version %s\n", xpdfVersion);
58 fprintf(stderr, "%s\n", xpdfCopyright);
60 printUsage("pdfinfo", "<PDF-file>", argDesc);
64 fileName = new GString(argv[1]);
70 initParams(xpdfConfigFile);
74 if (userPassword[0]) {
75 userPW = new GString(userPassword);
79 doc = new PDFDoc(fileName, userPW);
88 doc->getDocInfo(&info);
90 printInfoString(info.getDict(), "Title", "Title: %s\n");
91 printInfoString(info.getDict(), "Subject", "Subject: %s\n");
92 printInfoString(info.getDict(), "Keywords", "Keywords: %s\n");
93 printInfoString(info.getDict(), "Author", "Author: %s\n");
94 printInfoString(info.getDict(), "Creator", "Creator: %s\n");
95 printInfoString(info.getDict(), "Producer", "Producer: %s\n");
96 printInfoDate(info.getDict(), "CreationDate", "CreationDate: %s\n");
97 printInfoDate(info.getDict(), "ModDate", "ModDate: %s\n");
102 printf("Pages: %d\n", doc->getNumPages());
104 // print encryption info
105 printf("Encrypted: ");
106 if (doc->isEncrypted()) {
107 printf("yes (print:%s copy:%s change:%s addNotes:%s)\n",
108 doc->okToPrint() ? "yes" : "no",
109 doc->okToCopy() ? "yes" : "no",
110 doc->okToChange() ? "yes" : "no",
111 doc->okToAddNotes() ? "yes" : "no");
116 // print linearization info
117 printf("Linearized: %s\n", doc->isLinearized() ? "yes" : "no");
123 // check for memory leaks
124 Object::memCheck(stderr);
130 static void printInfoString(Dict *infoDict, char *key, char *fmt) {
135 if (infoDict->lookup(key, &obj)->isString()) {
136 s1 = obj.getString();
137 if ((s1->getChar(0) & 0xff) == 0xfe &&
138 (s1->getChar(1) & 0xff) == 0xff) {
140 for (i = 2; i < obj.getString()->getLength(); i += 2) {
141 if (s1->getChar(i) == '\0') {
142 s2->append(s1->getChar(i+1));
145 s2 = new GString("<unicode>");
149 printf(fmt, s2->getCString());
152 printf(fmt, s1->getCString());
158 static void printInfoDate(Dict *infoDict, char *key, char *fmt) {
162 if (infoDict->lookup(key, &obj)->isString()) {
163 s = obj.getString()->getCString();
164 if (s[0] == 'D' && s[1] == ':') {