# Printoperation

**URL:** <https://www.ruby-forum.com/t/printoperation/75771>\
**Category:** Ruby-Gnome 2\
**Created:** [November 13, 2006, 9:46am UTC](https://www.ruby-forum.com/t/printoperation/75771 "2006-11-13T09:46:19Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [November 13, 2006, 9:46am UTC](https://www.ruby-forum.com/t/printoperation/75771/1 "2006-11-13T09:46:19Z")

</div>

hi list,

i’m experimenting with printoperation, on a cvs version of Fri Nov 10  
11:47:07 2006.  
and i found a “[BUG] Segmentation fault”

p context.page\_setup.paper\_size.inspect  
in line 23 aborts the script.

i’m still experimenting with this stuff, all hints will be welcomed.

thanks

this is my script:  
$ cat printer2.rb  
require ‘gtk2’

Gtk.init

@w = Gtk::Window.new  
@w.signal\_connect(‘destroy’){Gtk.main\_quit}  
@w.set\_default\_size(300, 100)

pbutton=Gtk::Button.new  
pbutton.set\_image(Gtk::Image.new(Gtk::Stock::PRINT,Gtk::IconSize::LARGE\_TOOLBAR))  
pbutton.set\_label(“PrintTest”)  
pbutton.signal\_connect(“clicked”){|me|  
printo=Gtk::PrintOperation.new  
printo.set\_n\_pages(1).set\_show\_progress(true)  
printo.signal\_connect(‘draw-page’){|me,context,page\_number|  
me.set\_unit(Gtk::PaperSize::Unit::MM)  
height = context.height  
width = context.width  
p Gtk::PaperSize::Unit  
p me.unit  
print width,“x”,height,"\n"

# p context.page\_setup.paper\_size.inspect

```
    p context.page_setup.orientation.inspect
    cr = context.cairo_context

```

# cr.rectangle(0,0,width,20)

```
    cr.set_source_rgb(0, 0, 0)

```

# cr.fill

```
    layout = context.create_pango_layout

    desc = Pango::FontDescription.new("sans 10")
    layout.set_font_description(desc)

    layout.set_text(@editor.buffer.get_text)
    layout.set_width(width)

    layout_width, layout_height = layout.size
    text_height = layout_height / Pango::SCALE

    cr.show_pango_layout(layout)

```

}  
printo.signal\_connect(‘end-print’){|me,context|  
print “-=== printing ended\n”  
}  
printo.signal\_connect(‘status-changed’){|me|  
print “- status changed: “,me.status\_string,”\n”  
}

printr=printo.run(Gtk::PrintOperation::ACTION\_PRINT\_DIALOG,@w)  
case printr  
when Gtk::PrintOperation::RESULT\_ERROR  
print “error\n”  
when Gtk::PrintOperation::RESULT\_CANCEL  
print “cancelled\n”  
when Gtk::PrintOperation::RESULT\_APPLY  
print “applied\n”  
when Gtk::PrintOperation::RESULT\_IN\_PROGRESS  
print “in progress\n”  
else  
print “unknown result: “,printr.inspect,”\n”  
end

# printo.destroy

}

@editor=Gtk::TextView.new()  
@editor.set\_width\_request(200)

holder=Gtk::VBox.new()  
holder.pack\_start(@editor)  
holder.pack\_end(pbutton)  
@w.add(holder)  
@w.show\_all

Gtk.main

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [November 13, 2006, 3:42pm UTC](https://www.ruby-forum.com/t/printoperation/75771/2 "2006-11-13T15:42:59Z")

</div>

Hi,

Fixed. Thanks.

On Mon, 13 Nov 2006 10:44:28 +0200  
Dobai-Pataky B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> @w.set\_default\_size(300, 100)  
> width = context.width
> 
> ```
> text_height = layout_height / Pango::SCALE
> 
> ```
> 
> printr=printo.run(Gtk::PrintOperation::ACTION\_PRINT\_DIALOG,@w)  
> print “unknown result: “,printr.inspect,”\n”  
> holder=Gtk::VBox.new()  
> holder.pack\_start(@editor)  
> holder.pack\_end(pbutton)  
> @w.add(holder)  
> @w.show\_all
> 
> Gtk.main

* * *

Using Tomcat but need to do more? Need to support web services,  
security?  
Get stuff done quickly with pre-integrated technology to make your job  
easier  
Download IBM WebSphere Application Server v.1.0.1 based on Apache  
Geronimo  
[http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642](http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642)

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [November 13, 2006, 8:22pm UTC](https://www.ruby-forum.com/t/printoperation/75771/3 "2006-11-13T20:22:13Z")

</div>

* * *

Using Tomcat but need to do more? Need to support web services,  
security?  
Get stuff done quickly with pre-integrated technology to make your job  
easier  
Download IBM WebSphere Application Server v.1.0.1 based on Apache  
Geronimo  
[http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642](http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642)

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [November 15, 2006, 8:31am UTC](https://www.ruby-forum.com/t/printoperation/75771/4 "2006-11-15T08:31:07Z")

</div>

Hi,

2006/11/15, Dobai-Pataky Bálint [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> and i think here is another one:
> 
> layout.set\_text(layout.text+“\ncontext.page\_setup.paper\_height  
> = #{context.page\_setup.paper\_height}”)  
> gives  
> undefined method `paper\_height’ for #\<Gtk::PageSetup:0xb66ef0bc  
> ptr=0x83b4918\>
> 
> not according to  
> [http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3APageSetup#paper\_height](http://ruby-gnome2.sourceforge.jp/hiki.cgi?Gtk%3A%3APageSetup#paper_height)

The documentation is wrong. I fixed.  
Use #get\_paper\_height.

## Thanks,

kou

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [November 15, 2006, 10:15am UTC](https://www.ruby-forum.com/t/printoperation/75771/5 "2006-11-15T10:15:19Z")

</div>

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [November 15, 2006, 10:51am UTC](https://www.ruby-forum.com/t/printoperation/75771/6 "2006-11-15T10:51:32Z")

</div>

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [November 15, 2006, 1:49pm UTC](https://www.ruby-forum.com/t/printoperation/75771/7 "2006-11-15T13:49:47Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] printoperation” on Wed, 15 Nov 2006  
11:14:21 +0200,  
Dobai-Pataky Bálint [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> undefined method `run\_page\_setup\_dialog’ for #\<Gtk::PrintOperation:0xb66e71a0  
> ptr=0x834e000\>

run\_page\_setup\_dialog is a class method of  
Gtk::PrintOperation, not instance method.

## Thanks,

kou

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [November 15, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/printoperation/75771/8 "2006-11-15T14:13:53Z")

</div>

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [November 15, 2006, 8:15am UTC](https://www.ruby-forum.com/t/printoperation/75771/9 "2006-11-15T08:15:06Z")

</div>

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [November 16, 2006, 10:25am UTC](https://www.ruby-forum.com/t/printoperation/75771/10 "2006-11-16T10:25:08Z")

</div>

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_B](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/4da419/32.png) [@Dobai-Pataky\_B](https://www.ruby-forum.com/u/Dobai-Pataky_B)\
**Post date:** [November 16, 2006, 12:54am UTC](https://www.ruby-forum.com/t/printoperation/75771/11 "2006-11-16T00:54:16Z")

</div>

Hi,

Fixed. Try CVS again.

Also API reference was wrong. I fixed it, too.

require ‘gtk2’  
window = Gtk::Window.new  
page\_setup = Gtk::PageSetup.new  
setting = Gtk::PrintSettings.new  
p Gtk::PrintOperation.run\_page\_setup\_dialog(window, page\_setup, setting)

window, page\_setup, setting are omittable.  
So, you can write it as:

require ‘gtk2’  
p Gtk::PrintOperation.run\_page\_setup\_dialog

* * *

> ruby 1.8.5 (2006-08-25) [i686-linux]
> 
> Aborted

* * *

Take Surveys. Earn Cash. Influence the Future of IT  
Join [SourceForge.net](http://SourceForge.net)’s Techsay panel and you’ll get the chance to share  
your  
opinions on IT & business topics through brief surveys - and earn cash  
[http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV](http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV)
