Convert Word .doc to Acrobat .pdf files
Justin Ezequiel
justin.mailinglists at gmail.com
Thu Mar 23 22:17:21 EST 2006
## this creates a postscript file which you can then convert to PDF
## using Acrobat Distiller
##
## BTW, I spent an hour trying to get this working with
## win32com.client.Dispatch
## (the save file dialog still appeared)
## Then I remembered win32com.client.dynamic.Dispatch
##
## Can somebody please explain why this happened using
## win32com.client.Dispatch?
import win32com.client.dynamic
if __name__ == '__main__':
printer = "Adobe PDF on NE03:"
docpath = r"E:\Documents and Settings\justin\Desktop\test.doc"
pspath = r"E:\Documents and Settings\justin\Desktop\test.ps"
word = win32com.client.dynamic.Dispatch("Word.Application")
try:
document = word.Documents.Open(docpath, 0, -1)
try:
remember = word.ActivePrinter
word.ActivePrinter = printer
try:
document.PrintOut(Background=0, OutputFileName=pspath,
PrintToFile=-1)
finally:
word.ActivePrinter = remember
finally:
document.Close(0)
del document
finally:
word.Quit(0)
del word
More information about the Python-list
mailing list