odt_to_pdf.py 1.08 KB
Newer Older
1
from Products.PortalTransforms.interfaces import itransform
2
from zope.interface import implements
3 4 5 6 7 8 9
from oood_commandtransform import OOOdCommandTransform, OOoDocumentDataStream
from zLOG import LOG


class OdtToPdf:
  """Transforms ODT to PDF by using oood"""

10
  implements(itransform)
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

  __name__ = 'odt_to_pdf'
  inputs   = ('application/vnd.oasis.opendocument.text',)
  output = 'application/pdf'

  tranform_engine = OOOdCommandTransform.__module__

  def name(self):
    return self.__name__

  def __getattr__(self, attr):
    if attr == 'inputs':
      return self.config['inputs']
    if attr == 'output':
      return self.config['output']
    raise AttributeError(attr)

  def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs):
29
    data = str(orig)
30 31 32 33
    doc = OOOdCommandTransform(context, filename, data, self.inputs[0])
    doc.convert()
    pdf = doc.convertTo('pdf')
    if cache is not None:
Nicolas Delaby's avatar
Nicolas Delaby committed
34
      cache.setData(pdf)
35 36 37 38 39 40 41 42
      return cache
    else:
      stream = OOoDocumentDataStream()
      stream.setData(pdf)
      return stream

def register():
  return OdtToPdf()