Class: PDF::Core::DocumentState Private
- Inherits:
-
Object
- Object
- PDF::Core::DocumentState
- Defined in:
- lib/pdf/core/document_state.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.
Low-level PDF document representation mostly for keeping intermediate state while document is being constructed.
Instance Attribute Summary collapse
-
#before_render_callbacks ⇒ Array<Proc>
private
Before render callbacks.
-
#compress ⇒ Boolean
private
Whether to compress streams.
-
#encrypt ⇒ Boolean
private
Whether to encrypt document.
-
#encryption_key ⇒ String?
private
Encryption key.
-
#on_page_create_callback ⇒ Proc?
private
A block to call when a new page is created.
-
#page ⇒ PDF::Core::Page
private
Current page.
-
#pages ⇒ Array<PDF::Core::Page>
private
Document pages.
-
#skip_encoding ⇒ Object
deprecated
private
Deprecated.
Unused
-
#store ⇒ PDF::Core::ObjectStore
private
Object store.
-
#trailer ⇒ Hash
private
Document trailer dict.
-
#version ⇒ Float
private
PDF version used in this document.
Instance Method Summary collapse
-
#before_render_actions(_doc) ⇒ void
private
Executes before render callbacks.
-
#initialize(options) ⇒ DocumentState
constructor
private
A new instance of DocumentState.
-
#insert_page(page, page_number) ⇒ void
private
Insert a page at the specified position.
-
#normalize_metadata(options) ⇒ Hash
private
Adds Prawn metadata to document info.
-
#on_page_create_action(doc) ⇒ void
private
Execute page creation callback if one is defined.
-
#page_count ⇒ Integer
private
Number of pages in the document.
-
#populate_pages_from_store(document) ⇒ 0, Array<PDF::Core::Page>
private
Loads pages from object store.
-
#render_body(output) ⇒ void
private
Renders document body to the output.
Constructor Details
#initialize(options) ⇒ DocumentState
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 DocumentState.
Source Code
20 | def initialize(options) |
21 | normalize_metadata(options) |
22 | |
23 | @store = |
24 | if options[:print_scaling] |
25 | PDF::Core::ObjectStore.new( |
26 | info: options[:info], |
27 | print_scaling: options[:print_scaling], |
28 | )
|
29 | else
|
30 | PDF::Core::ObjectStore.new(info: options[:info]) |
31 | end
|
32 | |
33 | @version = 1.3 |
34 | @pages = [] |
35 | @page = nil |
36 | @trailer = options.fetch(:trailer, {}) |
37 | @compress = options.fetch(:compress, false) |
38 | @encrypt = options.fetch(:encrypt, false) |
39 | @encryption_key = options[:encryption_key] |
40 | @skip_encoding = options.fetch(:skip_encoding, false) |
41 | @before_render_callbacks = [] |
42 | @on_page_create_callback = nil |
43 | end
|
Instance Attribute Details
#before_render_callbacks ⇒ Array<Proc>
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.
Before render callbacks
Source Code
82 | def before_render_callbacks |
83 | @before_render_callbacks
|
84 | end
|
#compress ⇒ Boolean
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.
Whether to compress streams
Source Code
67 | def compress |
68 | @compress
|
69 | end
|
#encrypt ⇒ Boolean
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.
Whether to encrypt document
Source Code
71 | def encrypt |
72 | @encrypt
|
73 | end
|
#encryption_key ⇒ String?
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.
Encryption key
Source Code
75 | def encryption_key |
76 | @encryption_key
|
77 | end
|
#on_page_create_callback ⇒ Proc?
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.
A block to call when a new page is created
Source Code
86 | def on_page_create_callback |
87 | @on_page_create_callback
|
88 | end
|
#page ⇒ PDF::Core::Page
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.
Current page
Source Code
59 | def page |
60 | @page
|
61 | end
|
#pages ⇒ Array<PDF::Core::Page>
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
Source Code
55 | def pages |
56 | @pages
|
57 | end
|
#skip_encoding ⇒ Object
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.
Unused
Source Code
78 | def skip_encoding |
79 | @skip_encoding
|
80 | end
|
#store ⇒ PDF::Core::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.
Object store
Source Code
47 | def store |
48 | @store
|
49 | end
|
#trailer ⇒ Hash
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 trailer dict
Source Code
63 | def trailer |
64 | @trailer
|
65 | end
|
#version ⇒ Float
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.
PDF version used in this document
Source Code
51 | def version |
52 | @version
|
53 | end
|
Instance Method Details
#before_render_actions(_doc) ⇒ 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.
Executes before render callbacks
Source Code
139 | def before_render_actions(_doc) |
140 | before_render_callbacks.each { |c| c.call(self) } |
141 | end
|
#insert_page(page, page_number) ⇒ 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.
Insert a page at the specified position.
Source Code
121 | def insert_page(page, page_number) |
122 | pages.insert(page_number, page) |
123 | store.pages.data[:Kids].insert(page_number, page.dictionary) |
124 | store.pages.data[:Count] += 1 |
125 | end
|
#normalize_metadata(options) ⇒ Hash
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 Prawn metadata to document info
Source Code
108 | def normalize_metadata(options) |
109 | options[:info] ||= {} |
110 | options[:info][:Creator] ||= 'Prawn' |
111 | options[:info][:Producer] ||= 'Prawn' |
112 | |
113 | options[:info] |
114 | end
|
#on_page_create_action(doc) ⇒ 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.
Execute page creation callback if one is defined
Source Code
131 | def on_page_create_action(doc) |
132 | on_page_create_callback[doc] if on_page_create_callback |
133 | end
|
#page_count ⇒ 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.
Number of pages in the document
Source Code
146 | def page_count |
147 | pages.length |
148 | end
|
#populate_pages_from_store(document) ⇒ 0, Array<PDF::Core::Page>
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.
Loads pages from object store. Only does it when there are no pages loaded and there are some pages in the store.
Source Code
93 | def populate_pages_from_store(document) |
94 | return 0 if @store.page_count <= 0 || !@pages.empty? |
95 | |
96 | count = (1..@store.page_count) |
97 | @pages = |
98 | count.map { |index| |
99 | orig_dict_id = @store.object_id_for_page(index) |
100 | PDF::Core::Page.new(document, object_id: orig_dict_id) |
101 | }
|
102 | end
|
#render_body(output) ⇒ 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.
Renders document body to the output
Source Code
154 | def render_body(output) |
155 | store.each do |ref| |
156 | ref.offset = output.size |
157 | output << |
158 | if @encrypt |
159 | ref.encrypted_object(@encryption_key) |
160 | else
|
161 | ref.object |
162 | end
|
163 | end
|
164 | end
|