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

Discussion in 'Ruby' started by justin.irigo@gmail.com, Mar 7, 2007.

  1. Guest

    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.
     
    , Mar 7, 2007
    #1
    1. Advertising

  2. Dave Burt Guest

    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
     
    Dave Burt, Mar 7, 2007
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Davor
    Replies:
    4
    Views:
    477
    Davor
    Jun 14, 2006
  2. keto
    Replies:
    0
    Views:
    1,001
  3. Replies:
    3
    Views:
    842
    Jayakrishnan
    May 14, 2008
Loading...

Share This Page