using win32ole to print .txt, .pdf, .xps files

J

justin.irigo

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()
....


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?
if it is, can anyone provide me with the necessary details as to how?
if it is not possible, any suggestions for an alternative method?

thank you very much in advance.
 
D

Dave Burt

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top