# Printing plain text directly without dialogues

**URL:** <https://www.ruby-forum.com/t/printing-plain-text-directly-without-dialogues/170992>\
**Category:** wxRuby\
**Created:** [June 25, 2009, 12:42am UTC](https://www.ruby-forum.com/t/printing-plain-text-directly-without-dialogues/170992 "2009-06-25T00:42:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arno\_Dirlam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Arno\_Dirlam](https://www.ruby-forum.com/u/Arno_Dirlam)\
**Post date:** [June 25, 2009, 12:42am UTC](https://www.ruby-forum.com/t/printing-plain-text-directly-without-dialogues/170992/1 "2009-06-25T00:42:14Z")

</div>

Hi,

I recently searched for ways printing plain (but formatted) text  
directly  
and without major requirements using ruby and stumbled upon wxruby,  
which  
seems to be a nice framework that would meet my requirements quite well.

However, since I use a local Ruby on Rails server, I would like to be  
able  
to select a printer as well as print the text without using dialogues,  
i.e.  
only using the wxruby classes to interact with the user via http  
responses.

I had a look at the “printing.rb” example in the wxruby directory and  
modified it to just print formatted text, as I want it, but it’s still  
having dialogues. My try without dialogues was the following  
non-functional  
code:

begin  
require ‘rubygems’  
rescue LoadError  
end  
require ‘wx’

dc = Wx::PrinterDC.new("", “”, “”) // deprecated way to initiate  
PrinterDC  
on default printer

dc.set\_background(Wx::WHITE\_BRUSH)  
dc.clear()  
dc.set\_font(Wx::Font.new(12, Wx::DEFAULT, Wx::NORMAL, Wx::NORMAL, false,  
“Control”))

dc.set\_background\_mode(Wx::TRANSPARENT)

dc.draw\_text( “D”, 0, 0)

Since I could not figure out the whole concept of class relations in  
wxruby,  
yet, I would be very glad if someone could help me and give examples for  
selecting a printer and printing in wxruby without the use of dialogues.

As far as I understand, I need to create a PrintData object. This  
PrintData  
object could be handed to the device context PrinterDC containing my  
formatted text that got into there using draw\_text methods. I don’t yet  
understand where this PrintData comes from, if not from a dialogue  
(using  
Wx::get\_app.print\_data).

Thanks a lot for any hints!

Don Darone

---

<div class="post-metadata">

**Author:** ![Arno\_Dirlam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f19dbf/32.png) [@Arno\_Dirlam](https://www.ruby-forum.com/u/Arno_Dirlam)\
**Post date:** [October 6, 2009, 4:25pm UTC](https://www.ruby-forum.com/t/printing-plain-text-directly-without-dialogues/170992/2 "2009-10-06T16:25:07Z")

</div>

Have you tried cups? ([cups.rubyforge.org](http://cups.rubyforge.org)).

UNIX only, unfortunately, but it’s a bit easier to get up & running with  
it.

m0wf
