# Gruff with PDF::Writer

**URL:** <https://www.ruby-forum.com/t/gruff-with-pdf-writer/90287>\
**Category:** Rails\
**Created:** [March 27, 2007, 11:53am UTC](https://www.ruby-forum.com/t/gruff-with-pdf-writer/90287 "2007-03-27T11:53:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [March 27, 2007, 11:53am UTC](https://www.ruby-forum.com/t/gruff-with-pdf-writer/90287/1 "2007-03-27T11:53:33Z")

</div>

Hello all

Has anyone managed to embed gruff graphs into a PDF document using  
pdf::writer?

The easy way (as far as I can see) would be to just save the gruff graph  
as a temporary file then read that file in pdf::writer. I was wondering  
if anyone had managed to get them working together directly?

RJ

---

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [March 27, 2007, 2:02pm UTC](https://www.ruby-forum.com/t/gruff-with-pdf-writer/90287/2 "2007-03-27T14:02:08Z")

</div>

I’m definitely looking for a solution to the same thing as well.

---

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [April 12, 2007, 3:29am UTC](https://www.ruby-forum.com/t/gruff-with-pdf-writer/90287/3 "2007-04-12T03:29:07Z")

</div>

Bump…me too.

---

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [April 12, 2007, 4:00am UTC](https://www.ruby-forum.com/t/gruff-with-pdf-writer/90287/4 "2007-04-12T04:00:08Z")

</div>

I did this pretty easily using the technique RJ described earlier  
with writing a temp file. It’s kind of a hack but it works.

What I’m doing is:

First generating the gruff graphs and storing it as file, then  
loading that file in as a blob in the db  
Then generate the pdf by pulling the graphs out of the db, store them  
as temp files, then load that file using the pdf image method.

Andy

---

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [January 13, 2010, 3:07pm UTC](https://www.ruby-forum.com/t/gruff-with-pdf-writer/90287/5 "2010-01-13T15:07:25Z")

</div>

There is a much easier workaround.  
You may just set opacity to zero. Here’s how I did it:

require “gruff”  
class Chart \< Gruff::StackedBar  
def opacity  
@base\_image.opacity  
end  
def opacity=( value )  
@base\_image.opacity = value  
end

def draw  
super  
self.opacity = 0  
end  
end

Or, you may re-open the image and save it again:  
g = Gruff::StackedBar.new( 640 )

# …

i = unique\_filename  
g.write( i )

image = Magick::Image.read( i ).first  
image.opacity = 0  
image.write( i )

pdf = PDF::Writer.new  
( pdf.image i ) && File.delete( i )
