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

Disable Rake Commands in a Rails Project

Sometimes you want to disable some of the default rake tasks in a rails project. Here's a quick way to do just that.

May 15, 2015

Rollback A Deleted Rails Database Migration

You got yourself into that pickle where you created a migration, migrated, deleted the migration, then tried to rollback. Here's how you get around it!

Mar 08, 2016

Related Content (without metadata) in Rails using tf-idf

Sometimes metadata isn't available. Other times you don't want to rely on it. Here's a method for finding related content using term frequency / inverse document frequency.

Oct 12, 2014