简体   繁体   English

如何确定Rails应用程序的PDF附件中有多少页?

[英]How can I figure out how many pages are in a PDF attachment in a Rails app?

In my app a user can upload a PDF as an attachment. 在我的应用程序中,用户可以上传PDF作为附件。

I want to report how many pages it has. 我想报告它有多少页。

Is there a Ruby library that would help with this? 有没有一个Ruby库可以帮助解决这个问题?

  require 'rubygems'
  require 'pdf/reader'

  class PageReceiver
    attr_accessor :pages

    # Called when page parsing ends
    def page_count(arg)
      @pages = arg
    end
  end

  receiver = PageReceiver.new
  pdf = PDF::Reader.file("somefile.pdf", receiver, :pages => false)
  puts "#{receiver.pages} pages"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法弄清楚如何在Rails应用中添加多态标签 - Can't figure out how to add polymorphic tags in a rails app 我如何弄清楚为什么我的JRuby Rails应用程序需要太长时间才能提供页面? - How can I figure out why my JRuby rails app takes too long to serve a page? 我怎样才能弄清楚在我的rails应用程序中生成所有这些额外的sqlite3选择的位置? - How can I figure out where all these extra sqlite3 selects are being generated in my rails app? 我怎么弄清楚为什么我的rails 3应用程序,使用mod_rails,是如此之慢? - How do I figure out why my rails 3 app, using mod_rails, is so slow? 如何基于Rails应用程序中的视图生成PDF - How can I generate a PDF based on a view in a Rails app 如何找出 Rails Webpacker 更改我的 css 的原因? - How can I figure out why Rails Webpacker is changing my css? 如何确定我的route.rb文件的哪一行具有Rails 2语法? - How can I figure out which line of my routes.rb file has Rails 2 grammar? Rails4 Scaffold测试失败,如何找出原因? - Rails4 Scaffold test fails, how can I figure out the reason? 在Ruby on Rails中,如何确定哪个类在哪个模块中混合? - In Ruby on rails, how can I figure out which class mix in which module? Rails-无法弄清楚如何编写表格 - Rails - can't figure out how to write form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM