class HexaPDF::Revisions

Included Modules

Manages the revisions of a PDF document.

A PDF document has one revision when it is created. Later, new revisions are added when changes are made. This allows for adding information/content to a PDF file without changing the original content.

The order of the revisions is important. In HexaPDF the oldest revision always has index 0 and the newest revision the highest index. This is also the order in which the revisions get written.

See: PDF1.7 s7.5.6, HexaPDF::Revision



The Parser instance used for reading the initial revisions.

Public Class Methods

from_io(document, io)

Loads all revisions for the document from the given IO and returns the created Revisions object.

If the io object is nil, an empty Revisions object is returned.

new(document, initial_revisions: nil, parser: nil)

Creates a new revisions object for the given PDF document.



An array of revisions that should initially be used. If this option is not specified, a single empty revision is added.


The parser with which the initial revisions were read. If this option is not specified even though the document was read from an IO stream, some parts may not work, like incremental writing.

Public Instance Methods

Alias for: revision

Adds a new empty revision to the document and returns it.


Returns the current revision.

delete(index) → rev or nil
delete(oid) → rev or nil

Deletes a revision from the document, either by index or by specifying the revision object itself.

Returns the deleted revision object, or nil if the index was out of range or no matching revision was found.

Regarding the index: The oldest revision has index 0 and the current revision the highest index!

each {|rev| block } → revisions
each → Enumerator

Iterates over all revisions from oldest to current one.

merge(range = 0..-1) → revisions

Merges the revisions specified by the given range into one. Objects from newer revisions overwrite those from older ones.


Returns the revision at the specified index.

Also aliased as: []

Returns the number of HexaPDF::Revision objects managed by this object.