Class: Origami::Page

Inherits:
Dictionary show all
Includes:
ResourcesHolder, StandardObject
Defined in:
lib/origami/page.rb

Overview

Class representing a Page in the PDF document.

Constant Summary

Constants included from StandardObject

StandardObject::DEFAULT_ATTRIBUTES

Constants inherited from Dictionary

Dictionary::TOKENS

Constants included from Object

Object::TOKENS

Instance Attribute Summary

Attributes inherited from Dictionary

#names_cache, #strings_cache, #xref_cache

Attributes included from Object

#file_offset, #generation, #no, #objstm_offset, #parent

Instance Method Summary collapse

Methods included from ResourcesHolder

#add_colorspace, #add_extgstate, #add_font, #add_pattern, #add_properties, #add_shading, #add_xobject

Methods included from StandardObject

#do_type_check, #has_field?, included, #pdf_version_required, #set_default_value, #set_default_values

Methods inherited from Dictionary

#[], #[]=, #delete, #has_key?, #map!, #merge, #method_missing, parse, #real_type, #to_obfuscated_str, #to_s

Methods included from Object

#<=>, #copy, #indirect_parent, #is_indirect?, parse, #pdf, #pdf_version_required, #post_build, #reference, #set_indirect, #set_pdf, #size, skip_until_next_obj, #solve, #to_o, #to_s, #type, typeof, #xrefs

Methods inherited from Hash

#to_o

Constructor Details

#initialize(hash = {}) ⇒ Page

Returns a new instance of Page.



375
376
377
378
379
# File 'lib/origami/page.rb', line 375

def initialize(hash = {})
  super(hash)
  
  set_indirect(true)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Origami::Dictionary

Instance Method Details

#add_annot(*annotations) ⇒ Object

Add an Annotation to the Page.



401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/origami/page.rb', line 401

def add_annot(*annotations)
  unless annotations.all?{|annot| annot.is_a?(Annotation) or annot.is_a?(Reference)}
    raise TypeError, "Only Annotation objects must be passed."
  end
  
  self.Annots ||= []

  annotations.each do |annot| 
    annot.solve[:P] = self if is_indirect?
    self.Annots << annot 
  end
end

#add_flash_application(swfspec, params = {}) ⇒ Object

Embed a SWF Flash application in the page.



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/origami/page.rb', line 439

def add_flash_application(swfspec, params = {})
  options =
  {
    :windowed => false,
    :transparent => false,
    :navigation_pane => false,
    :toolbar => false,
    :pass_context_click => false,
    :activation => Annotation::RichMedia::Activation::PAGE_OPEN,
    :deactivation => Annotation::RichMedia::Deactivation::PAGE_CLOSE,
    :flash_vars => nil
  }
  options.update(params)

  annot = create_richmedia(:Flash, swfspec, options)
  add_annot(annot)

  annot
end

#annotationsObject

Returns the array of Annotation objects of the Page.



429
430
431
432
433
434
# File 'lib/origami/page.rb', line 429

def annotations
  annots = self.Annots
  return [] unless annots.is_a?(Array)
  
  annots.map{|annot| annot.solve} 
end

#each_annot(&b) ⇒ Object

Iterate through each Annotation of the Page.



417
418
419
420
421
422
423
424
# File 'lib/origami/page.rb', line 417

def each_annot(&b)
  annots = self.Annots
  return unless annots.is_a?(Array)

  annots.each do |annot|
    b.call(annot.solve) 
  end
end

#onClose(action) ⇒ Object

Will execute an action when the page is closed.



476
477
478
479
480
481
482
483
484
485
# File 'lib/origami/page.rb', line 476

def onClose(action)
  unless action.is_a?(Action) or action.is_a?(Reference)
    raise TypeError, "An Action object must be passed."
  end
  
  self.AA ||= PageAdditionalActions.new
  self.AA.C = action

  self
end

#onNavigateBackward(action) ⇒ Object

Will execute an action when navigating backward from this page.



504
505
506
507
508
509
510
511
512
513
# File 'lib/origami/page.rb', line 504

def onNavigateBackward(action) #:nodoc:
  unless action.is_a?(Action) or action.is_a?(Reference)
    raise TypeError, "An Action object must be passed."
  end
  
  self.PresSteps ||= NavigationNode.new
  self.PresSteps.PA = action

  self
end

#onNavigateForward(action) ⇒ Object

Will execute an action when navigating forward from this page.



490
491
492
493
494
495
496
497
498
499
# File 'lib/origami/page.rb', line 490

def onNavigateForward(action) #:nodoc:
  unless action.is_a?(Action) or action.is_a?(Reference)
    raise TypeError, "An Action object must be passed."
  end
  
  self.PresSteps ||= NavigationNode.new
  self.PresSteps.NA = action

  self
end

#onOpen(action) ⇒ Object

Will execute an action when the page is opened.



462
463
464
465
466
467
468
469
470
471
# File 'lib/origami/page.rb', line 462

def onOpen(action)
  unless action.is_a?(Action) or action.is_a?(Reference)
    raise TypeError, "An Action object must be passed."
  end
  
  self.AA ||= PageAdditionalActions.new
  self.AA.O = action
  
  self
end

#pre_buildObject



392
393
394
395
396
# File 'lib/origami/page.rb', line 392

def pre_build
  self.Resources = Resources.new.pre_build unless self.has_key?(:Resources)

  super
end

#render(engine) ⇒ Object

:nodoc:



381
382
383
384
385
386
387
388
389
390
# File 'lib/origami/page.rb', line 381

def render(engine) #:nodoc:
  contents = self.Contents
  return unless contents.is_a? Stream
  
  unless contents.is_a? ContentStream
    contents = ContentStream.new(contents.data)
  end

  contents.render(engine)
end