How to preview pdf using active storage and poppler?

柔情痞子 提交于 2021-01-29 09:24:08

问题


I'm trying to display a preview of the uploaded pdf in my application but all I get so far is a broken image.

I have installed the poppler gem as suggested in the active storage presentation for preview.

Then i tried different ways but all are returning a broken image.

<%= link_to bank.rib, rails_blob_path(bank.rib, disposition: "preview") %>

or

<%= image_tag bank.rib %>

or

where 'rib' being the attached file (has_one) of the model BankAccount (here bank = BankAccount.find(id))

bank.rib.previewable? returns true.


回答1:


Installing poppler, is just one of the steps you might need, here are some other things you should check:

  1. Rails might be requiring some additional gems installed:

You must have ImageMagick or GraphicsMagick installed

Add this to your Gemfile:

gem 'image_processing', '~> 1.2'

and install imagemagick:

brew install imagemagick
  1. Another possible issue is that your application cannot reach the /rails/active_storage path, so verify the path is mounted or you do not have a catch_all route that overwrites that path, in case you do, you can exclude rails path with the following:

get "*unmatched_route", constraints: -> (req) { !(req.fullpath =~ /^\/rails\/(active_storage|conductor|action_mailbox)\/.*/) }



来源:https://stackoverflow.com/questions/57698110/how-to-preview-pdf-using-active-storage-and-poppler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!