From: Dave Burt Date: 2007-03-08T00:45:06+09:00 Subject: Re: using win32ole to print .txt, .pdf, .xps files justin.irigo@gmail.com wrote: > good afternoon to all. > > i am creating a simple script to automate the printing of pdf, txt, > and xps files. i'm using this exercise as my first step in learning > ruby. > > i am able to print doc, xls, and ppt files using code that i put > together from snippets i got off the net: > > require 'win32ole' > ... > app = WIN32OLE.new("word.application") > app.Documents.Open("/test.doc") > testfile = app.ActiveDocument > testfile.PrintOut() > ... > testfile.Close() > app.Quit() > ... If you've written VBA code for MS Office programs, you may notice the similarity. You're using COM, an simple programming API that Office and some other programs expose. That is, all these methods (Documents, Open, ActiveDocument, PrintOut, Close, Quit) are being sent to Word to process. If you want to do more advanced stuff, the place you would look for reference is in the documentation for VBA in Word. > i haven't been able to find code snippets (or adequate win32ole > documentation) for printing .txt files (through notepad), or pdf or > xps. > is this even possible? through win32ole or otherwise? You can open and print a text file in Word in the same way you deal with a Word document. As far as I know, Adobe Reader doesn't have a COM interface. You could use a macro-type solution such as AutoIt3 (which provides a COM interface which can be used to interact with many Windows applications). I'm not sure about XPS. Try Word's help to see if you can deal with it like a Word document. Otherwise, if you're brave, there's a paper here describing the Vista .NET API, which you may be able to use via Ruby's DL library, or just a .NET program rather than Ruby: http://www.microsoft.com/whdc/xps/xps-read.mspx Cheers, Dave