dompdf is an HTML to PDF converter, requires PHP 5.0+ (5.3 recommended). This class is useful when you want to create PDF files with PHP.
Just create the content in HTML format, then use dompdf class to create PDF file(s) with that content.
- Download dompdf 0.6.0 beta 3.

Features:

- Handles most CSS 2.1 and a few CSS3 properties, including @import, @media & @page rules (CSS float is not supported).
- Supports most presentational HTML 4.0 attributes.
- Supports external stylesheets, either local or through http/ftp (via fopen-wrappers).
- Supports complex tables, including row & column spans, separate & collapsed border models, individual cell styling image support (gif, png (8, 24 and 32 bit with alpha channel), bmp & jpeg).

Example, create and save a PDF document from a HTML document defined directly in PHP.
<?php
include('dompdf/dompdf_config.inc.php');

$savein = 'pdfdir/';       // directory in which to save the PDF file

// the HTML content
$html = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ro">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Free Courses: http://coursesweb.net</title>
<style type="text/css">
body {
 padding:1px 22px;
 text-align:center;
}
h1 {
 margin:3px auto;
 font-size:18px;
 color:blue;
}
p {
 background:#fefeda;
 text-indent:20px;
 text-align:left;
}
a {
 border:1px dotted #01da02;
 font-size:13px;
 padding:4px;
}
</style>
<body>
 <h1>Free Courses for Web Development</h1>
 <a href="http://coursesweb.net/" title="Free Programming Courses">Free Programming Courses</a>
 <p>Put your html here, or generate it with your favourite templating system.</p>
 <img src="image.jpg" width="130" height="80" alt="Web Programming" />
</body></html>';

// uses dompdf class to create the PDF file, save it and streams the file
$dompdf = new DOMPDF();
$dompdf->load_html($html);            // Loads the HTML string
$dompdf->render();                    // Renders the HTML to PDF

$pdf = $dompdf->output();             // gets the PDF as a string
file_put_contents(($savein.'file.pdf'), $pdf);           // save the pdf file on server

$dompdf->stream('file.pdf');      // Streams the PDF to the client. Will open a download dialog by default
?>

- To see the result, click: PDF file.


Another example. The PDF document is generated on the fly by dompdf. The HTML content is loaded from an external file.
<?php
include('dompdf/dompdf_config.inc.php');

$html = file_get_contents('file.html');          // gets the HTML content as a string

// uses dompdf class to create the PDF file, and streams the file
$dompdf = new DOMPDF();
$dompdf->load_html($html);              // Loads the HTML string
$dompdf->render();                      // Renders the HTML to PDF
$dompdf->stream('file.pdf');      // Streams the PDF to the client. Will open a download dialog by default
?>

If you want to use the HTML content from an external file, is better to not use load_html_file() (because can cause error /problems due to a security enhancement implemented); load the file into a variable using the PHP function file_get_contents().

- In the archive with dompdf class you'll find more examples, and documentation (in "www" directory, accessed from server).
dompdf Web Site.

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which tag is a block element?
<div> <img> <span>
<div>Web Programming and Development</div>
Which CSS code displays the text underlined?
font-style: italic; text-decoration: underline; font-weight: 500;
h2 {
  text-decoration: underline;
}
Click on the JavaScript function that can access other function after a specified time.
insertBefore() setTimeout() querySelector()
function someFunction() { alert("CoursesWeb.net"); }
setTimeout("someFunction()", 2000);
Click on the instruction that returns the number of items of a multidimensional array in PHP.
count($array) count($array, 1) strlen()
$food = array("fruits" => array("banana", "apple"), "veggie" => array("collard", "pea"));
$nr_food = count($food, 1);
echo $nr_food;       // 6
dompdf

Last accessed pages

  1. innerHTML and outerHTML to Get and Replace HTML content (10944)
  2. Convert JSON in JavaScript (4542)
  3. Upload Script for Gallery of Images and Audio files (6282)
  4. Drag Racer V3 (2302)
  5. Butterfly Kyodai (13820)

Top accessed pages

  1. Courses Web: PHP-MySQL JavaScript Ajax HTML CSS Flash-AS3 (50906)
  2. Read Excel file data in PHP - PhpExcelReader (39764)
  3. PHP-MySQL free course, online tutorials PHP MySQL code (37936)
  4. Get Attribute (ID, Class, Name, Title, Src) with jQuery (34200)
  5. PHP PDO - exec (INSERT, UPDATE, DELETE) MySQL (31686)