Home

Convert PDF to Image with Dragonfly and Rails

Converting a PDF to an image using Rails and Dragonfly is actually quite simple. Check it out.

With other uploaders in rails, it's not super straightforward to convert a PDF to an image. But, by using Dragonfly's ImageMagick plugin, it's real simple.

Make sure you're using the ImageMagick plugin.

config/initializers/dragonfly.rb

Dragonfly.app.configure do
plugin :imagemagick
end

And you'll want GhostScript installed on your machine.

The markup for it, though is simple. If you want a small, 200x200 thumbnail of a pdf, it's as simple as the following.

<%= image.image.thumb('200x200#', :format => 'png', :frame => 0).url %>

Note: This assumes you have an image object that has an uploader mounted to an image accessor. You'll want to update to your application.


References:

Let's Connect

Keep Reading

Preview Emails in Rails

Rails 4.1 introduced the ability to preview email messages from your mailers without sending an email. Learn how ...

Oct 23, 2014

Transition Between Database Adapters in Rails

Transitioning from one database to another, or even to a whole new database with a new adapter, can be tough. Here's an easy way to transition content.

May 25, 2015

How To Use Paper Trail As An Activity Feed

That whole killing two birds with one stone approach might just work in using PaperTrail as an activity log, at least in simpler projects.

Jun 15, 2015