#!/bin/env python
#Copyright ReportLab Europe Ltd. 2000-2004
#all rights reserved
__version__='''$Id: rl_com_wrapper.py 13212 2004-06-28 12:31:48Z rgbecker $ '''
__doc__="""experimental COM wrapper around ReportLab Enterprise API"""

import os
from rlextra.rml2pdf import rml2pdf
from reportlab.lib.utils import getStringIO

class ReportServer:
    _public_methods_ = [
        'double',
        'convertRmlToPdfInMemory',
        'convertRmlFileToPdfFile'
        ]
    _reg_progid_ = 'ReportLab.ReportServer'
    _reg_clsid_ = '{3A9DD703-93F6-4F95-9539-9B84E092936C}'

    def double(self, num):
        "Test method to check server works"
        return 2 * num
    
    def convertRmlToPdfInMemory(self, rmlText):
        rmlText = rmlText.encode('latin-1') # de-unicode it
        outfile = getStringIO()
        rml2pdf.go(rmlText, outputFileName=outfile)
        return outfile.getvalue().decode('latin-1')

    def convertRmlFileToPdfFile(self, rmlFileName, pdfFileName):
        txt = open(rmlFileName, 'r').read()
        doc = rml2pdf.go(txt, outputFileName = pdfFileName)
        return 1
    

if __name__=='__main__':
    import win32com.server.register
    win32com.server.register.UseCommandLine(ReportServer)
    