Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Sebastian
erp5
Commits
57402c11
Commit
57402c11
authored
Feb 25, 2013
by
Sebastien Robin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use pyPdf instead of pdftk to extract non standard metadata from pdf
parent
50e1a93a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
20 deletions
+11
-20
product/ERP5/Document/PDFDocument.py
product/ERP5/Document/PDFDocument.py
+11
-20
No files found.
product/ERP5/Document/PDFDocument.py
View file @
57402c11
...
...
@@ -266,28 +266,19 @@ class PDFDocument(Image):
value
=
':'
.
join
(
item_list
[
1
:]).
strip
()
result
[
key
]
=
value
# Then we use p
dftk
to get extra metadata
# Then we use p
yPdf
to get extra metadata
try
:
command
=
[
'pdftk'
,
tmp
.
name
,
'dump_data'
,
'output'
]
command_result
=
Popen
(
command
,
stdout
=
PIPE
).
communicate
()[
0
]
except
OSError
,
e
:
# if pdftk not found, pass
if
e
.
errno
!=
errno
.
ENOENT
:
raise
from
pyPdf
import
PdfFileReader
except
ImportError
:
# if pyPdf not found, pass
pass
else
:
line_list
=
(
line
for
line
in
command_result
.
splitlines
())
while
True
:
try
:
line
=
line_list
.
next
()
except
StopIteration
:
break
if
line
.
startswith
(
'InfoKey'
):
key
=
line
[
len
(
'InfoKey: '
):]
line
=
line_list
.
next
()
assert
line
.
startswith
(
'InfoValue: '
),
\
"Wrong format returned by pdftk dump_data"
value
=
line
[
len
(
'InfoValue: '
):]
result
.
setdefault
(
key
,
value
)
pdf_file
=
PdfFileReader
(
tmp
)
for
info_key
,
info_value
in
pdf_file
.
getDocumentInfo
().
iteritems
():
info_key
=
info_key
.
lstrip
(
"/"
)
if
isinstance
(
info_value
,
unicode
):
info_value
=
info_value
.
encode
(
"utf-8"
)
result
.
setdefault
(
info_key
,
info_value
)
finally
:
tmp
.
close
()
...
...
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