How to download a multi-page PDF file and convert it to JPEG using Paperclip?

Does anyone know how to download a multi-page PDF file using Paperclip and convert each page to Jpeg?

So far, every time I download a PDF file, it allows me to see the first page of a PDF as a JPEG. But I would like to be able to download and convert every page from PDF to JPEG.

Is there any gem or plugin that can help me download 10-pg PDF and convert / save to database as 10 jpeg files?

I looked at docsplit-images , but I'm not sure if this is the best solution to the solution or how it works.

post.rb

class Post < ActiveRecord::Base belongs_to :Blogs attr_accessible :content, :title, :pdf has_attached_file :pdf, :url => "/assets/products/:id/:style/:basename.:extension", :path => ":rails_root/public/assets/products/:id/:style/:basename.:extension" validates_attachment_content_type :pdf, :content_type => [ 'application/pdf' ], :message => "only pdf files are allowed" end 

_form.html.erb

 <%= form_for ([@post]), :html => { :multipart => true } do |f| %> <%= f.file_field :pdf %> <% end %> 

show.html.erb

  <%= image_tag @post.pdf.url(:original) %> 
+6
source share
1 answer

Using an image tag for this does not make sense. Change your image_tag to a regular link and you can download and view all pages.

 <p> <%= link_to 'My PDF', @post.pdf.url %> </p> 
+6
source

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


All Articles