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