Class: ActiveStorageValidations::Analyzer::PdfAnalyzer
- Inherits:
-
Analyzer
- Object
- Analyzer
- ActiveStorageValidations::Analyzer::PdfAnalyzer
- Defined in:
- lib/active_storage_validations/analyzer/pdf_analyzer.rb
Overview
ActiveStorageValidations PDF Analyzer
Extracts the following from a pdf attachable:
- Width (pts) => for the first page only
- Height (pts) => for the first page only
- Pages (integer) => number of pages in the pdf
Example:
ActiveStorageValidations::Analyzer::PdfAnalyzer.new(attachable).
# => { width: 150, height: 150, pages: 1 }
This analyzer requires the poppler system library, which is not provided by Rails.
Constant Summary collapse
- PAGE_SIZE_NUMBER =
pdfinfo reports e.g. "595.276 x 841.89 pts (A4)". Capture the full integer or decimal so extra fractional digits are not split into a second number (which would make height 8 for A4).
/\d+(?:\.\d+)?/
Instance Method Summary collapse
Instance Method Details
#metadata ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/active_storage_validations/analyzer/pdf_analyzer.rb', line 24 def read_media do |media| { width: width, height: height, pages: pages }.compact end end |