简体   繁体   English

如何计算文件文档 ruby gem 中的页数?

[英]How to count pages in file docs ruby gem?

I need to count the number of pages in a docs file, There are many pages in a docs file, I want to count the number of pages in it to facilitate input Currently I only count the number of pages if it is a pdf file我需要统计一个docs文件的页数,一个docs文件有很多页,我想统计其中的页数,方便输入目前我只统计pdf文件的页数

Do you know any technology or gem that can solve it?你知道任何可以解决它的技术或宝石吗?

Thanks so much非常感谢

I believe you can use the docsplit gem.我相信您可以使用docsplit gem。 You can find the documentation here .您可以在此处找到文档。

Gemfile:宝石文件:

gem docsplit

Then you should be able to retrieve the number of pages with:然后您应该能够通过以下方式检索页数:

Docsplit.extract_length('path/to/stooges.docx')

Or you could convert your document to PDF and return the number of pages with the method you already know.或者您可以将您的文档转换为 PDF 并使用您已经知道的方法返回页数。 Using docsplit-paperclip-processor , find the documentation enter link description here .使用docsplit-paperclip-processor ,找到文档在此处输入链接描述

Gemfile:宝石文件:

gem 'docsplit-paperclip-processor'

Then run bundle install .然后运行bundle install Then in your model:然后在您的 model 中:

class Document < ActiveRecord::Base

  has_attached_file :file,
                    :styles => {
                      :pdf => {
                        :format => "pdf",
                        :processors => [:docsplit_pdf]
                      }
                    }

end

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM