Class: ActiveAnalysis::Analyzer::PDFAnalyzer

Inherits:
ActiveAnalysis::Analyzer show all
Defined in:
lib/active_analysis/analyzer/pdf_analyzer.rb

Overview

Extracts width, height in pixels and number of pages from a pdf blob.

Example:

ActiveAnalysis::Analyzer::PDFAnalyzer::Poppler.new(blob).
# => { width: 4104, height: 2736, pages: 10 }

This analyzer requires the poppler system library, which is not provided by Rails.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.accept?(blob) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/active_analysis/analyzer/pdf_analyzer.rb', line 16

def accept?(blob)
  blob.content_type == "application/pdf" && pdfinfo_exists?
end

.pdfinfo_exists?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/active_analysis/analyzer/pdf_analyzer.rb', line 24

def pdfinfo_exists?
  return @pdfinfo_exists if defined?(@pdfinfo_exists)

  @pdfinfo_exists = system(pdfinfo_path, "-v", out: File::NULL, err: File::NULL)
end

.pdfinfo_pathObject



20
21
22
# File 'lib/active_analysis/analyzer/pdf_analyzer.rb', line 20

def pdfinfo_path
  ActiveStorage.paths[:pdfinfo] || "pdfinfo"
end

Instance Method Details

#metadataObject



31
32
33
# File 'lib/active_analysis/analyzer/pdf_analyzer.rb', line 31

def 
  { width: width, height: height, pages: pages }.compact
end