Forum: Ruby Printing in Ruby

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Alexandru T. (Guest)
on 2006-02-18 20:22
It seems there is not a lot of information on this subject so I have a
few questions:

1. How can you do simple printing from Ruby? If you have a string how
can you print it? At the very least I would like to be able to select
the size and maybe the font from the printer's ROM. I know that you
could do this in the DOS days by sending a few control codes dirrectly
to the parallel port and then the text you wanted to print (this worked
for dot matrix printers where you had a manual which detailed all those
control codes). How would you do this in Ruby? Also, would it be
possible to do the same for modern inkjet or laser printers? Would it
also be possible to do this in a platform independent way? (I'm more
interested in Linux, but it would be great if the same code also worked
on Windows)

2. Would it be possible to do something like the above but for USB
printers? How?

3. How would you do more advanced printing? I know of ruby-cups... are
there other alternatives? How about Windows?

4. I have a program (it's actually a Rails application) that generates
PDFs using PDF::Writer. How would I be able to print the PDFs dirrectly
without having to save them or open them in a browser... I just want to
send them directly to the printer after they are generated. Ruby-cups
seems to have .printFile which will print an existing file but, as I
said, I don't want to save the file first. Can I just pipe the generated
file to some application? Are there more ellegant ways of doing this?
How about Windows?

I'm sorry for asking so many questions at once. If you could answer even
just one of them I would be very grateful. Also, if you have any links
about the subject or you know of other discussions on the topic that
would help as well.

Many thanks in advance.

Logan C. (Guest)
on 2006-02-18 20:36
(Received via mailing list)
On Feb 18, 2006, at 1:23 PM, Alexandru T. wrote:

> those
> 3. How would you do more advanced printing? I know of ruby-cups... are
> generated
> Many thanks in advance.
> Alex
> --
> Posted via

assuming cups or lpd is setup for pdfs you can just shell  out to lpr
$file_name. As far as windows goes I'm sure win32api or  win32ole can
get you where you need to be.
This topic is locked and can not be replied to.