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 {@link Frame} object to each node. {@link Frame} objects store positioning and layout information and each has a reference to a {@link Style} object.
Style information is loaded and parsed (see {@link Stylesheet}) and is applied to the frames in the tree by using XPath. CSS selectors are converted into XPath queries, and the computed {@link Style} objects are applied to the {@link Frame}s.
{@link Frame}s are then decorated (in the design pattern sense of the word) based on their CSS display property ({@link http://www.w3.org/TR/CSS21/visuren.html#propdef-display}). Frame_Decorators augment the basic {@link Frame} class by adding additional properties and methods specific to the particular type of {@link Frame}. 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 {@link Frame}s to lines and to add additional lines. {@link Frame}s also are attached to specific AbstractPositioner and {@link AbstractFrameReflower} 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 {@link Frame} 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. {@link Frame}s are rendered using an adapted {@link Cpdf} class, originally written by Wayne Munro, http://www.ros.co.nz/pdf/. (Some performance related changes have been made to the original {@link Cpdf} class, and the {@link Dompdf\Adapter\CPDF} class provides a simple, stateless interface to PDF generation.) PDFLib support has now also been added, via the {@link Dompdf\Adapter\PDFLib}.
| Methods | ||
|---|---|---|
public
|
__construct(Options|array|null $options = null)
|
# |
private
|
setPhpConfig()
|
# |
private
|
restorePhpConfig()
|
# |
public
|
load_html_file($file)
|
# |
public
|
loadHtmlFile(string $file, string $encoding = null)
|
# |
public
|
load_html(string $str, string $encoding = null)
|
# |
public
|
loadDOM($doc, $quirksmode = false)
|
# |
public
|
loadHtml(string $str, string $encoding = null)
|
# |
public
static
|
remove_text_nodes(DOMNode $node)
|
# |
public
static
|
removeTextNodes(DOMNode $node)
|
# |
private
|
processHtml()
|
# |
public
|
enable_caching(string $cacheId)
|
# |
public
|
enableCaching(string $cacheId)
|
# |
public
|
parse_default_view(string $value): bool
|
# |
public
|
parseDefaultView(string $value): bool
|
# |
public
|
render()
|
# |
private
|
writeLog(string $logOutputFile, float $startTime): void
|
# |
public
|
add_info($label, $value)
|
# |
public
|
addInfo(string $label, string $value): void
|
# |
public
|
stream(string $filename = "document.pdf", array $options = [])
|
# |
public
|
output(array $options = []): string|null
|
# |
public
|
output_html(): string
|
# |
public
|
outputHtml(): string
|
# |
public
|
get_option(string $key): mixed
|
# |
public
|
set_option(string $key, mixed $value): $this
|
# |
public
|
set_options(array $options): $this
|
# |
public
|
set_paper(string $size, string $orientation = "portrait")
|
# |
public
|
setPaper(string|float[] $size, string $orientation = "portrait"): $this
|
# |
public
|
getPaperSize(): float[]
|
# |
public
|
getPaperOrientation(): string
|
# |
public
|
setTree(FrameTree $tree): $this
|
# |
public
|
get_tree(): FrameTree
|
# |
public
|
getTree(): FrameTree
|
# |
public
|
set_protocol(string $protocol): $this
|
# |
public
|
setProtocol(string $protocol): $this
|
# |
public
|
get_protocol(): string
|
# |
public
|
getProtocol(): string
|
# |
public
|
set_host(string $host)
|
# |
public
|
setBaseHost(string $baseHost): $this
|
# |
public
|
get_host(): string
|
# |
public
|
getBaseHost(): string
|
# |
public
|
set_base_path(string $path)
|
# |
public
|
setBasePath(string $basePath): $this
|
# |
public
|
get_base_path(): string
|
# |
public
|
getBasePath(): string
|
# |
public
|
set_default_view(string $default_view, array $options): $this
|
# |
public
|
setDefaultView(string $defaultView, array $options): $this
|
# |
public
|
set_http_context(resource $http_context): $this
|
# |
public
|
setHttpContext(resource|array $httpContext): $this
|
# |
public
|
get_http_context(): resource
|
# |
public
|
getHttpContext(): resource
|
# |
public
|
setCanvas(Canvas $canvas): $this
|
# |
public
|
get_canvas(): Canvas
|
# |
public
|
getCanvas(): Canvas
|
# |
public
|
setCss(Stylesheet $css): $this
|
# |
public
|
get_css(): Stylesheet
|
# |
public
|
getCss(): Stylesheet
|
# |
public
|
setDom(DOMDocument $dom): $this
|
# |
public
|
get_dom(): DOMDocument
|
# |
public
|
getDom(): DOMDocument
|
# |
public
|
setOptions(Options $options): $this
|
# |
public
|
getOptions(): Options
|
# |
public
|
get_callbacks(): array
|
# |
public
|
getCallbacks(): array
|
# |
public
|
set_callbacks(array $callbacks): $this
|
# |
public
|
setCallbacks(array $callbacks): $this
|
# |
public
|
get_quirksmode(): boolean
|
# |
public
|
getQuirksmode(): boolean
|
# |
public
|
setFontMetrics(FontMetrics $fontMetrics): $this
|
# |
public
|
getFontMetrics(): FontMetrics
|
# |
public
|
__get(string $prop): mixed
|
# |
| Properties | |||
|---|---|---|---|
private
|
string
|
$version = 'dompdf'
|
# |
private
|
DOMDocument
|
$dom
|
# |
private
|
FrameTree
|
$tree
|
# |
private
|
Stylesheet
|
$css
|
# |
private
|
Canvas
|
$canvas
|
# |
private
|
string|float[]
|
$paperSize
|
# |
private
|
string
|
$paperOrientation = "portrait"
|
# |
private
|
array
|
$callbacks = []
|
# |
private
|
string
|
$cacheId
|
# |
private
|
string
|
$baseHost = ""
|
# |
private
|
string
|
$basePath = ""
|
# |
private
|
string
|
$protocol = ""
|
# |
private
|
string
|
$systemLocale = null
|
# |
private
|
string
|
$mbstringEncoding = null
|
# |
private
|
string
|
$pcreJit = null
|
# |
private
|
string
|
$defaultView = "Fit"
|
# |
private
|
array
|
$defaultViewOptions = []
|
# |
private
|
bool
|
$quirksmode = false
|
# |
private
|
array
|
$allowedLocalFileExtensions = ["htm", "html"]
|
# |
private
|
array
|
$messages = []
|
# |
private
|
Options
|
$options
|
# |
private
|
FontMetrics
|
$fontMetrics
|
# |
public
static
|
array
|
$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",
]
|
# |
public
static
|
array
|
$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",
]
|
# |