class HexaPDF::Revision

Parent
Included Modules

Embodies one revision of a PDF file, either the initial version or an incremental update.

The purpose of a Revision object is to manage the objects and the trailer of one revision. These objects can either be added manually or loaded from a cross-reference section or stream. Since a PDF file can be incrementally updated, it can have multiple revisions.

If a revision doesn’t have an associated cross-reference section, it wasn’t created from a PDF file.

See: PDF2.0 s7.5.6, Revisions

Attributes

loader[RW]

The callable object responsible for loading objects.

trailer[R]

The trailer dictionary

xref_section[R]

The associated XRefSection object.

Public Class Methods

new(trailer) → revision
new(trailer, xref_section: section, loader: loader) → revision
new(trailer, xref_section: section) {|entry| block } → revision

Creates a new Revision object.

Options:

xref_section

An XRefSection object that contains information on how to load objects. If this option is specified, then a loader or a block also needs to be specified!

loader

The loader object needs to respond to call taking a cross-reference entry and returning the loaded object. If no xref_section is supplied, this value is not used.

If a block is given, it is used instead of the loader object.

Public Instance Methods

add(obj) → obj

Adds the given object (needs to be a HexaPDF::Object) to this revision and returns it.

delete(ref, mark_as_free: true)
delete(oid, mark_as_free: true)

Deletes the object specified either by reference or by object number from this revision by marking it as free.

If the mark_as_free option is set to false, the object is really deleted.

each(only_loaded: false) {|obj| block } → revision
each(only_loaded: false) → Enumerator

Calls the given block for every object of the revision, or, if only_loaded is true, for every already loaded object.

Objects that are loadable via an associated cross-reference section but are currently not loaded, are loaded automatically if only_loaded is false.

each_modified_object(delete: false, all: all) {|obj| block } → revision
each_modified_object(delete: false, all: all) → Enumerator

Calls the given block once for each object that has been modified since it was loaded. Added or eleted object and cross-reference streams as well as signature dictionaries are ignored.

delete

If the delete argument is set to true, each modified object is deleted from the active objects.

all

If the all argument is set to true, added object and cross-reference streams are also yielded.

Note that this also means that for revisions without an associated cross-reference section all loaded objects will be yielded.

next_free_oid()

Returns the next free object number for adding an object to this revision.

object(ref) → obj or nil
object(oid) → obj or nil

Returns the object for the given reference or object number if such an object is available in this revision, or nil otherwise.

If the revision has an entry but one that is pointing to a free entry in the cross-reference section, an object representing PDF null is returned.

object?(ref) → true or false
object?(oid) → true or false

Returns true if the revision contains an object

  • for the exact reference if the argument responds to :oid, or else

  • for the given object number.

update(obj) → obj or nil

Updates the stored object to point to the given HexaPDF::Object wrapper, returning the object if successful or nil otherwise.

If obj isn’t stored in this revision or the stored object doesn’t contain the same HexaPDF::PDFData object as the given object, nothing is done.

This method should only be used if the wrong wrapper class is stored (e.g. because auto-detection didn’t or couldn’t work correctly) and thus needs correction.

xref(ref) → xref_entry or nil
xref(oid) → xref_entry or nil

Returns an XRefSection::Entry structure for the given reference or object number if it is available, or nil otherwise.