Hi,
i use your script with this vbs:

dim PythonUtils
Set PythonUtils = CreateObject("PythonDemo.Utilities")
call PythonUtils.add_watermark("d:\pippo.pdf","pluto_pluto","d:\pippooooo.pdf")

and it works well on win7 64Bit


May be reinstalling python, or win32com could be the right choice

Regards,
Matteo

Il 21/07/2011 19:05, dennis chou ha scritto:
Hello,

I recently upgraded to 32-bit windows 7.

For some reason, I am getting an automation error when i try to run my excel VBA script to call my Python COM server.

Here's the script for the python COM server. This is creating a COM server to watermark a PDF.

import pythoncom
class PythonUtilities:
    _public_methods_ = [ 'add_watermark' ]
    _reg_progid_ = "PythonDemo.Utilities"
    # NEVER copy the following ID
    # Use "print pythoncom.CreateGuid()" to make a new one.
    _reg_clsid_ = "{B7E3EE50-5E2A-4044-8241-4F76B1DAB894}"

def add_watermark(self, pdf_input_path, watermark_string, pdf_output_path):
        import StringIO
        from pyPdf import PdfFileReader, PdfFileWriter
        from reportlab.pdfgen import canvas

        output = PdfFileWriter()

        #create watermark
        packet = StringIO.StringIO()
        c = canvas.Canvas(packet)
        c.drawString(500,750,watermark_string)
        c.save()
        packet.seek(0)
        watermark = PdfFileReader(packet)

        input = PdfFileReader(file(pdf_input_path, "rb"))

        pdf_path_page_count = input.getNumPages()
        print pdf_path_page_count

        for page in range(pdf_path_page_count):
            print page
            current_page = input.getPage(page)
            current_page.mergePage(watermark.getPage(0))
            output.addPage(input.getPage(page))

        outputStream = file(pdf_output_path, "wb")
        output.write(outputStream)
        outputStream.close()

    # Add code so that when this script is run by
    # Python.exe, it self-registers.

if __name__=='__main__':
    print "Registering COM server..."
    import win32com.server.register
    win32com.server.register.UseCommandLine(PythonUtilities)





In Excel VBA, when i try to run

Set PythonUtils = CreateObject("PythonDemo.Utilities")



i get an automation error stating that the module cannot be found.

Looking around on the web, i see that Diego had a similar issue and he resolved it by properly installing Python. I believe Python is properly installed on my workstation so I don't think that is creating the issue.

Thanks,
dennis



_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32


Nessun virus nel messaggio.
Controllato da AVG - www.avg.com <http://www.avg.com>
Versione: 10.0.1390 / Database dei virus: 1518/3778 - Data di rilascio: 21/07/2011


_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to