module HexaPDF::Task


The Task module contains task implementations which are used to perform operations that affect a whole PDF document instead of just a single object.

Normally, such operations would be implemented by using methods on the HexaPDF::Document class. However, this would clutter up the document interface with various methods and also isn't very extensible.

A task name that can be used for HexaPDF::Document#task is mapped to a task object via the '' configuration option.

Implementing a Task

A task is simply a callable object that takes the document as first mandatory argument and can optionally take keyword arguments and/or a block. This means that a block suffices.

Here is a simple example:

doc =
doc.config[''][:validate] = lambda do |doc|
  doc.each {|obj| obj.validate || raise "Invalid object #{obj}"}