class HexaPDF::Document::Signatures

Parent
Included Modules

This class provides methods for interacting with digital signatures of a PDF file.

Public Class Methods

embed_signature(io, signature)

Embeds the given signature into the /Contents value of the newest signature dictionary of the PDF document given by the io argument.

This functionality can be used together with the support for external signing (see DefaultHandler and DefaultHandler#external_signing) to implement asynchronous signing.

Note: This will, most probably, only work on documents prepared for external signing by HexaPDF and not by other libraries.

locate_signature_dict(xref_section, start_xref_position, signature_oid)

Uses the information in the given cross-reference section as well as the byte offset of the cross-reference section to calculate the offset and length of the signature dictionary with the given object id.

new(document)

Creates a new Signatures object for the given PDF document.

replace_signature_contents(signature_data, contents)

Replaces the value of the /Contents key in the serialized signature_data with the value of contents.

Public Instance Methods

add(file_or_io, handler, signature: nil, write_options: {})

Adds a signature to the document and returns the corresponding signature object.

This method will add a new signature to the document and write the updated document to the given file or IO stream. Afterwards the document can't be modified anymore and still retain a correct digital signature. To modify the signed document (e.g. for adding another signature) create a new document based on the given file or IO stream instead.

signature

Can either be a signature object (determined via the /Type key), a signature field or nil. Providing a signature object or signature field provides for more control, e.g.:

  • Setting values for optional signature object fields like /Reason and /Location.

  • (In)directly specifying which signature field should be used.

If a signature object is provided and it is not associated with an AcroForm signature field, a new signature field is created and added to the main AcroForm object, creating that if necessary.

If a signature field is provided and it already has a signature object as field value, that signature object is discarded.

If the signature field doesn't have a widget, a non-visible one is created on the first page.

handler

The signing handler that provides the necessary methods for signing and adjusting the signature and signature field objects to one's liking, see handler and DefaultHandler.

write_options

The key-value pairs of this hash will be passed on to the HexaPDF::Document#write method. Note that incremental will be automatically set to ensure proper behaviour.

The used signature object will have the following default values set:

/Filter

/Adobe.PPKLite

/SubFilter

/adbe.pkcs7.detached

/M

The current time.

These values can be overridden in the finalize_objects method of the signature handler.

count()

Returns the number of signatures in the PDF document. May be zero if the document has no signatures.

each {|signature| block } → signatures
each → Enumerator

Iterates over all signatures in the order they are found.

handler(name: :default, **attributes)

Creates a signing handler with the given attributes and returns it.

A signing handler name is mapped to a class via the 'signature.signing_handler' configuration option. The default signing handler is DefaultHandler.