cybertools/docgen
2013-01-18 16:35:34 +01:00
..
testing document generation with images: embedding of image OK 2012-12-11 12:27:06 +01:00
__init__.py work in progress: new package docgen for document generation 2012-01-27 07:51:53 +01:00
base.py generate Word document by embedding content in .mht file 2012-08-07 18:56:13 +02:00
document.mht work in progress: use MHT files for generation of Word documents 2012-11-26 09:34:13 +01:00
mht.py fix boundary (add -- prefix) for MHT documents 2013-01-18 16:35:34 +01:00
README.txt document (.mht file) generation with images OK 2012-12-19 11:09:39 +01:00
tests.py work in progress: new package docgen for document generation 2012-01-27 07:51:53 +01:00
word.css generate Word document by embedding content in .mht file 2012-08-07 18:56:13 +02:00
word_body.pt generate Word document by embedding content in .mht file 2012-08-07 18:56:13 +02:00
word_macros.pt work in progress: new package docgen for document generation 2012-01-27 07:51:53 +01:00
word_page.pt allow definition of Section elements in report instead of standard page 2012-08-04 09:23:27 +02:00

================================================================
docgen - Document Generation from Result Sets and XML Structures
================================================================

  >>> from zope import component
  >>> from zope.publisher.browser import TestRequest

  >>> from cybertools.docgen.base import WordDocument
  >>> doc = WordDocument(None, TestRequest)


Working with MHT Files
======================

  >>> import os
  >>> basePath = os.path.join(os.path.dirname(__file__), 'testing')

  >>> path = os.path.join(basePath, 'test_doc.mht')
  >>> f = open(path, 'rt')
  >>> data = f.read()
  >>> f.close()

  >>> xbody = '''<div class="WordSection1">
  ... <v:shape id="Grafik_x0020_2" o:spid="_x0000_i1025" type="#_x0000_t75"
  ...     style="width:320pt;height:240pt;visibility:visible;mso-wrap-style:square">
  ...   <v:imagedata src="FB-Besprechungsprotokoll-Dateien/image002.jpg" o:title=""/>
  ... </v:shape>
  ... </div>
  ... '''

  >>> body = '''<div class="WordSection1">
  ... <img src="files/test_image.jpg" />
  ... </div>
  ... '''

  >>> from cybertools.docgen.mht import MHTFile
  >>> document = MHTFile(data, body)

  >>> imageRefs = document.htmlDoc.getImageRefs()
  >>> for path in imageRefs:
  ...     imagePath = os.path.join(basePath, os.path.basename(path))
  ...     f = open(imagePath, 'rt')
  ...     imageData = f.read()
  ...     f.close()
  ...     document.addImage(imageData, path)

  >>> document.insertBody()

  >>> output = document.asString()
  >>> len(data), len(output)
  (294996, 336140)

  >>> outPath = os.path.join(basePath, 'out_doc.mht')
  >>> #f = open(outPath, 'wt')
  >>> #f.write(document.asString())
  >>> #f.close()

  >>> #os.unlink(outPath)