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

Source Code
lib/pdf/core/object_store.rb, line 19
19
def initialize(opts = {})
20
  @objects = {}
21
  @identifiers = []
22
23
  @info ||= ref(opts[:info] || {}).identifier
24
  @root ||= ref(Type: :Catalog).identifier
25
  if opts[:print_scaling] == :none
26
    root.data[:ViewerPreferences] = { PrintScaling: :None }
27
  end
28
  if pages.nil?
29
    root.data[:Pages] = ref(Type: :Pages, Count: 0, Kids: [])
30
  end
31
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)
Source Code
lib/pdf/core/object_store.rb, line 13
13
def min_version
14
  @min_version
15
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:

Source Code
lib/pdf/core/object_store.rb, line 111
111
def [](id)
112
  @objects[id]
113
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:

Source Code
lib/pdf/core/object_store.rb, line 101
101
def each
102
  @identifiers.each do |id|
103
    yield(@objects[id])
104
  end
105
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:

Source Code
lib/pdf/core/object_store.rb, line 45
45
def info
46
  @objects[@info]
47
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

Source Code
lib/pdf/core/object_store.rb, line 137
137
def object_id_for_page(page)
138
  page -= 1 if page.positive?
139
  flat_page_ids = get_page_objects(pages).flatten
140
  flat_page_ids[page]
141
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)
Source Code
lib/pdf/core/object_store.rb, line 66
66
def page_count
67
  pages.data[:Count]
68
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:

Source Code
lib/pdf/core/object_store.rb, line 59
59
def pages
60
  root.data[:Pages]
61
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:

Source Code
lib/pdf/core/object_store.rb, line 82
82
def push(*args)
83
  reference =
84
    if args.first.is_a?(PDF::Core::Reference)
85
      args.first
86
    else
87
      PDF::Core::Reference.new(*args)
88
    end
89
90
  @objects[reference.identifier] = reference
91
  @identifiers << reference.identifier
92
  reference
93
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:

Source Code
lib/pdf/core/object_store.rb, line 38
38
def ref(data)
39
  push(size + 1, data)
40
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:

Source Code
lib/pdf/core/object_store.rb, line 52
52
def root
53
  @objects[@root]
54
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)
Source Code
lib/pdf/core/object_store.rb, line 118
118
def size
119
  @identifiers.size
120
end