class Pdfmult::PDFInfo
A class for PDF meta data (up to now only used for the page count).
Create an instance with PDFInfo.new
, specifying the file name. PDFInfo
tries to use the pdfinfo
system tool to obtain meta data. If successful, the attribute page_count
contains the page count, else the attribute is set to nil
.
Constants
- PDFINFOCMD
Attributes
page_count[R]
Returns the page count of the input file, or nil.
Public Class Methods
new(file, options={})
click to toggle source
This is the initialization method for the class.
file
- file name of the PDF file
# File lib/pdfmult.rb, line 257 def initialize(file, options={}) @file = file @binary = options[:pdfinfocmd] || PDFINFOCMD # for unit tests infos = retrieve_infos @page_count = infos['Pages'] && infos['Pages'].to_i end
Private Class Methods
infocmd_available?()
click to toggle source
Returns true if default pdfinfo
system tool is available (for unit tests).
# File lib/pdfmult.rb, line 277 def self.infocmd_available? Application.command_available?("#{PDFINFOCMD} -v") end
Private Instance Methods
retrieve_infos()
click to toggle source
Tries to retrieve the PDF infos for the file; returns an info hash.
# File lib/pdfmult.rb, line 267 def retrieve_infos command = "#{@binary} #{@file}" return {} unless Application.command_available?(command) info_array = `#{command}`.split(/\n/) Hash[info_array.map {|line| line.split(/\s*:\s*/, 2) }] end