Class: PDF::Reader::FormXObject

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pdf/reader/form_xobject.rb

Overview

High level representation of a single PDF form xobject. Form xobjects are contained pieces of content that can be inserted onto multiple pages. They’re generally used as a space efficient way to store repetative content (like logos, header, footers, etc).

This behaves and looks much like a limited PDF::Reader::Page class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, xobject, options = {}) ⇒ FormXObject

: (untyped, untyped, ?Hash[untyped, untyped]) -> void



33
34
35
36
37
38
# File 'lib/pdf/reader/form_xobject.rb', line 33

def initialize(page, xobject, options = {})
  @page    = page
  @objects = page.objects
  @cache   = options[:cache] || {}
  @xobject = @objects.deref_stream(xobject)
end

Instance Attribute Details

#xobjectObject (readonly)

: untyped



21
22
23
# File 'lib/pdf/reader/form_xobject.rb', line 21

def xobject
  @xobject
end

Instance Method Details

#font_objectsObject

return a hash of fonts used on this form.

The keys are the font labels used within the form content stream.

The values are a PDF::Reader::Font instances that provide access to most available metrics for each font.

: () -> untyped



48
49
50
51
52
53
# File 'lib/pdf/reader/form_xobject.rb', line 48

def font_objects
  raw_fonts = @objects.deref_hash(fonts)
  ::Hash[raw_fonts.map { |label, font|
    [label, PDF::Reader::Font.new(@objects, @objects.deref_hash(font) || {})]
  }]
end

#raw_contentObject

returns the raw content stream for this page. This is plumbing, nothing to see here unless you’re a PDF nerd like me.

: () -> untyped



72
73
74
# File 'lib/pdf/reader/form_xobject.rb', line 72

def raw_content
  @xobject.unfiltered_data
end

#walk(*receivers) ⇒ Object

processes the raw content stream for this form in sequential order and passes callbacks to the receiver objects.

See the comments on PDF::Reader::Page#walk for more detail.

: (*untyped) -> untyped



61
62
63
64
65
66
# File 'lib/pdf/reader/form_xobject.rb', line 61

def walk(*receivers)
  receivers = receivers.map { |receiver|
    ValidatingReceiver.new(receiver)
  }
  content_stream(receivers, raw_content)
end