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