[python-win32] printing to PDF

Michael S msherman77 at yahoo.com
Mon Sep 25 18:58:00 CEST 2006


Now that I resolved the PDF generation issue, I have another question.
I am trying to print numerous word documents to pdf, using the "Acrobat PDFWriter". 
I do it in the following way:
for i in range(1, 16):
            doc_file = "ish0%.2d.doc" % i
            pdf_file = "ish0%.2d.pdf" % i
            self.word_app.Documents.Open(self.dir_name+doc_file)
            self.word_app.Documents(self.dir_name+doc_file).PrintOut(Background=True,\
                                                    OutputFileName=pdf_file, PrintToFile=True)
            time.sleep(2)
            self.word_app.Documents(self.dir_name+doc_file).Close()

My problem is that I am prompted for a file name for every pdf file being printed, even though I supply one. Is there a way to avoid the File Save dialog popping up?

Thanks in advance.

----- Original Message ----
From: Michael S <msherman77 at yahoo.com>
To: Simon Dahlbacka <simon.dahlbacka at gmail.com>; python-win32 at python.org
Sent: Monday, September 25, 2006 11:54:05 AM
Subject: Re: [python-win32] How to force late binding/Solved

Thanks for you help.
The problem apparentely was in the parenthesis. I dropped the parenthesis from GetPDDoc and things started to work!


----- Original Message ----
From: Simon Dahlbacka <simon.dahlbacka at gmail.com>
To: Michael S <msherman77 at yahoo.com>
Sent: Monday, September 25, 2006 11:10:16 AM
Subject: Re: [python-win32] AVDoc and PDDoc/How to force late binding

Early bound code is case sensitive, so have you checked that you've got your casings correct?

 On 9/25/06, Michael S <msherman77 at yahoo.com> wrote:    You are right. I made a mistake, it forces early binding.
However neither late nor early can discover the AcroExch.AVdoc method I need and VB does it with no problem. 

By the way I can force early or late binding on the Excel.Application, but for some reason not on Acrobat classes.  

 ----- Original Message ----
From: Simon Dahlbacka < simon.dahlbacka at gmail.com>
To: Michael S <msherman77 at yahoo.com>
Cc: Justin Ezequiel < justin.mailinglists at gmail.com>; python-win32 at python.org
Sent: Monday, September 25, 2006 10:56:13 AM 
Subject: Re: [python-win32] AVDoc and PDDoc/How to force late binding

 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.py couldn'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 


 











_______________________________________________
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/e0cf2506/attachment.html 


More information about the Python-win32 mailing list