[python-win32] AVDoc and PDDoc/How to force late binding

Simon Dahlbacka simon.dahlbacka at gmail.com
Mon Sep 25 16:56:13 CEST 2006


EnsureModule forces *early* binding


On 9/25/06, Michael S <msherman77 at yahoo.com> wrote:
>
> I am trying to force late binding, since obviously early binding does not
> discover the methods that I am trying to call.
> I ran the makepy -i from within PythonWin, to get those two lines I need
> to paste in into my script.
> from win32com.client import gencache
> gencache.EnsureModule .......
>
> However when I run the script, I get an com_error saying that dynamic.pycouldn't find a certain method?
> I thought that EnsureModule should force late binding.
>
>
>
> ----- Original Message ----
> From: Michael S <msherman77 at yahoo.com>
> To: Justin Ezequiel <justin.mailinglists at gmail.com>;
> python-win32 at python.org
> Sent: Sunday, September 24, 2006 10:44:57 PM
> Subject: Re: [python-win32] AVDoc and PDDoc
>
> Thanks a lot Justin. I tried running your code, for some reason it just
> hangs. I wonder why.
>
> ----- Original Message ----
> From: Justin Ezequiel <justin.mailinglists at gmail.com>
> To: python-win32 at python.org
> Sent: Sunday, September 24, 2006 9:52:18 PM
> Subject: Re: [python-win32] AVDoc and PDDoc
>
>
> > 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)
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
>
>
> _______________________________________________
> Python-win32 mailing list
> Python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20060925/1965a01a/attachment.htm 


More information about the Python-win32 mailing list