Gruff with PDF::Writer

Hello all

Has anyone managed to embed gruff graphs into a PDF document using

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?


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

Bump…me too.

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.


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
def opacity=( value )
@base_image.opacity = value

def draw
self.opacity = 0

Or, you may re-open the image and save it again:
g = 640 )

i = unique_filename
g.write( i )

image = i ).first
image.opacity = 0
image.write( i )

pdf =
( pdf.image i ) && File.delete( i )

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs