Commit 6892d346 authored by Tristan Cavelier's avatar Tristan Cavelier

xxx transform improvements wip (PDFDocument)

parent 4e92e1e0
......@@ -142,16 +142,33 @@ class PDFDocument(Image):
data = self._convertToDJVU()
self.setConversion(data, mime=mime, format='djvu')
return (mime, data)
elif format in ('', None,) or format=='pdf':
elif format in ('', None,) or format.lower() == 'pdf':
# return original content
return self.getContentType(), self.getData()
else:
elif format.lower() 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)
return Image._convert(self, format.lower(), **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):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment