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
Labels
Merge Requests
7
Merge Requests
7
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Jérome Perrin
erp5
Commits
f48eeb6f
Commit
f48eeb6f
authored
Feb 05, 2015
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDF: use cache conversion to cache PDF content information
parent
5875c450
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
12 deletions
+8
-12
product/ERP5/Document/PDFDocument.py
product/ERP5/Document/PDFDocument.py
+8
-12
No files found.
product/ERP5/Document/PDFDocument.py
View file @
f48eeb6f
...
...
@@ -27,6 +27,7 @@
##############################################################################
import
tempfile
,
os
,
pickle
import
json
import
zope.interface
from
AccessControl
import
ClassSecurityInfo
...
...
@@ -278,18 +279,19 @@ class PDFDocument(Image):
def
getContentInformation
(
self
):
"""Returns the information about the PDF document with pdfinfo.
"""
content_information_pseudo_format
=
'content_information_pseudo_format'
if
not
self
.
hasData
():
return
{}
try
:
return
self
.
_content_information
.
copy
()
except
AttributeError
:
pass
# XXX we reuse the conversion infrastructure for cache
if
self
.
hasConversion
(
format
=
content_information_pseudo_format
):
mime
,
data
=
self
.
getConversion
(
format
=
content_information_pseudo_format
)
return
json
.
loads
(
data
)
tmp
=
tempfile
.
NamedTemporaryFile
()
tmp
.
write
(
self
.
getData
())
tmp
.
seek
(
0
)
command_result
=
None
try
:
# First, we use pdfinfo to get standard metadata
command
=
[
'pdfinfo'
,
'-meta'
,
'-box'
,
tmp
.
name
]
try
:
...
...
@@ -341,16 +343,10 @@ class PDFDocument(Image):
finally
:
tmp
.
close
()
# Store cache as an instance of document. FIXME: we usually try to avoid this
# pattern and cache the result of methods using content md5 as a cache key.
self
.
_content_information
=
result
self
.
setConversion
(
json
.
dumps
(
result
),
format
=
content_information_pseudo_format
)
return
result
.
copy
()
def
_setFile
(
self
,
data
,
precondition
=
None
):
try
:
del
self
.
_content_information
except
(
AttributeError
,
KeyError
):
pass
# Use File._setFile because Image._setFile will guess image size & content
# type
File
.
_setFile
(
self
,
data
,
precondition
=
precondition
)
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