RSS category feeds

RSS site feeds

More related

Thanks to...

Home arrow Script Collection arrow Microsoft Office arrow A MS Office to Postscript Converter
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:
i
mport pythoncom
print pythoncom.CreateGuid()
 
usage:
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 -> http://www.goermezer.de
"""
 
def word(wordfile, psfile, printer):
    pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)
    myWord = win32com.client.DispatchEx('Word.Application')
    myWord.Application.ActivePrinter = printer
    myDoc = myWord.Documents.Open(wordfile, False, False, False)
    myDoc.Saved=1
    myWord.Application.NormalTemplate.Saved = 1
    myWord.PrintOut(True, False, 0, psfile)
    while myWord.BackgroundPrintingStatus > 0:
        time.sleep(0.1)
    myDoc.Close()
    myWord.Quit()
    del myDoc
    del myWord
    pythoncom.CoUninitialize()
 
def excel(excelfile, psfile, printer):
    pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)
    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)
    Excel.Close()
    myExcel.Quit()
    del myExcel
    del Excel
    pythoncom.CoUninitialize()
 
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 )
    pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)
    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)
    myPpt.Close()
    #myPowerpoint.Quit()
    del myPpt
    #del myPowerpoint
    pythoncom.CoUninitialize()
 
Last Updated ( Friday, 24 February 2006 )
 
< Prev   Next >

Feedback

Comments

  • I tried this for outlook 2007 and it doesn't work, but python doesn't have an er... More...
  • I never understood why people don't include the import statements at the top of ... More...
  • Thanks friend! ;-) Work really apprecciated from italy! More...
  • y am I not being allowed to view more on catia scripts. More...
  • eval('item.%s' % attribute) should be written as getattr(item, attribute) More...

Login Form






Lost Password?
No account yet? Register

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.