Class: PDF::Core::DocumentState
- Inherits:
- 
      Object
      
        - Object
- PDF::Core::DocumentState
 
- Defined in:
- lib/pdf/core/document_state.rb
Overview
:nodoc:
Instance Attribute Summary collapse
- 
  
    
      #before_render_callbacks  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute before_render_callbacks. 
- 
  
    
      #compress  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute compress. 
- 
  
    
      #encrypt  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute encrypt. 
- 
  
    
      #encryption_key  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute encryption_key. 
- 
  
    
      #on_page_create_callback  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute on_page_create_callback. 
- 
  
    
      #optimize_objects  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute optimize_objects. 
- 
  
    
      #page  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute page. 
- 
  
    
      #pages  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute pages. 
- 
  
    
      #skip_encoding  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute skip_encoding. 
- 
  
    
      #store  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute store. 
- 
  
    
      #trailer  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute trailer. 
- 
  
    
      #version  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    Returns the value of attribute version. 
Instance Method Summary collapse
- #before_render_actions(doc) ⇒ Object
- 
  
    
      #initialize(options)  ⇒ DocumentState 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of DocumentState. 
- #insert_page(page, page_number) ⇒ Object
- #normalize_metadata(options) ⇒ Object
- #on_page_create_action(doc) ⇒ Object
- #page_count ⇒ Object
- #populate_pages_from_store(document) ⇒ Object
- #render_body(output) ⇒ Object
Constructor Details
#initialize(options) ⇒ DocumentState
Returns a new instance of DocumentState.
| 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # File 'lib/pdf/core/document_state.rb', line 4 def initialize() () if [:template] @store = PDF::Core::ObjectStore.new(:template => [:template]) @store.info.data.merge!([:info]) if [:info] else @store = PDF::Core::ObjectStore.new(:info => [:info]) end @version = 1.3 @pages = [] @page = nil @trailer = {} @compress = .fetch(:compress, false) @encrypt = .fetch(:encrypt, false) @encryption_key = [:encryption_key] @optimize_objects = .fetch(:optimize_objects, false) @skip_encoding = .fetch(:skip_encoding, false) @before_render_callbacks = [] @on_page_create_callback = nil end | 
Instance Attribute Details
#before_render_callbacks ⇒ Object
Returns the value of attribute before_render_callbacks.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def before_render_callbacks @before_render_callbacks end | 
#compress ⇒ Object
Returns the value of attribute compress.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def compress @compress end | 
#encrypt ⇒ Object
Returns the value of attribute encrypt.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def encrypt @encrypt end | 
#encryption_key ⇒ Object
Returns the value of attribute encryption_key.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def encryption_key @encryption_key end | 
#on_page_create_callback ⇒ Object
Returns the value of attribute on_page_create_callback.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def on_page_create_callback @on_page_create_callback end | 
#optimize_objects ⇒ Object
Returns the value of attribute optimize_objects.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def optimize_objects @optimize_objects end | 
#page ⇒ Object
Returns the value of attribute page.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def page @page end | 
#pages ⇒ Object
Returns the value of attribute pages.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def pages @pages end | 
#skip_encoding ⇒ Object
Returns the value of attribute skip_encoding.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def skip_encoding @skip_encoding end | 
#store ⇒ Object
Returns the value of attribute store.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def store @store end | 
#trailer ⇒ Object
Returns the value of attribute trailer.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def trailer @trailer end | 
#version ⇒ Object
Returns the value of attribute version.
| 27 28 29 | # File 'lib/pdf/core/document_state.rb', line 27 def version @version end | 
Instance Method Details
#before_render_actions(doc) ⇒ Object
| 60 61 62 | # File 'lib/pdf/core/document_state.rb', line 60 def before_render_actions(doc) before_render_callbacks.each{ |c| c.call(self) } end | 
#insert_page(page, page_number) ⇒ Object
| 50 51 52 53 54 | # File 'lib/pdf/core/document_state.rb', line 50 def insert_page(page, page_number) pages.insert(page_number, page) store.pages.data[:Kids].insert(page_number, page.dictionary) store.pages.data[:Count] += 1 end | 
#normalize_metadata(options) ⇒ Object
| 42 43 44 45 46 47 48 | # File 'lib/pdf/core/document_state.rb', line 42 def () [:info] ||= {} [:info][:Creator] ||= "Prawn" [:info][:Producer] ||= "Prawn" [:info] end | 
#on_page_create_action(doc) ⇒ Object
| 56 57 58 | # File 'lib/pdf/core/document_state.rb', line 56 def on_page_create_action(doc) on_page_create_callback[doc] if on_page_create_callback end | 
#page_count ⇒ Object
| 64 65 66 | # File 'lib/pdf/core/document_state.rb', line 64 def page_count pages.length end | 
#populate_pages_from_store(document) ⇒ Object
| 31 32 33 34 35 36 37 38 39 40 | # File 'lib/pdf/core/document_state.rb', line 31 def populate_pages_from_store(document) return 0 if @store.page_count <= 0 || @pages.size > 0 count = (1..@store.page_count) @pages = count.map do |index| orig_dict_id = @store.object_id_for_page(index) PDF::Core::Page.new(document, :object_id => orig_dict_id) end end | 
#render_body(output) ⇒ Object
| 68 69 70 71 72 73 74 75 | # File 'lib/pdf/core/document_state.rb', line 68 def render_body(output) store.compact if optimize_objects store.each do |ref| ref.offset = output.size output << (@encrypt ? ref.encrypted_object(@encryption_key) : ref.object) end end |