Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Masamichi Hosoda
poppler
Commits
b1564167
Commit
b1564167
authored
Sep 17, 2010
by
srinivas adicherla
Committed by
Carlos Garcia Campos
Sep 17, 2010
Browse files
Add a method to get the PDF file identifier
parent
3b4a901a
Changes
2
Hide whitespace changes
Inline
Side-by-side
poppler/PDFDoc.cc
View file @
b1564167
...
...
@@ -71,6 +71,7 @@
#define headerSearchSize 1024 // read this many bytes at beginning of
// file to look for '%PDF'
#define pdfIdLength 32 // PDF Document IDs (PermanentId, UpdateId) length
//------------------------------------------------------------------------
// PDFDoc
...
...
@@ -462,6 +463,70 @@ GBool PDFDoc::isLinearized() {
return
lin
;
}
static
GBool
get_id
(
const
char
*
encodedid
,
GooString
*
id
)
{
char
pdfid
[
pdfIdLength
+
1
];
int
n
;
if
(
strlen
(
encodedid
)
!=
16
)
return
gFalse
;
n
=
sprintf
(
pdfid
,
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x"
,
encodedid
[
0
]
&
0xff
,
encodedid
[
1
]
&
0xff
,
encodedid
[
2
]
&
0xff
,
encodedid
[
3
]
&
0xff
,
encodedid
[
4
]
&
0xff
,
encodedid
[
5
]
&
0xff
,
encodedid
[
6
]
&
0xff
,
encodedid
[
7
]
&
0xff
,
encodedid
[
8
]
&
0xff
,
encodedid
[
9
]
&
0xff
,
encodedid
[
10
]
&
0xff
,
encodedid
[
11
]
&
0xff
,
encodedid
[
12
]
&
0xff
,
encodedid
[
13
]
&
0xff
,
encodedid
[
14
]
&
0xff
,
encodedid
[
15
]
&
0xff
);
if
(
n
!=
pdfIdLength
)
return
gFalse
;
id
->
Set
(
pdfid
,
pdfIdLength
);
return
gTrue
;
}
GBool
PDFDoc
::
getID
(
GooString
*
permanent_id
,
GooString
*
update_id
)
{
Object
obj
;
xref
->
getTrailerDict
()
->
dictLookup
(
"ID"
,
&
obj
);
if
(
obj
.
isArray
()
&&
obj
.
arrayGetLength
()
==
2
)
{
Object
obj2
;
if
(
permanent_id
)
{
if
(
obj
.
arrayGet
(
0
,
&
obj2
)
->
isString
())
{
if
(
!
get_id
(
obj2
.
getString
()
->
getCString
(),
permanent_id
))
{
obj2
.
free
();
return
gFalse
;
}
}
else
{
error
(
-
1
,
"Invalid permanent ID"
);
obj2
.
free
();
return
gFalse
;
}
obj2
.
free
();
}
if
(
update_id
)
{
if
(
obj
.
arrayGet
(
1
,
&
obj2
)
->
isString
())
{
if
(
!
get_id
(
obj2
.
getString
()
->
getCString
(),
update_id
))
{
obj2
.
free
();
return
gFalse
;
}
}
else
{
error
(
-
1
,
"Invalid update ID"
);
obj2
.
free
();
return
gFalse
;
}
obj2
.
free
();
}
obj
.
free
();
return
gTrue
;
}
obj
.
free
();
return
gFalse
;
}
int
PDFDoc
::
saveAs
(
GooString
*
name
,
PDFWriteMode
mode
)
{
FILE
*
f
;
OutStream
*
outStr
;
...
...
poppler/PDFDoc.h
View file @
b1564167
...
...
@@ -206,6 +206,9 @@ public:
int
getPDFMajorVersion
()
{
return
pdfMajorVersion
;
}
int
getPDFMinorVersion
()
{
return
pdfMinorVersion
;
}
//Return the PDF ID in the trailer dictionary (if any).
GBool
getID
(
GooString
*
permanent_id
,
GooString
*
update_id
);
// Save this file with another name.
int
saveAs
(
GooString
*
name
,
PDFWriteMode
mode
=
writeStandard
);
// Save this file in the given output stream.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment