Documentation

Dompdf
in package

Dompdf - PHP5 HTML to PDF renderer

Dompdf loads HTML and does its best to render it as a PDF. It gets its name from the new DomDocument PHP5 extension. Source HTML is first parsed by a DomDocument object. Dompdf takes the resulting DOM tree and attaches a object to each node. objects store positioning and layout information and each has a reference to a object.

Style information is loaded and parsed (see ) and is applied to the frames in the tree by using XPath. CSS selectors are converted into XPath queries, and the computed objects are applied to the s.

s are then decorated (in the design pattern sense of the word) based on their CSS display property (). Frame_Decorators augment the basic class by adding additional properties and methods specific to the particular type of . For example, in the CSS layout model, block frames (display: block;) contain line boxes that are usually filled with text or other inline frames. The Block therefore adds a $lines property as well as methods to add s to lines and to add additional lines. s also are attached to specific AbstractPositioner and objects that contain the positioining and layout algorithm for a specific type of frame, respectively. This is an application of the Strategy pattern.

Layout, or reflow, proceeds recursively (post-order) starting at the root of the document. Space constraints (containing block width & height) are pushed down, and resolved positions and sizes bubble up. Thus, every in the document tree is traversed once (except for tables which use a two-pass layout algorithm). If you are interested in the details, see the reflow() method of the Reflower classes.

Rendering is relatively straightforward once layout is complete. s are rendered using an adapted class, originally written by Wayne Munro, http://www.ros.co.nz/pdf/. (Some performance related changes have been made to the original class, and the class provides a simple, stateless interface to PDF generation.) PDFLib support has now also been added, via the .

Table of Contents

