Uninitialized constant RGhost::Color - How to fix it!

Posted on 07 November 2008 by Johannes Fahrenkrug. Tags: Ruby rails
I'm replacing PDF::Writer with RGhost in my Rails application at the moment - after trying out Prawn and realizing that - although it's a great library - it's fast enough either and doesn't meet our real life needs yet (really wide tables were just cut off). RGhost has great documentation, but there is one pitfall when using it with Rails and Ruport: the uninitialized constant RGhost::Color error. When you google for it, you only find a few Portuguese forum posts with no solution. The solution is pretty simple, though: On my Mac, the error occurred in /Library/Ruby/Gems/1.8/gems/rghost-0.8.6/lib/rghost/font_map.rb. In the first lines of the file, 'color' is required. The problem is this: when you have PDF::Writer installed, it depends on a gem with the name 'color'. And that's what gets required when you use RGhost in Rails (under certain circumstances). So the solution is to replace this line:
require 'color'
with this line:
require File.dirname(__FILE__) + '/color'
That's it! Oh, and don't forget to set the path to your Ghostscript executable like so:
RGhost::Config::GS[:path]='/opt/local/bin/gs'
Enjoy!

If this was useful for you, please take a minute and recommend me:
Recommend Me
Thank you!



Comments

Gregory Brown said...

Johannes,

Releases previous to Prawn 0.3 had a strange dependency issue that made it run about 4x slower than it should. If you were trying one of these earlier releases, you might check out the latest version and see if it performs better for you (Though I doubt we'll beat HTMLDOC in any case).

Unfortunately, I won't be at Scotland On Rails. I'll be going to several US based conferences and maybe RubyKaigi if I'm lucky, so please let me know if you make it to any of those.

Also, feel free to let us know how things go if you use Prawn on your upcoming project. Or better yet, write about it here!

January 18, 2009 12:56 AM

Johannes Fahrenkrug said...

Hey Greg,

That's great news, thank you! For performance reasons I went with HTMLDOC for the project I mentioened. But I'm considering Prawn for a different project I'm working on right now. Btw, will you be at Scotland On Rails? I'm considering it... would be great to meet.

January 14, 2009 06:32 AM

Gregory Brown said...

Though it's probably way too late for your needs, Prawn now handles tables that are too wide gracefully thanks to a patch from Andrew Timberlake. This will make it into Prawn 0.4

-greg

January 14, 2009 03:54 AM

Gregory Brown said...

I like HTMLDOC too but it runs into serious limitations when things get too complex.

Also, licensing is less than ideal, you have the choice between GPL or a commercial license, whereas License of Ruby (which is dual-licensed with GPL) or the MIT/BSD licenses are far more appealing.

November 08, 2008 01:09 AM

Johannes Fahrenkrug said...

Hey Greg,

Thanks for the comment. Yeah, RGhost is pretty cool, BUT I ended up using HTMLDOC. Tables are a pain with RGhost because you'll have to manually calculate the right column widths. HTMLDOC just takes an html stream/file and works like a charm. I'll blog about it later. Speed improvement of a pdf with a 8 column table, 9 pages: PDF::Writer: 17 seconds (!), HTMLDOC: 0.5 seconds. Nice!

November 07, 2008 02:10 PM

Gregory Brown said...

Wow, I've never seen RGhost.

That's very cool stuff. I'll have to contact the maintainer so we can collaborate a bit.

Obviously there is a difference between relying on Ghostscript and doing pure Ruby PDF generation, but the library looks very mature and cool!

November 07, 2008 01:50 PM

Comments

Please keep it clean, everybody. Comments with profanity will be deleted.

blog comments powered by Disqus