class PDF::Extract::Field

Attributes

data[R]
reference_resoler[R]

Public Class Methods

new(data, reference_resoler) click to toggle source
# File lib/pdf/extract/field.rb, line 7
def initialize(data, reference_resoler)
  @data = data
  @reference_resoler = reference_resoler
end

Public Instance Methods

as_json() click to toggle source
# File lib/pdf/extract/field.rb, line 63
def as_json
  h = {
    "name" => name,
    "value" => value
  }

  image.tap { |i| h["image"] = i if i }

  h
end
image() click to toggle source
# File lib/pdf/extract/field.rb, line 30
def image
  # PDF Reference 6th Edition, Version 1.7, November 2006 page 641
  # MK: An appearance characteristics dictionary (see Table 8.40) to be used in constructing
  # a dynamic appearance stream specifying the annotation’s visual presentation on the page.
  # The name MK for this entry is of historical significance only and has no direct meaning.
  #
  # PDF Reference 6th Edition, Version 1.7, November 2006 page 1118
  # Implementation Notes
  # If the MK entry is present in the field’s widget annotation dictionary (see Table 8.39),
  # Acrobat viewers regenerate the entire XObject appearance stream. If MK is not present,
  # the contents of the stream outside /Tx BMC ... EMC are preserved.
  mk = data[:MK] || {}

  mk = mk.is_a?(PDF::Reader::Reference) ? reference_resoler.lookup(mk) : mk

  # PDF Reference 6th Edition, Version 1.7, November 2006 page 642
  # I: A form XObject defining the widget annotation’s normal icon, displayed when it is not
  # interacting with the user.
  stream = reference_resoler.lookup(mk[:I])&.hash || {}

  # PDF Reference 6th Edition, Version 1.7, November 2006 page 358
  # form dictionary
  resources = reference_resoler.lookup(stream[:Resources]) || {}

  xobject = resources[:XObject] || {}

  stream = reference_resoler.lookup(xobject[:Im1])

  data = stream&.data

  data ? Base64.encode64(data) : nil
end
name() click to toggle source

PDF Reference 6th Edition, Version 1.7, November 2006 page 675 The partial field name

# File lib/pdf/extract/field.rb, line 14
def name
  data[:T]
end
type() click to toggle source

PDF Reference 6th Edition, Version 1.7, November 2006 page 675 The type of field that this dictionary describes.

# File lib/pdf/extract/field.rb, line 20
def type
  data[:FT]
end
value() click to toggle source

PDF Reference 6th Edition, Version 1.7, November 2006 page 676 The field’s value, whose format varies depending on the field type.

# File lib/pdf/extract/field.rb, line 26
def value
  data[:V]
end