Posted over 6 years ago. Visible to the public.

Howto provide a single page preview for PDF & TXT with carrierwave

Assert rmagick provision ...


gem 'rmagick', '2.13.2' # at this moment the latest stable version


require 'carrierwave/processing/rmagick'

... and define a custom processor


class MyUploader < CarrierWave::Uploader::Base include CarrierWave::RMagick def cover manipulate! do |frame, index| frame if # take only the first page of the file end end version :preview do process :cover process :resize_to_fit => [310, 438] process :convert => :jpg def full_filename (for_file = model.source.file) super.chomp(File.extname(super)) + '.jpg' end end ... # the other stuff end


  • Only PDF and TXT files (and of course images) are previewable to my knowledge till dato.
  • Don't forget to provide rmagick on your server

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Martin Straub
Last edit:
about 5 years ago
by Thomas Klemm
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Martin Straub to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more