-->

如何上传多页PDF,并将其与回形针转换成JPEG?(How to Upload a multipag

2019-07-30 13:22发布

有谁知道如何上传多页PDF文件使用回形针和每个页面转换成JPEG?

到目前为止,我每次上传PDF时,它只是让我看到了PDF的第一页为JPEG。 不过,我想能够上传和每一页从PDF转换为JPEG。

是否有任何宝石或插件,可以帮我上载有10微克PDF和数据库10个JPEG文件转换/店铺?

我已经看过docsplit图像宝石,但我不知道这是解决方案最好的解决方案或它是如何工作。

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) %>

Answer 1:

使用图像标记这个是没有意义的。 您IMAGE_TAG更改为普通链接,你就可以下载和查看所有页面。

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


文章来源: How to Upload a multipage PDF and convert it to JPEG with Paperclip?