Commit 84d27d37 authored by Bartek Górny's avatar Bartek Górny

html representation functions (for web display)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9417 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f8e085aa
......@@ -376,6 +376,30 @@ class OOoDocument(DMSFile):
except AttributeError:
pass
def getHtmlRepresentation(self):
'''
get simplified html version to display
'''
# XXX use caching method
# we have to figure out which html format to use
tgts=[x[1] for x in self.getTargetFormatItemList() if x[1].startswith('html')]
if len(tgts)==0:
return 'no html representation available'
fmt=tgts[0]
fmt,data=self.getTargetFile(fmt)
cs=cStringIO.StringIO()
cs.write(self._unpackData(data))
z=zipfile.ZipFile(cs)
h='could not extract anything'
for f in z.infolist():
fn=f.filename
if fn.endswith('html'):
h=z.read(fn)
break
z.close()
cs.close()
return h
security.declareProtected(Permissions.View,'getTargetFile')
def getTargetFile(self,format,REQUEST=None):
"""
......
......@@ -83,6 +83,22 @@ class PdfDocument(DMSFile):
SearchableText=getSearchableText
def getHtmlRepresentation(self):
'''
get simplified html version to display
'''
# XXX use caching method
if not hasattr(self,'data'):
return 'no data'
tmp=tempfile.NamedTemporaryFile()
tmp.write(self._unpackData(self.data))
tmp.seek(0)
cmd='pdftohtml -enc UTF-8 -stdout -noframes -i %s' % tmp.name
r=os.popen(cmd)
h=r.read()
tmp.close()
r.close()
return h
# vim: syntax=python shiftwidth=2
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