How to get the first page of a PDF as an image using Carrierwave in rails?

Imagemagick and mini_magick gem are installed, but I cannot force the model to save when I download pdf.

When I try to create a new instance of the model, I get the following error:

Pdf Failed to manipulate with MiniMagick, maybe it is not an image?

What am I doing wrong here? My intention was to use the solution shown at: http://afreshcup.com/home/2012/9/27/thumbnailing-pdfs-with-minimagick.html

My bootloader:

 class PrivatePdfUploader < CarrierWave::Uploader::Base include CarrierWave::MiniMagick storage :file def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end def default_url "/images/fallback/" + [version_name, "default.png"].compact.join('_') end version :web_thumb do process :thumbnail_pdf end def thumbnail_pdf manipulate! do |img| img.format("png", 1) img.resize("150x150") img = yield(img) if block_given? img end end end 
+5
source share
1 answer

Is ghostscript installed?

 brew install ghostscript 
+2
source

Source: https://habr.com/ru/post/1235055/


All Articles