Commit 7dbabca8 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Added conversion to DJVU

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42893 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e1adaf3e
...@@ -87,6 +87,14 @@ class PDFDocument(Image): ...@@ -87,6 +87,14 @@ class PDFDocument(Image):
data = self._convertToText() data = self._convertToText()
self.setConversion(data, mime=mime, format='txt') self.setConversion(data, mime=mime, format='txt')
return (mime, data) return (mime, data)
elif format in ('djvu', 'DJVU'):
try:
return self.getConversion(format='djvu')
except KeyError:
mime = 'image/vnd.djvu'
data = self._convertToDJVU()
self.setConversion(data, mime=mime, format='djvu')
return (mime, data)
elif format is None: elif format is None:
return self.getContentType(), self.getData() return self.getContentType(), self.getData()
else: else:
...@@ -197,6 +205,31 @@ class PDFDocument(Image): ...@@ -197,6 +205,31 @@ class PDFDocument(Image):
'href="asEntireHTML') 'href="asEntireHTML')
return h return h
security.declarePrivate('_convertToDJVU')
def _convertToDJVU(self):
"""
Convert the PDF text content to DJVU with pdf2djvu
"""
if not self.hasData():
return ''
tmp = tempfile.NamedTemporaryFile()
tmp.write(self.getData())
tmp.seek(0)
command_result = None
try:
command = ['pdf2djvu', tmp.name]
try:
command_result = Popen(command, stdout=PIPE).communicate()[0]
except OSError, e:
if e.errno == errno.ENOENT:
raise ConversionError('pdf2djvu was not found')
raise
finally:
tmp.close()
return command_result
security.declareProtected(Permissions.AccessContentsInformation, 'getContentInformation') security.declareProtected(Permissions.AccessContentsInformation, 'getContentInformation')
def getContentInformation(self): def getContentInformation(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