Class: PDF::Core::ObjectStore Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/pdf/core/object_store.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

PDF object repository

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ObjectStore

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ObjectStore.

Parameters:

  • opts (Hash) (defaults to: {})

Options Hash (opts):

  • :info (Hash)

    Documnt info dict

  • :print_scaling (:none, nil) — default: nil

    Print scaling viewer option



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/pdf/core/object_store.rb', line 19

def initialize(opts = {})
  @objects = {}
  @identifiers = []

  @info ||= ref(opts[:info] || {}).identifier
  @root ||= ref(Type: :Catalog).identifier
  if opts[:print_scaling] == :none
    root.data[:ViewerPreferences] = { PrintScaling: :None }
  end
  if pages.nil?
    root.data[:Pages] = ref(Type: :Pages, Count: 0, Kids: [])
  end
end

Instance Attribute Details

#min_versionFloat (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Minimum PDF version

Returns:

  • (Float)


13
14
15
# File 'lib/pdf/core/object_store.rb', line 13

def min_version
  @min_version
end

Instance Method Details

#[](id) ⇒ Reference

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get object reference by its identifier.

Parameters:

  • id (Integer)

    object identifier

Returns:



111
112
113
# File 'lib/pdf/core/object_store.rb', line 111

def [](id)
  @objects[id]
end

#each {|ref| ... } ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Iterate over document object references.

Yield Parameters:



101
102
103
104
105
# File 'lib/pdf/core/object_store.rb', line 101

def each
  @identifiers.each do |id|
    yield(@objects[id])
  end
end

#infoReference

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Document info dict reference

Returns:



45
46
47
# File 'lib/pdf/core/object_store.rb', line 45

def info
  @objects[@info]
end

#object_id_for_page(page) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get page reference identifier by page number.Pages are indexed starting at 1 (**not 0**).

Examples:

object_id_for_page(1)
#=> 5
object_id_for_page(10)
#=> 87
object_id_for_page(-11)
#=> 17

Parameters:

  • page (Integer)

    page number

Returns:

  • (Integer)

    page object identifier



137
138
139
140
141
# File 'lib/pdf/core/object_store.rb', line 137

def object_id_for_page(page)
  page -= 1 if page.positive?
  flat_page_ids = get_page_objects(pages).flatten
  flat_page_ids[page]
end

#page_countInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Number of pages in the document

Returns:

  • (Integer)


66
67
68
# File 'lib/pdf/core/object_store.rb', line 66

def page_count
  pages.data[:Count]
end

#pagesReference

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Document pages reference

Returns:



59
60
61
# File 'lib/pdf/core/object_store.rb', line 59

def pages
  root.data[:Pages]
end

#push(reference) ⇒ reference #push(id, data) ⇒ Reference Also known as: <<

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds the given reference to the store and returns the reference object. If the object provided is not a PDF::Core::Reference, one is created from the arguments provided.

Overloads:

  • #push(reference) ⇒ reference

    Parameters:

    Returns:

    • (reference)
  • #push(id, data) ⇒ Reference

    Returns - the added reference.

    Parameters:

    • id (Integer)

      reference identifier

    • data (Hash, Array, Numeric, String, Symbol, Date, Time, nil)

      object data

    Returns:



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/pdf/core/object_store.rb', line 82

def push(*args)
  reference =
    if args.first.is_a?(PDF::Core::Reference)
      args.first
    else
      PDF::Core::Reference.new(*args)
    end

  @objects[reference.identifier] = reference
  @identifiers << reference.identifier
  reference
end

#ref(data) ⇒ Reference

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Wrap an object into a reference.

Parameters:

  • data (Hash, Array, Numeric, String, Symbol, Date, Time, nil)

    object data

Returns:



38
39
40
# File 'lib/pdf/core/object_store.rb', line 38

def ref(data)
  push(size + 1, data)
end

#rootReference

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Document root dict reference

Returns:



52
53
54
# File 'lib/pdf/core/object_store.rb', line 52

def root
  @objects[@root]
end

#sizeInteger Also known as: length

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Number of object references in the document.

Returns:

  • (Integer)


118
119
120
# File 'lib/pdf/core/object_store.rb', line 118

def size
  @identifiers.size
end