[python-win32] AVDoc and PDDoc

Justin Ezequiel justin.mailinglists at gmail.com
Mon Sep 25 03:52:18 CEST 2006


> From: Michael S <msherman77 at yahoo.com>
>
> I am trying to write a short Python script to create
> some PDFs.
> I create instances of App, AVDoc and PDDoc using the
> following syntax:
> app = Dispatch("AcroExch.App")
> doc = Dispatch("AcroExch.AVDoc")
> pd = Dispatch("AcroExch.PDDoc")
>
> However when I call pd = doc.GetPDDoc(), the Python
> interpreter
> complains about the member function not being found. I
> know for sure
> that it is there, since I can execute the code in VB
> no problem.
>

was experimenting with Acrobat months ago

import win32com.client.dynamic

NOSAVE = -1
PDSAVEFULL = 1

class Acrobat2pdfError(RuntimeError): pass

def Acrobat2pdf(src, dst):
    avdoc = win32com.client.dynamic.Dispatch("AcroExch.AVDoc")

    if not avdoc.Open(src, "doc2pdf"):
        raise Acrobat2pdfError("unable to open %s" % src)

    pddoc = avdoc.GetPDDoc()

    if not pddoc.Save(PDSAVEFULL, dst):
        raise Acrobat2pdfError("unable to save %s" % dst)

    if not pddoc.Close():
        raise Acrobat2pdfError("unable to close %s" % dst)

    del pddoc

    if not avdoc.Close(NOSAVE):
        raise Acrobat2pdfError("unable to close %s" % src)

    del avdoc

if __name__ == '__main__':
    import os
    src = r"C:\test\file1.doc"
    dst = r"C:\test\file2.pdf"
    Acrobat2pdf(src, dst)
    assert os.path.isfile(dst)


More information about the Python-win32 mailing list