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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tristan Cavelier
erp5
Commits
c0e132ce
Commit
c0e132ce
authored
8 years ago
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDFDocument: add portal transforms conversions
parent
8217bffe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
product/ERP5/Document/PDFDocument.py
product/ERP5/Document/PDFDocument.py
+20
-2
No files found.
product/ERP5/Document/PDFDocument.py
View file @
c0e132ce
...
...
@@ -118,6 +118,7 @@ class PDFDocument(Image):
"""
Implementation of conversion for PDF files
"""
format
=
str
(
format
).
lower
()
if
format
==
'html'
:
try
:
return
self
.
getConversion
(
format
=
format
)
...
...
@@ -134,7 +135,7 @@ class PDFDocument(Image):
data
=
self
.
_convertToText
()
self
.
setConversion
(
data
,
mime
=
mime
,
format
=
'txt'
)
return
(
mime
,
data
)
elif
format
in
(
'djvu'
,
'DJVU'
)
:
elif
format
==
'djvu'
:
try
:
return
self
.
getConversion
(
format
=
'djvu'
)
except
KeyError
:
...
...
@@ -145,13 +146,30 @@ class PDFDocument(Image):
elif
format
in
(
''
,
None
,)
or
format
==
'pdf'
:
# return original content
return
self
.
getContentType
(),
self
.
getData
()
el
se
:
el
if
format
in
(
'png'
,
'jpg'
,
'jpeg'
,
'tif'
,
'tiff'
,
'gif'
,
'bmp'
,
'ico'
,
'svg'
,
'ppm'
,
'pcx'
)
:
if
kw
.
get
(
'frame'
,
None
)
is
None
:
# when converting to image from PDF we care for first page only
# this will make sure that only first page is used and not whole content of
# PDF file read & converted which is a performance issue
kw
[
'frame'
]
=
0
return
Image
.
_convert
(
self
,
format
,
**
kw
)
elif
"/"
in
format
:
data
=
self
.
getPortalObject
().
portal_transforms
.
convertToData
(
format
,
str
(
self
.
getData
()
or
""
),
context
=
self
,
mimetype
=
self
.
getContentType
())
if
data
is
None
:
raise
ConversionError
(
'PDFDocument conversion error. '
'portal_transforms failed to convert to %r: %r'
%
(
format
,
self
))
return
format
,
data
else
:
portal
=
self
.
getPortalObject
()
mimetype
=
portal
.
mimetypes_registry
.
lookupExtension
(
"a."
+
format
)
if
mimetype
is
None
:
raise
ConversionError
(
'PDFDocument conversion error. '
'mimetypes_registry failed to find mimetype of extension %r: %r'
%
(
format
,
self
))
data
=
portal
.
portal_transforms
.
convertToData
(
mimetype
,
str
(
self
.
getData
()
or
""
),
context
=
self
,
mimetype
=
self
.
getContentType
())
if
data
is
None
:
raise
ConversionError
(
'PDFDocument conversion error. '
'portal_transforms failed to convert to %r (%s): %r'
%
(
format
,
mimetype
,
self
))
return
mimetype
,
data
security
.
declareProtected
(
Permissions
.
ModifyPortalContent
,
'populateContent'
)
def
populateContent
(
self
):
...
...
This diff is collapsed.
Click to expand it.
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