class HexaPDF::CLI::Command


Base class for all hexapdf commands. It provides utility methods needed by the individual commands.



Protected Instance Methods


Applies the encryption related options to the given HexaPDF::Document instance.

See: define_encryption_options


Applies the optimization options to the given HexaPDF::Document instance.

See: define_optimization_options


Defines the encryption options.

See: out_options, apply_encryption_options


Defines the optimization options.

See: out_options, apply_optimization_options


Returns the human readable file size.


Checks whether the given output file exists and ask whether to overwrite the output file if it does. If HexaPDF::CLI#force is set, a possibly existing output file is always overwritten.


Optimize the object if it is a font object.


Applies the chosen stream mode to the given object.

parse_pages_specification(range, count)

Parses the pages specification string and returns an array of tuples containing a page number and a rotation value (either -90, 90, 180, :none or nil where an integer means adding a rotation by that number of degrees, :none means removing any set rotation value and nil means preserving the set rotation value).

The parameter count needs to be the total number of pages in the document.

For details on the pages specification see the hexapdf(1) manual page.


Returns a hash with HexaPDF::Document options based on the given password and the option switches.

read_password(prompt = "Password")

Reads a password from the standard input and falls back to the console if needed.

The optional argument prompt can be used to customize the prompt when reading from the console.


Removes unused pages and page tree nodes from the document.

with_document(file, password: nil, out_file: nil, incremental: false) { |document| ... }

Creates a HexaPDF::Document instance for the PDF file and yields it.

If out_file is given, the document is written to it after yielding.

write_document(doc, out_file, incremental: false)

Writes the document to the given file or does nothing if out_file is nil.