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 Frame object to each one. Frame objects store positioning and layout information and each has a reference to a Style object.
Style information is loaded and parsed (see Stylesheet) and is applied to the frames in the tree by using XPath. CSS selectors are converted into XPath queries, and the computed Style objects are applied to the Frames.
Frames are then decorated (in the design pattern sense of the word) based on their CSS display property (http://www.w3.org/TR/CSS21/visuren.html#propdef-display). additional properties and methods specific to the particular type of 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_Frame_Decorator therefore adds a $lines property as well as methods to add Frames to lines and to add additional lines. Frames also are attached to specific Positioner and Reflower 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 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 a Reflower class.
Rendering is relatively straightforward once layout is complete. Frames are rendered using an adapted Cpdf class, originally written by Wayne Munro, http://www.ros.co.nz/pdf/. (Some performance related changes have been made to the original Cpdf class, and the CPDF_Adapter class provides a simple, stateless interface to PDF generation.)
Located in /include/dompdf.cls.php (line 88)
Base hostname
Used for relative paths/urls
Absolute base path
Used for relative paths/urls
Stylesheet for the document
Paper orientation ('portrait' or 'landscape')
Desired paper size ('letter', 'legal', 'A4', etc.)
Actual PDF renderer
Protcol used to request file (file://, http://, etc)
Frame_Tree derived from the DOM tree
DomDocument representing the HTML document
Class constructor
Returns the base path
Returns the base hostname
Returns the protocol in use
Loads an HTML string
Parse errors are stored in the global array _dompdf_warnings.
Loads an HTML file
Parse errors are stored in the global array _dompdf_warnings.
Returns the PDF as a string
Renders the HTML to PDF
Sets the base path
Sets the base hostname
Sets the paper size & orientation
Sets the protocol to use
Streams the PDF to the client
The file will always open a download dialog.
Builds the Frame_Tree, loads any CSS and applies the styles to
the Frame_Tree
Documentation generated on Fri, 04 Mar 2005 13:31:17 -0700 by phpDocumentor 1.3.0RC3