PHP Class mikehaertl\wkhtmlto\Pdf

This class is a slim wrapper around wkhtmltopdf.
Author: Michael Härtl ([email protected])
Afficher le fichier Open project: mikehaertl/phpwkhtmltopdf Class Usage Examples

Méthodes publiques

Свойство Type Description
$binary the name of the wkhtmltopdf binary. Default is wkhtmltopdf. You can also configure a full path here.
$commandOptions options to pass to the Command constructor. Default is none.
$ignoreWarnings whether to ignore any errors if some PDF file was still created. Default is false.
$tmpDir the directory to use for temporary files. If null (default) the dir is autodetected.
$version9 whether the old version 9 of wkhtmltopdf is used (slightly different syntax). Default is false.

Protected Properties

Свойство Type Description
$_command the command instance that executes wkhtmltopdf
$_error the detailed error message. Empty string if none.
$_isCreated whether the PDF was created
$_objects list of wkhtmltopdf objects as arrays
$_options global options for wkhtmltopdf as array('--opt1', '--opt2'=>'val', ...)
$_tmpFiles list of tmp file objects. This is here to keep a reference to File and thus avoid too early call of File::__destruct() if the file is not referenced anymore.
$_tmpPdfFile the temporary PDF file

Méthodes publiques

Méthode Description
__construct ( array | string $options = null )
addCover ( string $input, array $options = [], string | null $type = null ) : static Add a cover page object to the output
addPage ( string $input, array $options = [], string | null $type = null ) : static Add a page object to the output
addToc ( array $options = [] ) : static Add a TOC object to the output
getCommand ( ) : Command
getError ( ) : string
getPdfFilename ( ) : string
saveAs ( string $filename ) : boolean Save the PDF to given filename (triggers PDF creation)
send ( string | null $filename = null, boolean $inline = false ) : boolean Send PDF to client, either inline or as download (triggers PDF creation)
setOptions ( array $options = [] ) : static Set global option(s)
toString ( ) : string | boolean Get the raw PDF contents (triggers PDF creation).

Méthodes protégées

Méthode Description
createPdf ( ) : boolean Run the Command to create the tmp PDF file
processInput ( string $input, string | null $type = null ) : mikehaertl\tmp\File | string
processOptions ( array $options = [] ) : array

Method Details

__construct() public méthode

public __construct ( array | string $options = null )
$options array | string global options for wkhtmltopdf, a page URL, a HTML string or a filename

addCover() public méthode

Add a cover page object to the output
public addCover ( string $input, array $options = [], string | null $type = null ) : static
$input string either a URL, a HTML string or a filename
$options array optional options for the cover page
$type string | null a type hint if the input is a string of known type. This can either be `TYPE_HTML` or `TYPE_XML`. If `null` (default) the type is auto detected from the string content.
Résultat static the Pdf instance for method chaining

addPage() public méthode

Add a page object to the output
public addPage ( string $input, array $options = [], string | null $type = null ) : static
$input string either a URL, a HTML string or a filename
$options array optional options for this page
$type string | null a type hint if the input is a string of known type. This can either be `TYPE_HTML` or `TYPE_XML`. If `null` (default) the type is auto detected from the string content.
Résultat static the Pdf instance for method chaining

addToc() public méthode

Add a TOC object to the output
public addToc ( array $options = [] ) : static
$options array optional options for the table of contents
Résultat static the Pdf instance for method chaining

createPdf() protected méthode

Run the Command to create the tmp PDF file
protected createPdf ( ) : boolean
Résultat boolean whether creation was successful

getCommand() public méthode

public getCommand ( ) : Command
Résultat Command the command instance that executes wkhtmltopdf

getError() public méthode

public getError ( ) : string
Résultat string the detailed error message. Empty string if none.

getPdfFilename() public méthode

public getPdfFilename ( ) : string
Résultat string the filename of the temporary PDF file

processInput() protected méthode

protected processInput ( string $input, string | null $type = null ) : mikehaertl\tmp\File | string
$input string
$type string | null a type hint if the input is a string of known type. This can either be `TYPE_HTML` or `TYPE_XML`. If `null` (default) the type is auto detected from the string content.
Résultat mikehaertl\tmp\File | string a File object if the input is a HTML or XML string. The unchanged input otherwhise.

processOptions() protected méthode

protected processOptions ( array $options = [] ) : array
$options array list of options as name/value pairs
Résultat array options with raw content converted to tmp files where neccessary

saveAs() public méthode

Save the PDF to given filename (triggers PDF creation)
public saveAs ( string $filename ) : boolean
$filename string to save PDF as
Résultat boolean whether PDF was created successfully

send() public méthode

Send PDF to client, either inline or as download (triggers PDF creation)
public send ( string | null $filename = null, boolean $inline = false ) : boolean
$filename string | null the filename to send. If empty, the PDF is streamed inline.
$inline boolean whether to force inline display of the PDF, even if filename is present.
Résultat boolean whether PDF was created successfully

setOptions() public méthode

Set global option(s)
public setOptions ( array $options = [] ) : static
$options array list of global PDF options to set as name/value pairs
Résultat static the Pdf instance for method chaining

toString() public méthode

Get the raw PDF contents (triggers PDF creation).
public toString ( ) : string | boolean
Résultat string | boolean The PDF content as a string or `false` if the PDF wasn't created successfully.

Property Details

$_command protected_oe property

the command instance that executes wkhtmltopdf
protected $_command

$_error protected_oe property

the detailed error message. Empty string if none.
protected $_error

$_isCreated protected_oe property

whether the PDF was created
protected $_isCreated

$_objects protected_oe property

list of wkhtmltopdf objects as arrays
protected $_objects

$_options protected_oe property

global options for wkhtmltopdf as array('--opt1', '--opt2'=>'val', ...)
protected $_options

$_tmpFiles protected_oe property

list of tmp file objects. This is here to keep a reference to File and thus avoid too early call of File::__destruct() if the file is not referenced anymore.
protected $_tmpFiles

$_tmpPdfFile protected_oe property

the temporary PDF file
protected $_tmpPdfFile

$binary public_oe property

the name of the wkhtmltopdf binary. Default is wkhtmltopdf. You can also configure a full path here.
public $binary

$commandOptions public_oe property

options to pass to the Command constructor. Default is none.
public $commandOptions

$ignoreWarnings public_oe property

whether to ignore any errors if some PDF file was still created. Default is false.
public $ignoreWarnings

$tmpDir public_oe property

the directory to use for temporary files. If null (default) the dir is autodetected.
public $tmpDir

$version9 public_oe property

whether the old version 9 of wkhtmltopdf is used (slightly different syntax). Default is false.
public $version9