Class: Pdfmult::PDFInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfmult.rb

Overview

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.

Constant Summary collapse

PDFINFOCMD =
"/usr/bin/pdfinfo"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}) ⇒ PDFInfo

This is the initialization method for the class.

file - file name of the PDF file



262
263
264
265
266
267
# File 'lib/pdfmult.rb', line 262

def initialize(file, options = {})
  @file = file
  @binary = options[:pdfinfocmd] || PDFINFOCMD  # for unit tests
  infos = retrieve_infos
  @page_count = infos["Pages"]&.to_i
end

Instance Attribute Details

#page_countObject (readonly)

Returns the page count of the input file, or nil.



257
258
259
# File 'lib/pdfmult.rb', line 257

def page_count
  @page_count
end

Class Method Details

.infocmd_available?Boolean

Returns true if default pdfinfo system tool is available (for unit tests).

Returns:

  • (Boolean)


270
271
272
# File 'lib/pdfmult.rb', line 270

def self.infocmd_available?
  Application.command_available?("#{PDFINFOCMD} -v")
end