Class: PDF::Extract::Field
- Inherits:
-
Object
- Object
- PDF::Extract::Field
- Defined in:
- lib/pdf/extract/field.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#reference_resoler ⇒ Object
readonly
Returns the value of attribute reference_resoler.
Instance Method Summary collapse
- #as_json ⇒ Object
- #image ⇒ Object
-
#initialize(data, reference_resoler) ⇒ Field
constructor
A new instance of Field.
-
#name ⇒ Object
PDF Reference 6th Edition, Version 1.7, November 2006 page 675 The partial field name.
-
#type ⇒ Object
PDF Reference 6th Edition, Version 1.7, November 2006 page 675 The type of field that this dictionary describes.
-
#value ⇒ Object
PDF Reference 6th Edition, Version 1.7, November 2006 page 676 The field’s value, whose format varies depending on the field type.
Constructor Details
#initialize(data, reference_resoler) ⇒ Field
Returns a new instance of Field.
7 8 9 10 |
# File 'lib/pdf/extract/field.rb', line 7 def initialize(data, reference_resoler) @data = data @reference_resoler = reference_resoler end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
5 6 7 |
# File 'lib/pdf/extract/field.rb', line 5 def data @data end |
#reference_resoler ⇒ Object (readonly)
Returns the value of attribute reference_resoler.
5 6 7 |
# File 'lib/pdf/extract/field.rb', line 5 def reference_resoler @reference_resoler end |
Instance Method Details
#as_json ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# 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 ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# 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 ⇒ Object
PDF Reference 6th Edition, Version 1.7, November 2006 page 675 The partial field name
14 15 16 |
# File 'lib/pdf/extract/field.rb', line 14 def name data[:T] end |
#type ⇒ Object
PDF Reference 6th Edition, Version 1.7, November 2006 page 675 The type of field that this dictionary describes.
20 21 22 |
# File 'lib/pdf/extract/field.rb', line 20 def type data[:FT] end |
#value ⇒ Object
PDF Reference 6th Edition, Version 1.7, November 2006 page 676 The field’s value, whose format varies depending on the field type.
26 27 28 |
# File 'lib/pdf/extract/field.rb', line 26 def value data[:V] end |