[python-win32] Printing a Word file silently

Alexandre Lemière alexandre.lemiere at laposte.net
Tue Dec 23 19:13:21 EST 2003


Hi the list,

  I'd like to generate Postscript silently from Word.
  but word still show a dialog box for the filename.

  Here's the code I try :

from win32com.client import constants,Dispatch,DispatchEx
WORD = 'Word.Application.8'
Faux, Vrai = 0,1

class Word:
    def __init__(self):
        self.app = DispatchEx(WORD)
        #self.app.Visible = 1
    def ouvrir(self, doc):
        self.app.Documents.Open(FileName=doc)
    def imprimer(self):
        self.app.Application.ActivePrinter = "PostScript"
        self.app.Application.PrintOut(OutputFileName=r"c:\temp\testout.ps", PrintToFile=1, Append=Faux)
    def quitter(self):
        self.app.Documents(r"c:\temp\test.doc").Close(SaveChanges=Faux)
)

if __name__ == '__main__':
    word = Word()
    word.ouvrir(r"c:\temp\test.doc")
    word.imprimer()
    word.quitter()  


I've found an old post (On 22 April 2003) about this but the answer doesn't work
for me ;(

here's a code of a macro that works, if it can helps...
Sub Macro1()
    Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
        wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
        Collate:=True, Background:=True, PrintToFile:=True, PrintZoomColumn:=0, _
        PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0, _
        OutputFileName:="c:/temp/lulu.ps", Append:=False
    ActiveDocument.Close
End Sub

-- 
Best regards,
 Alexandre




More information about the Python-win32 mailing list