PHP Class mikehaertl\pdftk\Command

This class represents an pdftk shell command. It extends a standard shellcommand and adds pdftk specific features to add options and operations.
Author: Michael Härtl ([email protected])
Inheritance: extends mikehaertl\shellcommand\Command
Mostra file Open project: mikehaertl/php-pdftk Class Usage Examples

Protected Properties

Property Type Description
$_command the pdftk binary
$_escapeOperationArgument whether to force escaping of the operation argument e.g. for filenames
$_files list of input files to process as array('name' => $filename, 'password' => $pw) indexed by handle
$_operation the operation to perform
$_operationArgument operation arguments, e.g. a list of page ranges or a filename or tmp file instance
$_options list of command options, either strings or array with arguments to addArg()

Public Methods

Method Description
addFile ( string $name, string $handle, string | null $password = null ) : Command
addOption ( string $option, string | File | null $argument = null, $escape = null ) : Command
addPageRange ( integer | string | array $start, integer | string | null $end = null, string | null $handle = null, string | null $qualifier = null, string $rotation = null ) : Command Add a page range as used by some operations
execute ( string | null $filename = null ) : boolean
getFileCount ( ) : integer
getOperation ( ) : string | null
getOperationArgument ( ) : string | array | null
setOperation ( string $operation ) : Command
setOperationArgument ( string $value, boolean $escape = false ) : Command

Protected Methods

Method Description
checkExecutionStatus ( ) Ensure that the command was not exectued yet. Throws exception otherwise.
processInputFiles ( ) Process input PDF files and create respective command arguments
processOperation ( ) Process opearation and create respective command arguments
processOptions ( string | null $filename = null ) Process options and create respective command arguments

Method Details

addFile() public method

public addFile ( string $name, string $handle, string | null $password = null ) : Command
$name string the PDF file to add for processing
$handle string one or more uppercase letters A..Z to reference this file later.
$password string | null the owner (or user) password if any
return Command the command instance for method chaining

addOption() public method

public addOption ( string $option, string | File | null $argument = null, $escape = null ) : Command
$option string the pdftk option to add
$argument string | File | null the argument to add, either string, File instance or null if none
return Command the command instance for method chaining

addPageRange() public method

Add a page range as used by some operations
public addPageRange ( integer | string | array $start, integer | string | null $end = null, string | null $handle = null, string | null $qualifier = null, string $rotation = null ) : Command
$start integer | string | array the start page number or an array of page numbers. If an array, the other arguments will be ignored. $start can also be bigger than $end for pages in reverse order.
$end integer | string | null the end page number or null for single page (or list if $start is an array)
$handle string | null the handle of the file to use. Can be null if only a single file was added.
$qualifier string | null the page number qualifier, either 'even' or 'odd' or null for none
$rotation string the rotation to apply to the pages.
return Command the command instance for method chaining

checkExecutionStatus() protected method

Ensure that the command was not exectued yet. Throws exception otherwise.
protected checkExecutionStatus ( )

execute() public method

public execute ( string | null $filename = null ) : boolean
$filename string | null the filename to add as 'output' option or null if none
return boolean whether the command was executed successfully

getFileCount() public method

public getFileCount ( ) : integer
return integer the number of files added to the command

getOperation() public method

public getOperation ( ) : string | null
return string | null the current operation or null if none set

getOperationArgument() public method

public getOperationArgument ( ) : string | array | null
return string | array | null the current operation argument as string or array or null if none set

processInputFiles() protected method

Process input PDF files and create respective command arguments
protected processInputFiles ( )

processOperation() protected method

Process opearation and create respective command arguments
protected processOperation ( )

processOptions() protected method

Process options and create respective command arguments
protected processOptions ( string | null $filename = null )
$filename string | null if provided an 'output' option will be added

setOperation() public method

public setOperation ( string $operation ) : Command
$operation string the operation to perform
return Command the command instance for method chaining

setOperationArgument() public method

public setOperationArgument ( string $value, boolean $escape = false ) : Command
$value string the operation argument
$escape boolean whether to escape the operation argument
return Command the command instance for method chaining

Property Details

$_command protected_oe property

the pdftk binary
protected $_command

$_escapeOperationArgument protected_oe property

whether to force escaping of the operation argument e.g. for filenames
protected $_escapeOperationArgument

$_files protected_oe property

list of input files to process as array('name' => $filename, 'password' => $pw) indexed by handle
protected $_files

$_operation protected_oe property

the operation to perform
protected $_operation

$_operationArgument protected_oe property

operation arguments, e.g. a list of page ranges or a filename or tmp file instance
protected $_operationArgument

$_options protected_oe property

list of command options, either strings or array with arguments to addArg()
protected $_options