Class DOMPDF

Description

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)


	
			
Variable Summary
Method Summary
DOMPDF __construct ()
string get_base_path ()
string get_host ()
string get_protocol ()
void load_html (string $str)
void load_html_file (string $file)
string output ()
void render ()
void set_base_path (string $path)
void set_host (string $host)
void set_paper (string $size, [string $orientation = "portrait"])
void set_protocol (string $proto)
void stream (string $filename)
void _process_html ()
Variables
string $_base_host (line 141)

Base hostname

Used for relative paths/urls

  • access: protected
string $_base_path (line 149)

Absolute base path

Used for relative paths/urls

  • access: protected
Stylesheet $_css (line 110)

Stylesheet for the document

  • access: protected
string $_paper_orientation (line 131)

Paper orientation ('portrait' or 'landscape')

  • access: protected
string $_paper_size (line 124)

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

  • access: protected
Canvas $_pdf (line 117)

Actual PDF renderer

  • access: protected
string $_protocol (line 156)

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

  • access: protected
Frame_Tree $_tree (line 103)

Frame_Tree derived from the DOM tree

  • access: protected
DomDocument $_xml (line 96)

DomDocument representing the HTML document

  • access: protected
Methods
Constructor __construct (line 162)

Class constructor

DOMPDF __construct ()
get_base_path (line 226)

Returns the base path

string get_base_path ()
get_host (line 219)

Returns the base hostname

string get_host ()
get_protocol (line 212)

Returns the protocol in use

string get_protocol ()
get_tree (line 181)

Returns the underlying Frame_Tree object

Frame_Tree get_tree ()
load_html (line 263)

Loads an HTML string

Parse errors are stored in the global array _dompdf_warnings.

void load_html (string $str)
  • string $str: HTML text to load
load_html_file (line 237)

Loads an HTML file

Parse errors are stored in the global array _dompdf_warnings.

void load_html_file (string $file)
  • string $file: a filename or url to load
output (line 427)

Returns the PDF as a string

string output ()
render (line 358)

Renders the HTML to PDF

void render ()
set_base_path (line 205)

Sets the base path

void set_base_path (string $path)
  • string $path
set_host (line 198)

Sets the base hostname

void set_host (string $host)
  • string $host
set_paper (line 338)

Sets the paper size & orientation

void set_paper (string $size, [string $orientation = "portrait"])
set_protocol (line 191)

Sets the protocol to use

void set_protocol (string $proto)
  • string $proto
stream (line 417)

Streams the PDF to the client

The file will always open a download dialog.

void stream (string $filename)
  • string $filename: the name of the streamed file
_process_html (line 283)

Builds the Frame_Tree, loads any CSS and applies the styles to

  • access: protected
void _process_html ()

Documentation generated on Fri, 04 Mar 2005 13:31:17 -0700 by phpDocumentor 1.3.0RC3