RSS category feeds

RSS site feeds


A MS Office to Postscript Converter PDF Print E-mail

This Python module can be used to convert files from Microsoft Office to Postscript. Remember: To print out Postscript files from Microsoft Office you need a virtual Postscript printer.

Alternatively you can download this tool from here too.

import win32com.client, time, pythoncom
MSOffice2PS - Microsoft Office to Postscript Converter 1.1
Makes a Postscript file from Word-, Excel- or Powerpoint.
Now with mutex support for Powerpoint. Because Powerpoint can
only run as a single instance. Line 57 must have a unique GUID.
You can create a new GUID via:
mport pythoncom
print pythoncom.CreateGuid()
first: import msoffice2ps in the script, where it should be used
then call the convert-function. 
import msoffice2ps
msoffice2ps.word('wordfilename', 'psfilename', 'ps_printername')
msoffice2ps.excel('excelfilename', 'psfilename', 'ps_printername')
msoffice2ps.powerpoint('powerpointfilename', 'psfilename', 'ps_printername')
Dipl.-Ing. Mustafa Goermezer ->
def word(wordfile, psfile, printer):
    myWord = win32com.client.DispatchEx('Word.Application')
    myWord.Application.ActivePrinter = printer
    myDoc = myWord.Documents.Open(wordfile, False, False, False)
    myWord.Application.NormalTemplate.Saved = 1
    myWord.PrintOut(True, False, 0, psfile)
    while myWord.BackgroundPrintingStatus > 0:
    del myDoc
    del myWord
def excel(excelfile, psfile, printer):
    myExcel = win32com.client.DispatchEx('Excel.Application')
    myExcel.Application.AskToUpdateLinks = 0
    Excel = myExcel.Workbooks.Open(excelfile, 0, False, 2)
    Excel.Saved = 1
    Excel.PrintOut(1, 5000, 1, False, printer, True, False, psfile)
    del myExcel
    del Excel
def powerpoint(powerpointfile, psfile, printer):
    from win32event import CreateMutex
    from win32api import GetLastError
    from winerror import ERROR_ALREADY_EXISTS
    from sys import exit
    #the guid in the next line must be unique !!!
    handle = CreateMutex ( None, 1, '{8620EF5C-7ED7-4A46-834B-3C9220566F69}' )
    if GetLastError ( ) == ERROR_ALREADY_EXISTS:
        print 'Powerpoint conversion already working'
        exit ( 1 )
    myPowerpoint = win32com.client.DispatchEx('Powerpoint.Application')
    myPpt = myPowerpoint.Presentations.Open(powerpointfile, False, False, False)
    myPpt.PrintOptions.PrintInBackground = 0
    myPpt.PrintOptions.ActivePrinter = printer
    myPpt.Saved = 1
    myPpt.PrintOut(1, 5000, psfile, 0, False)
    del myPpt
    #del myPowerpoint
Last Updated ( Friday, 24 February 2006 )
< Prev   Next >




  • I have run your code on my own machine, but I just got the last paragraph of the... More...
  • Hello Gabriel, It seem that the linked site moved to (... More...
  • There is no script to download, could you provide the right link More...
  • Interesting but doesn't really help me. I do not see what the 'xxxxx' in the Ses... More...
  • You can see more python editor comparison: (http://sparkledg... More...

Login Form

Lost Password?

My prefered Python IDE

My prefered Python editor is Pyscripter from MMExperts. It is not only an editor. Pyscripter is a full Python IDE including (remote) debugging, a class browser, and all other nice helpers which a full featured IDE needs.

Do you have a script for me ?

Do you have an interesting Python script which does some really cool thing on Windows ? Please post them to this site. It`s very simple - simply copy&paste it to this form. No login is requiered.

Hint: For syntax highlighting and correct Python intendation place your code between html tags <pre> and </pre>.

My prefered web framework

My prefered web framework for developing web applications is Django. Django calls itself The web framework for perfectionists with deadlines. It is a really fast, scalable and (thanks Python) the sexiest web framework of the world.