PHP Класс mikehaertl\wkhtmlto\Pdf

This class is a slim wrapper around wkhtmltopdf.
Автор: Michael Härtl ([email protected])
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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)

Свойство Тип Описание
$_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

Открытые методы

Метод Описание
__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).

Защищенные методы

Метод Описание
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

Описание методов

__construct() публичный метод

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

addCover() публичный метод

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.
Результат static the Pdf instance for method chaining

addPage() публичный метод

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.
Результат static the Pdf instance for method chaining

addToc() публичный метод

Add a TOC object to the output
public addToc ( array $options = [] ) : static
$options array optional options for the table of contents
Результат static the Pdf instance for method chaining

createPdf() защищенный метод

Run the Command to create the tmp PDF file
protected createPdf ( ) : boolean
Результат boolean whether creation was successful

getCommand() публичный метод

public getCommand ( ) : Command
Результат Command the command instance that executes wkhtmltopdf

getError() публичный метод

public getError ( ) : string
Результат string the detailed error message. Empty string if none.

getPdfFilename() публичный метод

public getPdfFilename ( ) : string
Результат string the filename of the temporary PDF file

processInput() защищенный метод

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.
Результат mikehaertl\tmp\File | string a File object if the input is a HTML or XML string. The unchanged input otherwhise.

processOptions() защищенный метод

protected processOptions ( array $options = [] ) : array
$options array list of options as name/value pairs
Результат array options with raw content converted to tmp files where neccessary

saveAs() публичный метод

Save the PDF to given filename (triggers PDF creation)
public saveAs ( string $filename ) : boolean
$filename string to save PDF as
Результат boolean whether PDF was created successfully

send() публичный метод

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.
Результат boolean whether PDF was created successfully

setOptions() публичный метод

Set global option(s)
public setOptions ( array $options = [] ) : static
$options array list of global PDF options to set as name/value pairs
Результат static the Pdf instance for method chaining

toString() публичный метод

Get the raw PDF contents (triggers PDF creation).
public toString ( ) : string | boolean
Результат string | boolean The PDF content as a string or `false` if the PDF wasn't created successfully.

Описание свойств

$_command защищенное свойство

the command instance that executes wkhtmltopdf
protected $_command

$_error защищенное свойство

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

$_isCreated защищенное свойство

whether the PDF was created
protected $_isCreated

$_objects защищенное свойство

list of wkhtmltopdf objects as arrays
protected $_objects

$_options защищенное свойство

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

$_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.
protected $_tmpFiles

$_tmpPdfFile защищенное свойство

the temporary PDF file
protected $_tmpPdfFile

$binary публичное свойство

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

$commandOptions публичное свойство

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

$ignoreWarnings публичное свойство

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

$tmpDir публичное свойство

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

$version9 публичное свойство

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