Sha256: 0d100ed15503ac122a8b30db3a79b730dae428a53a29227241147f0ad79104d8

Contents?: true

Size: 652 Bytes

Versions: 2

Compression:

Stored size: 652 Bytes

Contents

class FormatParser::PDFParser
  include FormatParser::IOUtils

  # First 9 bytes of a PDF should be in this format, according to:
  #
  #  https://stackoverflow.com/questions/3108201/detect-if-pdf-file-is-correct-header-pdf
  #
  # There are however exceptions, which are left out for now.
  #
  PDF_MARKER = /%PDF-1\.[0-8]{1}/

  def self.likely_match?(filename)
    filename =~ /\.(pdf|ai)$/i
  end

  def call(io)
    io = FormatParser::IOConstraint.new(io)

    return unless safe_read(io, 9) =~ PDF_MARKER

    FormatParser::Document.new(format: :pdf)
  end

  FormatParser.register_parser self, natures: :document, formats: :pdf, priority: 1
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
format_parser-0.16.1 lib/parsers/pdf_parser.rb
format_parser-0.16.0 lib/parsers/pdf_parser.rb