$native_fonts  : array<string|int, mixed>
The list of built-in fonts
$nativeFonts  : array<string|int, mixed>
The list of built-in fonts
$allowedLocalFileExtensions  : array<string|int, mixed>
Local file extension whitelist
$allowedProtocols  : array<string|int, mixed>
Protocol whitelist
$baseHost  : string
Base hostname
$basePath  : string
Absolute base path
$cacheId  : string
Experimental caching capability
$callbacks  : array<string|int, mixed>
Callbacks on new page and new element
$canvas  : Canvas
Actual PDF renderer
$css  : Stylesheet
Stylesheet for the document
$defaultView  : string
The default view of the PDF in the viewer
$defaultViewOptions  : array<string|int, mixed>
The default view options of the PDF in the viewer
$dom  : DOMDocument
DomDocument representing the HTML document
$fontMetrics  : FontMetrics
$httpContext  : resource
HTTP context created with stream_context_create() Will be used for file_get_contents
$localeStandard  : bool
Tells if the system's locale is the C standard one
$messages  : array<string|int, mixed>
$options  : Options
$paperOrientation  : string
Paper orientation ('portrait' or 'landscape')
$paperSize  : string|array<string|int, mixed>
Desired paper size ('letter', 'legal', 'A4', etc.)
$protocol  : string
Protocol used to request file (file://, http://, etc)
$quirksmode  : bool
Tells whether the DOM document is in quirksmode (experimental)
$startTime  : int
Timestamp of the script start time
$systemLocale  : string
The system's locale
$tree  : FrameTree
FrameTree derived from the DOM tree
$version  : string
Version string for dompdf
__construct()  : mixed
Class constructor
__get()  : mixed
PHP5 overloaded getter Along with {@link Dompdf::__set()} __get() provides access to all properties directly. Typically __get() is not called directly outside of this class.
add_info()  : mixed
Add meta information to the PDF after rendering
enable_caching()  : mixed
enableCaching()  : mixed
Enable experimental caching capability
get_base_path()  : string
get_callbacks()  : array<string|int, mixed>
get_canvas()  : Canvas
get_css()  : Stylesheet
get_dom()  : DOMDocument
get_host()  : string
get_http_context()  : resource
get_option()  : mixed
Get the dompdf option value
get_protocol()  : string
get_quirksmode()  : bool
get_tree()  : FrameTree
getBaseHost()  : string
Returns the base hostname
getBasePath()  : string
Returns the base path
getCallbacks()  : array<string|int, mixed>
Returns the callbacks array
getCanvas()  : Canvas
Return the underlying Canvas instance (e.g. Dompdf\Adapter\CPDF, Dompdf\Adapter\GD)
getCss()  : Stylesheet
Returns the stylesheet
getDom()  : DOMDocument
getFontMetrics()  : FontMetrics
getHttpContext()  : resource
Returns the HTTP context
getOptions()  : Options
getPaperOrientation()  : string
Gets the paper orientation
getPaperSize()  : array<string|int, int>
Gets the paper size
getProtocol()  : string
Returns the protocol in use
getQuirksmode()  : bool
Get the quirks mode
getTree()  : FrameTree
Returns the underlying {@link FrameTree} object
load_html()  : mixed
load_html_file()  : mixed
loadDOM()  : mixed
loadHtml()  : mixed
Loads an HTML string Parse errors are stored in the global array _dompdf_warnings.
loadHtmlFile()  : mixed
Loads an HTML file Parse errors are stored in the global array _dompdf_warnings.
output()  : string|null
Returns the PDF as a string.
output_html()  : string
outputHtml()  : string
Returns the underlying HTML document as a string
parse_default_view()  : bool
parseDefaultView()  : bool
remove_text_nodes()  : mixed
removeTextNodes()  : mixed
render()  : mixed
Renders the HTML to PDF
set_base_path()  : mixed
Sets the base path
set_callbacks()  : mixed
set_default_view()  : $this
set_host()  : mixed
set_http_context()  : $this
set_option()  : $this
set_options()  : $this
set_paper()  : mixed
set_protocol()  : $this
setBaseHost()  : $this
Sets the base hostname
setBasePath()  : $this
Sets the base path
setCallbacks()  : mixed
Sets callbacks for events like rendering of pages and elements.
setCanvas()  : $this
setCss()  : $this
setDefaultView()  : $this
Sets the default view
setDom()  : $this
setFontMetrics()  : $this
setHttpContext()  : $this
Sets the HTTP context
setOptions()  : $this
setPaper()  : $this
Sets the paper size & orientation
setProtocol()  : $this
Sets the protocol to use FIXME validate these
setTree()  : $this
stream()  : mixed
Streams the PDF to the client.
processHtml()  : mixed
Builds the {@link FrameTree}, loads any CSS and applies the styles to the {@link FrameTree}
restoreLocale()  : mixed
Restore the system's locale configuration
saveLocale()  : mixed
Save the system's locale configuration and set the right value for numeric formatting
write_log()  : void
Writes the output buffer in the log file

Properties

$native_fonts

The list of built-in fonts

public static array<string|int, mixed> $native_fonts = ["courier", "courier-bold", "courier-oblique", "courier-boldoblique", "helvetica", "helvetica-bold", "helvetica-oblique", "helvetica-boldoblique", "times-roman", "times-bold", "times-italic", "times-bolditalic", "symbol", "zapfdinbats"]
Tags
deprecated

$nativeFonts

The list of built-in fonts

public static array<string|int, mixed> $nativeFonts = ["courier", "courier-bold", "courier-oblique", "courier-boldoblique", "helvetica", "helvetica-bold", "helvetica-oblique", "helvetica-boldoblique", "times-roman", "times-bold", "times-italic", "times-bolditalic", "symbol", "zapfdinbats"]

$allowedLocalFileExtensions

Local file extension whitelist

private array<string|int, mixed> $allowedLocalFileExtensions = ["htm", "html"]

File extensions supported by dompdf for local files.

$allowedProtocols

Protocol whitelist

private array<string|int, mixed> $allowedProtocols = [null, "", "file://", "http://", "https://"]

Protocols and PHP wrappers allowed in URLs. Full support is not guaranteed for the protocols/wrappers contained in this array.

$baseHost

Base hostname

private string $baseHost = ""

Used for relative paths/urls

$basePath

Absolute base path

private string $basePath = ""

Used for relative paths/urls

$cacheId

Experimental caching capability

private string $cacheId

$callbacks

Callbacks on new page and new element

private array<string|int, mixed> $callbacks = []

$defaultView

The default view of the PDF in the viewer

private string $defaultView = "Fit"

$defaultViewOptions

The default view options of the PDF in the viewer

private array<string|int, mixed> $defaultViewOptions = []

$dom

DomDocument representing the HTML document

private DOMDocument $dom

$httpContext

HTTP context created with stream_context_create() Will be used for file_get_contents

private resource $httpContext

$localeStandard

Tells if the system's locale is the C standard one

private bool $localeStandard = false

$messages

private array<string|int, mixed> $messages = []

$paperOrientation

Paper orientation ('portrait' or 'landscape')

private string $paperOrientation = "portrait"

$paperSize

Desired paper size ('letter', 'legal', 'A4', etc.)

private string|array<string|int, mixed> $paperSize

$protocol

Protocol used to request file (file://, http://, etc)

private string $protocol

$quirksmode

Tells whether the DOM document is in quirksmode (experimental)

private bool $quirksmode = false

$startTime

Timestamp of the script start time

private int $startTime = null

$systemLocale

The system's locale

private string $systemLocale = null

$version

Version string for dompdf

private string $version = 'dompdf'

Methods

__construct()

Class constructor

public __construct([array<string|int, mixed>|Options $options = null ]) : mixed
Parameters
$options : array<string|int, mixed>|Options = null
Return values
mixed

__get()

PHP5 overloaded getter Along with {@link Dompdf::__set()} __get() provides access to all properties directly. Typically __get() is not called directly outside of this class.

public __get(string $prop) : mixed
Parameters
$prop : string
Tags
throws
Exception
Return values
mixed

add_info()

Add meta information to the PDF after rendering

public add_info(mixed $label, mixed $value) : mixed
Parameters
$label : mixed
$value : mixed
Return values
mixed

enable_caching()

public enable_caching(string $cacheId) : mixed
Parameters
$cacheId : string
Tags
deprecated
Return values
mixed

enableCaching()

Enable experimental caching capability

public enableCaching(string $cacheId) : mixed
Parameters
$cacheId : string
Return values
mixed

get_base_path()

public get_base_path() : string
Tags
deprecated
Return values
string

get_callbacks()

public get_callbacks() : array<string|int, mixed>
Tags
deprecated
Return values
array<string|int, mixed>

get_dom()

public get_dom() : DOMDocument
Tags
deprecated
Return values
DOMDocument

get_host()

public get_host() : string
Tags
deprecated
Return values
string

get_http_context()

public get_http_context() : resource
Tags
deprecated
Return values
resource

get_option()

Get the dompdf option value

public get_option(string $key) : mixed
Parameters
$key : string
Tags
deprecated
Return values
mixed

get_protocol()

public get_protocol() : string
Tags
deprecated
Return values
string

get_quirksmode()

public get_quirksmode() : bool
Tags
deprecated
Return values
bool

getBaseHost()

Returns the base hostname

public getBaseHost() : string
Return values
string

getBasePath()

Returns the base path

public getBasePath() : string
Return values
string

getCallbacks()

Returns the callbacks array

public getCallbacks() : array<string|int, mixed>
Return values
array<string|int, mixed>

getCanvas()

Return the underlying Canvas instance (e.g. Dompdf\Adapter\CPDF, Dompdf\Adapter\GD)

public getCanvas() : Canvas
Return values
Canvas

getDom()

public getDom() : DOMDocument
Return values
DOMDocument

getHttpContext()

Returns the HTTP context

public getHttpContext() : resource
Return values
resource

getPaperOrientation()

Gets the paper orientation

public getPaperOrientation() : string
Return values
string

Either "portrait" or "landscape"

getPaperSize()

Gets the paper size

public getPaperSize([null|string|array<string|int, mixed> $paperSize = null ]) : array<string|int, int>
Parameters
$paperSize : null|string|array<string|int, mixed> = null
Return values
array<string|int, int>

A four-element integer array

getProtocol()

Returns the protocol in use

public getProtocol() : string
Return values
string

getQuirksmode()

Get the quirks mode

public getQuirksmode() : bool
Return values
bool

true if quirks mode is active

load_html()

public load_html(string $str[, string $encoding = null ]) : mixed
Parameters
$str : string
$encoding : string = null
Tags
deprecated
Return values
mixed

load_html_file()

public load_html_file( $file) : mixed
Parameters
$file :
Tags
deprecated
Return values
mixed

loadDOM()

public loadDOM(mixed $doc[, mixed $quirksmode = false ]) : mixed
Parameters
$doc : mixed
$quirksmode : mixed = false
Return values
mixed

loadHtml()

Loads an HTML string Parse errors are stored in the global array _dompdf_warnings.

public loadHtml(string $str[, string $encoding = null ]) : mixed
Parameters
$str : string

HTML text to load

$encoding : string = null

Encoding of $str

Return values
mixed

loadHtmlFile()

Loads an HTML file Parse errors are stored in the global array _dompdf_warnings.

public loadHtmlFile(string $file[, string $encoding = null ]) : mixed
Parameters
$file : string

a filename or url to load

$encoding : string = null

Encoding of $file

Tags
throws
Exception
Return values
mixed

output()

Returns the PDF as a string.

public output([array<string|int, mixed> $options = [] ]) : string|null

The options parameter controls the output. Accepted options are:

'compress' = > 1 or 0 - apply content stream compression, this is on (1) by default

Parameters
$options : array<string|int, mixed> = []

options (see above)

Return values
string|null

output_html()

public output_html() : string
Tags
deprecated
Return values
string

outputHtml()

Returns the underlying HTML document as a string

public outputHtml() : string
Return values
string

parse_default_view()

public parse_default_view(string $value) : bool
Parameters
$value : string
Tags
deprecated
Return values
bool

parseDefaultView()

public parseDefaultView(string $value) : bool
Parameters
$value : string
Return values
bool

remove_text_nodes()

public static remove_text_nodes(DOMNode $node) : mixed
Parameters
$node : DOMNode
Tags
deprecated
Return values
mixed

removeTextNodes()

public static removeTextNodes(DOMNode $node) : mixed
Parameters
$node : DOMNode
Return values
mixed

render()

Renders the HTML to PDF

public render() : mixed
Return values
mixed

set_base_path()

Sets the base path

public set_base_path(string $path) : mixed
Parameters
$path : string
Tags
deprecated
Return values
mixed

set_callbacks()

public set_callbacks(array<string|int, mixed> $callbacks) : mixed
Parameters
$callbacks : array<string|int, mixed>

the set of callbacks to set

Tags
deprecated
Return values
mixed

set_default_view()

public set_default_view(string $default_view, array<string|int, mixed> $options) : $this
Parameters
$default_view : string

The default document view

$options : array<string|int, mixed>

The view's options

Tags
deprecated
Return values
$this

set_host()

public set_host(string $host) : mixed
Parameters
$host : string
Tags
deprecated
Return values
mixed

set_http_context()

public set_http_context(resource $http_context) : $this
Parameters
$http_context : resource
Tags
deprecated
Return values
$this

set_option()

public set_option(string $key, mixed $value) : $this
Parameters
$key : string
$value : mixed
Tags
deprecated
Return values
$this

set_options()

public set_options(array<string|int, mixed> $options) : $this
Parameters
$options : array<string|int, mixed>
Tags
deprecated
Return values
$this

set_paper()

public set_paper(string $size[, string $orientation = "portrait" ]) : mixed
Parameters
$size : string
$orientation : string = "portrait"
Tags
deprecated
Return values
mixed

set_protocol()

public set_protocol(string $protocol) : $this
Parameters
$protocol : string
Tags
deprecated
Return values
$this

setBaseHost()

Sets the base hostname

public setBaseHost(string $baseHost) : $this
Parameters
$baseHost : string
Return values
$this

setBasePath()

Sets the base path

public setBasePath(string $basePath) : $this
Parameters
$basePath : string
Return values
$this

setCallbacks()

Sets callbacks for events like rendering of pages and elements.

public setCallbacks(array<string|int, mixed> $callbacks) : mixed

The callbacks array contains arrays with 'event' set to 'begin_page', 'end_page', 'begin_frame', or 'end_frame' and 'f' set to a function or object plus method to be called.

The function 'f' must take an array as argument, which contains info about the event.

Parameters
$callbacks : array<string|int, mixed>

the set of callbacks to set

Return values
mixed

setCanvas()

public setCanvas(Canvas $canvas) : $this
Parameters
$canvas : Canvas
Return values
$this

setDefaultView()

Sets the default view

public setDefaultView(string $defaultView, array<string|int, mixed> $options) : $this
Parameters
$defaultView : string

The default document view

$options : array<string|int, mixed>

The view's options

Return values
$this

setDom()

public setDom(DOMDocument $dom) : $this
Parameters
$dom : DOMDocument
Return values
$this

setHttpContext()

Sets the HTTP context

public setHttpContext(resource $httpContext) : $this
Parameters
$httpContext : resource
Return values
$this

setOptions()

public setOptions(Options $options) : $this
Parameters
$options : Options
Return values
$this

setPaper()

Sets the paper size & orientation

public setPaper(string|array<string|int, mixed> $size[, string $orientation = "portrait" ]) : $this
Parameters
$size : string|array<string|int, mixed>

'letter', 'legal', 'A4', etc.

$orientation : string = "portrait"

'portrait' or 'landscape'

Return values
$this

setProtocol()

Sets the protocol to use FIXME validate these

public setProtocol(string $protocol) : $this
Parameters
$protocol : string
Return values
$this

stream()

Streams the PDF to the client.

public stream([string $filename = "document.pdf" ][, array<string|int, mixed> $options = [] ]) : mixed

The file will open a download dialog by default. The options parameter controls the output. Accepted options (array keys) are:

'compress' = > 1 (=default) or 0: Apply content stream compression

'Attachment' => 1 (=default) or 0: Set the 'Content-Disposition:' HTTP header to 'attachment' (thereby causing the browser to open a download dialog)

Parameters
$filename : string = "document.pdf"

the name of the streamed file

$options : array<string|int, mixed> = []

header options (see above)

Return values
mixed

processHtml()

Builds the {@link FrameTree}, loads any CSS and applies the styles to the {@link FrameTree}

private processHtml() : mixed
Return values
mixed

restoreLocale()

Restore the system's locale configuration

private restoreLocale() : mixed
Return values
mixed

saveLocale()

Save the system's locale configuration and set the right value for numeric formatting

private saveLocale() : mixed
Return values
mixed

write_log()

Writes the output buffer in the log file

private write_log() : void
Return values
void

Search results