Class: PDF::Reader::FormXObject

Inherits:
Object
  • Object
show all
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 Method Summary collapse

Constructor Details

#initialize(page, xobject) ⇒ FormXObject

Returns a new instance of FormXObject.



15
16
17
18
19
# File 'lib/pdf/reader/form_xobject.rb', line 15

def initialize(page, xobject)
  @page    = page
  @objects = page.objects
  @xobject = @objects.deref(xobject)
end

Instance Method Details

#fontsObject

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.



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

def fonts
  raw_fonts = @objects.deref(resources[:Font] || {})
  ::Hash[raw_fonts.map { |label, font|
    [label, PDF::Reader::Font.new(@objects, @objects.deref(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.



53
54
55
# File 'lib/pdf/reader/form_xobject.rb', line 53

def raw_content
  @xobject.unfiltered_data
end

#resourcesObject

Returns the resources that accompany this form.



23
24
25
# File 'lib/pdf/reader/form_xobject.rb', line 23

def resources
  @resources ||= @objects.deref(@xobject.hash[:Resources]) || {}
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.



46
47
48
# File 'lib/pdf/reader/form_xobject.rb', line 46

def walk(*receivers)
  content_stream(receivers, raw_content)
end