Does anyone know how to upload a multi-page pdf with Paperclip and convert each page into a Jpeg?
So far, every time I upload a PDF, it only allows me to see the first page of the PDF as a JPEG. But I would like to be able to upload and convert every page from the PDF into a JPEG.
Is there any gem or plug-in that can help me upload a 10-pg PDF and Convert/Store in the Database as 10 JPEG files?
I have looked at docsplit-images gem, but I am not sure if that is the solution best 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) %>
Convert PDF to JPG using Acrobat Open the PDF in Acrobat. Click the Export PDF tool in the right pane. Choose Image as your export format, and then choose JPEG. Click Export.
Click the "View > Tools > Export PDF > Open" in the top menu bar. Then, select "Image" from the "Convert To" dropdown menu, choose the "JPEG" option, and select the quality for your output file.
No, JPEG does not support multi-page images. TIFF is the appropriate format for doing so.
Using an image tag for this makes no sense. Change your image_tag to a regular link and you'll be able to download and view all the pages.
<p>
<%= link_to 'My PDF', @post.pdf.url %>
</p>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With