[python-win32] Dispatch InternetExplorer.Application fails

Waldemar Osuch waldemar.osuch at gmail.com
Wed May 28 22:25:39 CEST 2008


>
> 2) use some python libraries (libxml2, libxslt) to transform the xml to
> html. That part works but now how to I make a pdf from the html file?
>
I would use lxml for the transformation and wx for printing.
The example below will prompt you with the dialog but
it should be possible to silence it somehow.
Instead of Acrobat Printer I would use PDFCreator.
It is free and one of the myriad options is to automatically save
without prompting for a file name.

For example:

8<------------------------------------------------------------------------------
import wx
from wx import html
import lxml.etree as ET


def get_reports():
    xmlfile = 'report.xml'
    xslfile = 'style.xsl'
    for i in range(3):
        transform = ET.XSLT(ET.parse(xslfile))
        result = transform(ET.parse(xmlfile))
        yield ET.tostring(result)


class MyFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None)
        self.prn = html.HtmlEasyPrinting()
        but = wx.Button(self, label='Go')
        self.Bind(wx.EVT_BUTTON, self.PrintReports)

    def PrintReports(self, evt):
        for rpt in get_reports():
            self.prn.PrintText(rpt)


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = MyFrame()
    frame.Show(True)
    app.MainLoop()


More information about the python-win32 mailing list