Sha256: b924e9eea664e8a60c27636e192c7beef56f241c1c76591fa86f6d9d98a48a86

Contents?: true

Size: 716 Bytes

Versions: 16

Compression:

Stored size: 716 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}/
  PDF_CONTENT_TYPE = 'application/pdf'

  def 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, content_type: PDF_CONTENT_TYPE)
  end

  FormatParser.register_parser new, natures: :document, formats: :pdf, priority: 3
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
format_parser-2.3.0 lib/parsers/pdf_parser.rb
format_parser-2.2.1 lib/parsers/pdf_parser.rb
format_parser-2.2.0 lib/parsers/pdf_parser.rb
format_parser-2.1.0 lib/parsers/pdf_parser.rb
format_parser-2.0.0 lib/parsers/pdf_parser.rb
format_parser-2.0.0.pre.4 lib/parsers/pdf_parser.rb
format_parser-2.0.0.pre.3 lib/parsers/pdf_parser.rb
format_parser-2.0.0.pre.2 lib/parsers/pdf_parser.rb
format_parser-2.0.0.pre lib/parsers/pdf_parser.rb
format_parser-1.7.0 lib/parsers/pdf_parser.rb
format_parser-1.6.0 lib/parsers/pdf_parser.rb
format_parser-1.5.0 lib/parsers/pdf_parser.rb
format_parser-1.4.2 lib/parsers/pdf_parser.rb
format_parser-1.4.1 lib/parsers/pdf_parser.rb
format_parser-1.4.0 lib/parsers/pdf_parser.rb
format_parser-1.3.0 lib/parsers/pdf_parser.rb