如何使用Paperclip上传多页PDF并将其转换为JPEG? [英] How to Upload a multipage PDF and convert it to JPEG with Paperclip?
问题描述
有人知道如何使用Paperclip上传多页pdf并将每页转换为Jpeg吗?
Does anyone know how to upload a multi-page pdf with Paperclip and convert each page into a Jpeg?
到目前为止,每次我上载PDF时,它只允许我以JPEG格式查看PDF的首页.但我希望能够将PDF的每个页面上传并转换为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.
是否有任何gem或插件可以帮助我上载10-pg PDF并作为10个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?
我看过 docsplit-images gem,但是我不确定这是否是最佳解决方案解决方案或其工作方式.
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.html.erb
<%= form_for ([@post]), :html => { :multipart => true } do |f| %>
<%= f.file_field :pdf %>
<% end %>
show.html.erb
show.html.erb
<%= image_tag @post.pdf.url(:original) %>
推荐答案
为此使用图像标签没有任何意义.将您的image_tag更改为常规链接,即可下载和查看所有页面.
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>
这篇关于如何使用Paperclip上传多页PDF并将其转换为JPEG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!