Module: HexaPDF::Task

Defined in:
lib/hexapdf/task.rb,
lib/hexapdf/task/pdfa.rb,
lib/hexapdf/task/optimize.rb,
lib/hexapdf/task/dereference.rb

Overview

Overview

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 ‘task.map’ 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 = HexaPDF::Document.new
doc.config['task.map'][:validate] = lambda do |doc|
  doc.each {|obj| obj.validate || raise "Invalid object #{obj}"}
end

Defined Under Namespace

Modules: Optimize, PDFA Classes: Dereference