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

Connect to a Remote MySQL Database in Rails

Using a remote database with rails is useful for collaborating on projects or for keeping all your data in one place. Here's how to get it set up from scratch.

Mar 09, 2015

3 Reasons Why Turbolinks Is Not Worth The Effort

Turbolinks is a great idea in theory, but it comes with enough problems to offset its benefits.

Mar 15, 2016

Why I Don't Use has_and_belongs_to_many in Rails

The magic of Rails makes it easy to create simple many-to-many relationships, but I almost never use it, and here's why.

Mar 31, 2015