带有回形针的PDF-获取文档属性(如页数) [英] PDF attached with Paperclip - get document properties (like page count)
问题描述
在我的学习RoR的应用程序中,我想了解如何处理附件.得到回形针工作,并希望获得文档属性.那么,如何从pdf文件(使用Paperclip附加)中获取文档属性(PDF信息)?
In my app to learn RoR, I want to see how to handle attachments. Got paperclip to work and want to get document properties. So, how can I get document properties (PDF info) from pdf files (attached using Paperclip)?
一种方法是使用命令行,但如何获取文件(在此为@annotation.file
-或为其他对象@document.file
)?实际上,我需要将文件下载到temp文件夹中,然后删除文件进行清理.如何不下载就获取详细信息?
One way is to use command line, yet how to get it the file (here @annotation.file
- or for other object @document.file
)? Actually, I would need to download the file to a temp folder to do this and do a file delete to clean up. How can I get the details without download?
所以控制器看起来像这样:
So controller to look like this:
def pdf
@annotation = Annotation.find(params[:id])
render layout: false
command = 'pdfinfo @annotation.file'
no_of_pages = command.split("\n")[-7].split(":").last.strip
end
它引发错误:
nil:NilClass的未定义方法"split"
undefined method `split' for nil:NilClass
我使用以下命令将其转到注释视图
I get it to my annotation view using:
<%= @no_of_pages %>
与此同时,我查看了宝石"[pdfinfo][1]
",但是如何使用它呢?
Meanwhile I looked at the gem "[pdfinfo][1]
" as an alternative, yet how to use this?
推荐答案
轻松解决方案L使用PDFINFO gem;效果很好
Easy solutionL use the PDFINFO gem; works very well
这篇关于带有回形针的PDF-获取文档属性(如页数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!