Class: IiifPrint::SplitPdfs::BaseSplitter Abstract

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/iiif_print/split_pdfs/base_splitter.rb

Overview

This class is abstract.

The purpose of this class is to split the PDF into constituent image files.

See Also:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, tmpdir: Dir.mktmpdir, default_dpi: 400) ⇒ BaseSplitter

Returns a new instance of BaseSplitter.



45
46
47
48
49
50
51
# File 'lib/iiif_print/split_pdfs/base_splitter.rb', line 45

def initialize(path, tmpdir: Dir.mktmpdir, default_dpi: 400)
  @baseid = SecureRandom.uuid
  @pdfpath = path
  @pdfinfo = IiifPrint::SplitPdfs::PdfImageExtractionService.new(pdfpath)
  @tmpdir = tmpdir
  @default_dpi = default_dpi
end

Class Method Details

.call(path) ⇒ Enumerable

Note:

We’re including the ** args to provide method conformity; other services require additional information (such as the FileSet)

Parameters:

  • path (String)

    local path to the PDF that we will split.

Returns:

  • (Enumerable)

See Also:



26
27
28
# File 'lib/iiif_print/split_pdfs/base_splitter.rb', line 26

def self.call(path, **)
  new(path).to_a
end

.never_split_pdfs?Boolean

Added to allow for fine-tuning of splitting decision such as tenant-based omission

Returns:

  • (Boolean)

    returns false to not limit the splitting of PDFs

See Also:



37
38
39
# File 'lib/iiif_print/split_pdfs/base_splitter.rb', line 37

def self.never_split_pdfs?
  false
end

Instance Method Details

#each {|the| ... } ⇒ Object

Yield Parameters:

  • the (String)

    path to the page’s tiff.



59
60
61
62
63
# File 'lib/iiif_print/split_pdfs/base_splitter.rb', line 59

def each
  entries.each do |e|
    yield(e)
  end
end

#invalid_pdf?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO: put this test somewhere to prevent invalid pdfs from crashing the image service.

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/iiif_print/split_pdfs/base_splitter.rb', line 68

def invalid_pdf?
  return true if pdfinfo.color.include?(nil) || pdfinfo.width.nil? || pdfinfo.height.nil? || pdfinfo.page_count.zero?
  false
end