class

PdfForms::PdftkWrapper

Inherits PdfForms::NormalizePath / Reference / Object

Wraps calls to PdfTk

Constants

ALLOWED_OPTIONS = ["drop_xmp", "drop_xfa", "flatten", "need_appearances"] of ::String

Constructors

new(pdftk_path : String = PDFTK_PATH, options : Hash(String, Bool | String) = {} of String => String | Bool)

Initializes a new wrapper instance. Pdftk will be autodetected from PATH: PdftkWrapper.new(:flatten => true, :encrypt => true, :encrypt_options => "allow Printing")

The pdftk binary may also be explecitly specified: PdftkWrapper.new("/usr/bin/pdftk", :flatten => true, :encrypt => true, :encrypt_options => "allow Printing")

Besides the options shown above, the drop_xfa or drop_xmp options are also supported.

Source

Instance methods

call_pdftk(args : Array(String))

returns the commands output, check general execution success with $?.success?

Source
cat(*args)

concatenate documents, can optionally specify page ranges

args: in_file1, {in_file2 => ["1-2", "4-10"]}, ... , in_file_n, output

Source
fill_form(template : String, destination : String, data : Hash(String, String) = {} of String => String, fill_options : Hash(String, String | Bool) = {} of String => String | Bool)

pdftk.fill_form "/path/to/form.pdf", "/path/to/destination.pdf", :field1 => "value 1"

Source
get_field_names(template)

get field names for template

Initialize the object with utf8_fields: true to get utf8 encoded field names.

Source
get_fields(template)

Get field metadata for template

Initialize the object with utf8_fields: true to get utf8 encoded field metadata.

Source
multistamp(primary_file, stamp_file, output)

applies each page of the stamp PDF to the corresponding page of the input PDF args: primary_file, stamp_file, output

Source
options=(options : Hash(String, String | Bool))
Source
pdftk_path=(pdftk_path : String)
Source
read(path)

pdftk.read "/path/to/form.pdf" returns an instance of PdfForms::Pdf representing the given template

Source
stamp(primary_file, stamp_file, output)

stamp one pdf with another

args: primary_file, stamp_file, output

Source