views:

367

answers:

2

I'm looking for an easy way to generate previews for labels generated as pdfs. It would be great if I could convert these pdfs to images and show them to the user before the actual print/download.

The application is currently running in a Jruby on rails environment, but it's quite possible that we switch to two applications, one running in native ruby (the main application) and one in jruby (the pdf facility). So the choice is not really limited to one of these worlds.

So far I see the following options:

  • RMagick: seems mature, ImageMagick as backend, probably not working on jruby
  • RMagick4J: as RMagick but available for JRuby, appears inactive, only supports subset.
  • Jmagick: JNI Interface for Java, only works in JRuby

The PDF generation itself will always be in a Jruby environment, therefore JMagick sounds like a good idea (expect the possible JNI hassle). On the other hand it would be great if the solution wouldn't be limited to one plattform.

Any ideas? Suggestions? Bad experiences? Perhaps a completely different idea?

Thanks!

+1  A: 

Here's a very thin pure Ruby wrapper for ImageMagick. You can easily send whatever commands you want to ImageMagick via some module methods:

www.misuse.org/science/2008/01/30/mojomagick-ruby-image-library-for-imagemagick/

It should work fine on jruby as well, since there's no DLL magic or anything under the hood.

science
+1  A: 

I use IText for PDF generation/manipulation. It's a Java jar, but it's really easy to call from JRuby. If you combine it with the FlyingSaucer project you can also generate images. Both are very easy to use.

Samuel Holloway