# Printing image problem

**URL:** <https://www.ruby-forum.com/t/printing-image-problem/146297>\
**Category:** Ruby-Gnome 2\
**Created:** [August 19, 2008, 9:39pm UTC](https://www.ruby-forum.com/t/printing-image-problem/146297 "2008-08-19T21:39:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [August 19, 2008, 9:39pm UTC](https://www.ruby-forum.com/t/printing-image-problem/146297/1 "2008-08-19T21:39:17Z")

</div>

hi,

i got a complex printing class, it pronts text,line,image objects.  
it generates a good preview, good pdf if print to file,  
but if printed to printer or to file type ps, printing of the page stops  
after an image is prnted. the image comes out, but the paper is white  
after it.

on the draw-page signal i run a cycle and draw each item.  
each page begins with  
cr=context.cairo\_context  
ends with cr.stroke

items are placed on cr,  
this is how the image is placed:  
cr.set\_source\_pixbuf(pixbuf.scale(width.to\_f, height.to\_f), x,y)  
cr.paint  
cr.stroke

if i comment out the row containing set\_surce, than printing the .ps  
file continues.

my question: is this not the right way to print images?

thanks  
balint

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [August 20, 2008, 9:16am UTC](https://www.ruby-forum.com/t/printing-image-problem/146297/2 "2008-08-20T09:16:33Z")

</div>

don’t bother,  
looks like i have systems where it works, and systems, where id does  
not.

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [August 20, 2008, 12:22pm UTC](https://www.ruby-forum.com/t/printing-image-problem/146297/3 "2008-08-20T12:22:31Z")

</div>

i managed to implemented a workaround, by changing the order of placing  
items on the page: images after all other items  
that way the .ps looks as the .pdf, thus printing is looks ok.

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [August 20, 2008, 10:23am UTC](https://www.ruby-forum.com/t/printing-image-problem/146297/4 "2008-08-20T10:23:59Z")

</div>

take back the last one.  
i come now with a working script, attached.  
i also attach the generated pdf and ps files.

the fist page will include the image, the second will not.  
there are some lines printed before the image,  
there is a text printed after the image.

place the script and the image in the same folder, change there, run  
from there.  
step1: print to file ps format  
step2: print to file pdf format  
step3: notice on the first page there is no other graphics than the  
image, while on the second page there is are lines.  
step4: notice the pdf having the text after the image, while the ps does  
not.

i think cairo\_context.set\_source\_pixbuf is doing this to me. can i  
replace it with something else?

thanks  
balint

---

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [September 6, 2008, 4:17pm UTC](https://www.ruby-forum.com/t/printing-image-problem/146297/5 "2008-09-06T16:17:30Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] printing image problem” on Wed, 20 Aug  
2008 11:09:16 +0300,  
Dobai-Pataky Bálint [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> step1: print to file ps format  
> step2: print to file pdf format  
> step3: notice on the first page there is no other graphics than the image,  
> while on the second page there is are lines.  
> step4: notice the pdf having the text after the image, while the ps does not.
> 
> i think cairo\_context.set\_source\_pixbuf is doing this to me. can i replace it  
> with something else?

You need to restore surface’s source.

before:

if page\_number == 0  
cr.set\_source\_pixbuf(Gtk::Image.new(“im.png”).pixbuf.scale(60,60),30,30)  
cr.paint  
end

after:

if page\_number == 0  
cr.save do  
cr.set\_source\_pixbuf(Gtk::Image.new(“im.png”).pixbuf.scale(60,60),30,30)  
cr.paint  
end  
end

## Thanks,

kou
