Class: ComicBook::PDF

Inherits:
Adapter show all
Defined in:
lib/comic_book/pdf.rb,
lib/comic_book/pdf/extractor.rb

Defined Under Namespace

Classes: Extractor

Instance Method Summary collapse

Methods inherited from Adapter

#initialize

Constructor Details

This class inherits a constructor from ComicBook::Adapter

Instance Method Details

#archive(_options = {}) ⇒ Object

Raises:



10
11
12
# File 'lib/comic_book/pdf.rb', line 10

def archive _options = {}
  raise Error, 'PDF archiving not supported (use extract to convert PDF pages to images)'
end

#extract(options = {}) ⇒ Object



14
15
16
17
# File 'lib/comic_book/pdf.rb', line 14

def extract options = {}
  require_vips!
  Extractor.new(path).extract options
end

#infoObject



6
7
8
# File 'lib/comic_book/pdf.rb', line 6

def info
  nil
end

#pagesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/comic_book/pdf.rb', line 19

def pages
  require_vips!
  image = Vips::Image.new_from_file path
  count = image.get 'n-pages'

  (1..count).map do |page_number|
    name = format('page_%03d.jpg', page_number)

    ComicBook::Page.new name, name
  end
rescue StandardError => e
  raise unless e.class.name == 'Vips::Error' # rubocop:disable Style/ClassEqualityComparison

  []
end