Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
mat2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tails
mat2
Commits
7ec1eff9
Commit
7ec1eff9
authored
6 years ago
by
Julien (jvoisin) Voisin
Browse files
Options
Downloads
Patches
Plain Diff
Improve the way we parse/display pdf metadata
parent
0239ab3b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/pdf.py
+11
-0
11 additions, 0 deletions
src/pdf.py
tests/test_libmat2.py
+4
-0
4 additions, 0 deletions
tests/test_libmat2.py
with
15 additions
and
0 deletions
src/pdf.py
+
11
−
0
View file @
7ec1eff9
...
...
@@ -3,6 +3,7 @@
"""
import
os
import
re
import
logging
import
tempfile
import
io
...
...
@@ -76,6 +77,13 @@ class PDFParser(abstract.AbstractParser):
return
True
def
__parse_metadata_field
(
self
,
data
:
str
)
->
dict
:
metadata
=
{}
for
(
_
,
key
,
value
)
in
re
.
findall
(
r
"
<(xmp|pdfx|pdf|xmpMM):(.+)>(.+)</\1:\2>
"
,
data
,
re
.
I
):
metadata
[
key
]
=
value
return
metadata
def
get_meta
(
self
):
"""
Return a dict with all the meta of the file
"""
...
...
@@ -84,4 +92,7 @@ class PDFParser(abstract.AbstractParser):
for
key
in
self
.
meta_list
:
if
document
.
get_property
(
key
):
metadata
[
key
]
=
document
.
get_property
(
key
)
if
'
metadata
'
in
metadata
:
parsed_meta
=
self
.
__parse_metadata_field
(
metadata
[
'
metadata
'
])
return
{
**
metadata
,
**
parsed_meta
}
return
metadata
This diff is collapsed.
Click to expand it.
tests/test_libmat2.py
+
4
−
0
View file @
7ec1eff9
...
...
@@ -23,6 +23,10 @@ class TestGetMeta(unittest.TestCase):
meta
=
p
.
get_meta
()
self
.
assertEqual
(
meta
[
'
producer
'
],
'
pdfTeX-1.40.14
'
)
self
.
assertEqual
(
meta
[
'
creator
'
],
"'
Certified by IEEE PDFeXpress at 03/19/2016 2:56:07 AM
'"
)
self
.
assertEqual
(
meta
[
'
DocumentID
'
],
"
uuid:4a1a79c8-404e-4d38-9580-5bc081036e61
"
)
self
.
assertEqual
(
meta
[
'
PTEX.Fullbanner
'
],
"
This is pdfTeX, Version
"
\
"
3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) kpathsea
"
\
"
version 6.1.1
"
)
def
test_png
(
self
):
p
=
images
.
PNGParser
(
'
./tests/data/dirty.png
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment