HTML to PDF converter for PHP
This release has been superseded by version 0.8.2
Change highlights since 0.8.0
View all changes since the previous release in the commit history.
Updated dependencies
We would like to extend our gratitude to the community members who helped make this release possible.
Requirements
dompdf 0.8.1 requires the following:
allow_url_fopen
set to true (for retrieving stylesheets or images via http) or the curl PHP extensionFor full requirements and recommendations see the requirements page on the wiki.
Download Instructions
The dompdf team recommends that you use Composer for easier dependency management.
If you're not yet using Composer you can download a packaged release of dompdf which includes all the files you need to use the library. Click the link labeled "dompdf_0-8-1.zip" for the packaged release. The two buttons labeled "Source code" are auto-generated by github and do not include all the dependencies.
This release has been superseded by version 0.8.1
Change highlights since 0.7.0
width: auto
CSS stylingUpdated dependencies
We would like to extend our gratitude to the community members who helped make this release possible.
Requirements
dompdf 0.7.0 requires the following:
allow_url_fopen
set to true (for retrieving stylesheets or images via http) or the curl PHP extensionFor full requirements and recommendations see the requirements page on the wiki.
Download Instructions
The dompdf team recommends that you use Composer for easier dependency management.
If you're not yet using Composer you can download a packaged release of dompdf which includes all the files you need to use the library. Click the link labeled "dompdf_0-8-0.zip" for the packaged release. The two buttons labeled "Source code" are auto-generated by github and do not include all the necessary files.
This release has been superseded by version 0.8.0
Change highlights since 0.6.2
The majority of work in this release went towards support for namespaces, PSR, and SVG support but a few code improvements were also made. Highlights include:
We would like to extend our gratitude to the community members who helped make this release possible.
Requirements
dompdf 0.7.0 requires the following:
allow_url_fopen
set to true (for retrieving stylesheets or images via http)For full requirements and recommendations see the requirements page on the wiki.
The dompdf team recommends that you use Composer for easier dependency management. If you're not yet using Composer you can download a packaged release of dompdf which includes all the files you need to use the library. The release package is titled dompdf_0-7-0.zip.
Notes on migrating from an earlier version of dompdf
@font-face
CSS rule to install fonts at run time. If you wish to pre-load fonts you may find a copy of the load_font.php script updated to run with this release of dompdf in the dompdf-utils project.FontMetrics
class is now instantiated instead of static. To simplify migration of embedded scripts from earlier versions of dompdf we provide access to the instantiated FontMetrics class via the $fontMetrics
variable. Please update your embedded scripts. For example, FontMetrics::get_font('helvetica')
would now be $fontMetrics->getFont('helvetica')
.Change highlights since 0.6.2
The majority of work in this release went towards support for namespaces, PSR, and SVG support but a few code improvements were also made. Highlights include:
Requirements
The dompdf 0.7.0 beta 3 requires the following:
allow_url_fopen
set to true (for retrieving stylesheets or images via http)For full requirements and recommendations see the requirements page on the wiki.
The dompdf team recommends that you use Composer for easier dependency management. If you're not yet using Composer you can download a packaged release of dompdf which includes all the files you need to use the library. The beta package is titled dompdf_0-7-0_beta3.zip.
Notes on migrating from an earlier version of dompdf
@font-face
CSS rule to install fonts at run time.$fontMetrics
variable. Please update your embedded scripts. For example, FontMetrics::get_font('helvetica')
would now be $fontMetrics->getFont('helvetica')
.This release is superseded by version 0.7.0
This is a security-focused release that addresses a number of vulnerabilities that can expose your system to exploitation. In tandem with this release we have also posted a document to the wiki with advice for securing dompdf. Please read the new document and take appropriate measures to protect your systems.
We urge all users to upgrade to this release if you are using dompdf 0.6.1 or earlier.
Change Summary for 0.6.2
This update addresses the following announced vulnerabilities:
Vulnerability | Reference | Type | Severity |
---|---|---|---|
Remote Code Execution (complement of CVE-2014-2383) | CVE-2014-5013 | Remote Code Execution | Low; Critical (depending on configuration) |
Denial Of Service Vector | CVE-2014-5012 | Information Disclosure | Medium |
Information Disclosure | CVE-2014-5011 | Information Disclosure | Medium |
Arbitrary file read in dompdf using PHP stream filters | CVE-2014-2383 | Information Disclosure | Medium |
Change Summary for 0.6.1
This update addresses the following announced vulnerabilities:
Vulnerability | Reference | Type | Severity |
---|---|---|---|
Arbitrary file read in dompdf using PHP stream filters | CVE-2014-2383 | Information Disclosure | Medium |
PHP remote file inclusion vulnerability in dompdf.php | CVE-2010-4879 | Remote File Inclusion | Low; Critical (depending on configuration) |
Change Summary for 0.6.0
@page
, @font-face
, generated content, fixed-positioning, transformationsDownload Instructions
Click the link labeled "dompdf-0.6.2.zip" to download the packaged release. The two buttons labeled "Source code" are auto-generated by github and do not include all the necessary files.
Change highlights since 0.6.2
The majority of work in this release went towards support for namespaces, PSR, and SVG support but a few code improvements were also made. Highlights include:
Requirements
The dompdf 0.7.0 beta 2 requires the following:
allow_url_fopen
set to true (for retrieving stylesheets or images via http)For full requirements and recommendations see the requirements page on the wiki.
The dompdf team recommends that you use Composer for easier dependency management. If you're not yet using Composer you can download a packaged release of dompdf which includes all the files you need to use the library. The beta package is titled dompdf_0-7-0_beta2.zip.
Notes on migrating from an earlier version of dompdf
@font-face
CSS rule to install fonts at run time.FontMetrics::get_font('helvetica')
would now be $fontMetrics->getFont('helvetica')
.Change highlights since 0.6.2
The majority of work in this release went towards support for namespaces and PSR-2, but a few code improvements were also made.
Requirements
The dompdf 0.7.0 beta requires the following:
allow_url_fopen
set to true (for retrieving images via http)For full requirements and recommendations see the requirements page on the wiki.
The dompdf team recommends that you use Composer for easier dependency management. If you're not yet using Composer you can download an archived release of dompdf which includes all the files you need to use the library. The beta download is titled dompdf_0.7.0.beta.zip.
Notes on migrating from an earlier version of dompdf
@font-face
CSS rule to install fonts at run time.FontMetrics::get_font('helvetica')
would now be $fontMetrics->get_font('helvetica')
.This release is superseded by version 0.6.2
dompdf is an HTML to PDF converter. At its heart, dompdf is (mostly) CSS2.1 compliant HTML layout and rendering engine written in PHP. It is a style-driven renderer: it will download and read external stylesheets, inline style tags, and the style attributes of individual HTML elements. It also supports most presentational HTML attributes.
Change highlights since 0.6.0
Change highlights since 0.5.2
@page
, @font-face
, generated content, fixed-positioning, transformationsDownload Instructions
The two buttons labeled "Source code" are auto-generated by github and do not include all the necessary files.
This release is superseded by version 0.6.2
dompdf is an HTML to PDF converter. At its heart, dompdf is (mostly) CSS2.1 compliant HTML layout and rendering engine written in PHP. It is a style-driven renderer: it will download and read external stylesheets, inline style tags, and the style attributes of individual HTML elements. It also supports most presentational HTML attributes.
Change highlights since 0.5.2
@page
, @font-face
, generated content, fixed-positioning, transformationsDownload Instructions
The two buttons labeled "Source code" are auto-generated by github and do not include all the necessary files.
This release is superseded by version 0.6.2
Table of Contents:
For installation instructions see INSTALL.
dompdf is an HTML to PDF converter. At its heart, dompdf is (mostly) CSS2.1 compliant HTML layout and rendering engine written in PHP. It is a style-driven renderer: it will download and read external stylesheets, inline style tags, and the style attributes of individual HTML elements. It also supports most presentational HTML attributes.
PDF rendering is currently provided either by PDFLib or by a bundled version the R&OS CPDF class written by Wayne Munro. (Some performance related changes have been made to the R&OS class, however). In order to use PDFLib with dompdf, the PDFLib PECL extension is required. Using PDFLib improves performance and reduces the memory requirements of dompdf somewhat, while the R&OS CPDF class, though slightly slower, eliminates any dependencies on external PDF libraries.
dompdf was entered in the Zend PHP 5 Contest and placed 20th overall.
Please note that dompdf works only with PHP 5. There are no plans for a PHP 4 port. If your web host does not offer PHP 4, I suggest either pestering them, or setting up your own PHP 5 box and using it to run dompdf. Your scripts on your web host can redirect PDF requests to your PHP 5 box.
This package should contain:
File | Notes |
---|---|
dompdf.php | PDF Generating script |
dompdf_config.inc.php | Main configuration file |
load_font.php | Font loading utility script |
HACKING | Notes on messing with the code |
INSTALL | Installation instructions |
LICENSE.LGPL | GNU Lesser General Public License |
NEWS | Release news |
README | This content |
TODO | Things I'm working on |
include/ | PHP class & include files |
lib/ | R&OS PDF class, fonts, default CSS file |
www/ | Demonstration webpage |
www/test/ | Some test HTML pages |
For the impatient: Once you have installed dompdf, point your browser at the www/ directory for HTML documentation and a quick demonstration.
@import
, @media
& @page
rulesThe included dompdf.php script can be used both from the command line or via a web browser. Alternatively, the dompdf class can be used directly.
The dompdf.php script is not intended to be an interactive page. It receives input parameters via $_GET and can stream a PDF directly to the browser. This makes it possible to embed links to the script in a page that look like static PDF links, but are actually dynamically generated. This method is also useful as a redirection target.
dompdf.php accepts the following $_GET
variables:
Variable | Required? | Notes |
---|---|---|
input_file | required | a rawurlencoded() path to the HTML file to process. Remote files (http/ftp) are supported if fopen wrappers are enabled. |
paper | optional | the paper size. Defaults to 'letter' (unless the default has been changed in dompdf_config.inc.php). See include/cpdf_adapter.cls.php, or invoke dompdf.php on the command line with the -l switch for accepted paper sizes. orientation |
base_path | optional | the base path to use when resolving relative links (images or CSS files). Defaults to the directory containing the file being accessed. (This option is useful for pointing dompdf at your CSS files even though the HTML file may be elsewhere.) |
output_file | optional | the rawurlencoded() name of the output file. Defaults to 'dompdf_out.pdf'. |
save_file | optional | If present (i.e. isset($_GET["save_file"]) == true ), output_file is saved locally, Otherwise the file is streamed directly to the client. |
One technique for generating dynamic PDFs is to generate dynamic HTML as you normally would, except instead of displaying the output to the browser, you use output buffering and write the output to a temporary file. Once this file is saved, you redirect to the dompdf.php script. If you use a templating engine like Smarty, you can simply do:
<?php
$tmpfile = tempnam("/tmp", "dompdf_");
file_put_contents($tmp_file, $smarty->fetch());
$url = "dompdf.php?input_file=" . rawurlencode($tmpfile) .
"&paper=letter&output_file=" . rawurlencode("My Fancy PDF.pdf");
header("Location: http://" . $_SERVER["HTTP_HOST"] . "/$url");
?>
If you use any stylesheets, you may need to provide the base_path option to tell dompdf where to look for them, as they are not likely relative to /tmp ;).
###Invoking dompdf via the command line:
You can execute dompdf.php using the following command:
$ php -f dompdf.php -- [options]
(If you find yourself using only the cli interface, you can add #!/usr/bin/php
as the first line of dompdf.php to invoke dompdf.php directly.)
dompdf.php is invoked as follows:
$ ./dompdf.php [options] html_file
Option | Notes |
---|---|
html_file | can be a filename, a url if fopen_wrappers are enabled, or the '-' character to read from standard input. |
-h | Show a brief help message |
-l | list available paper sizes |
-p <size> | paper size; something like 'letter', 'A4', 'legal', etc. The default is 'letter' |
-o <orientation> | either 'portrait' or 'landscape'. Default is 'portrait'. |
-b <path> | the base path to use when resolving relative links (images or CSS files). Default is the directory of html_file. |
-f <file> | the output filename. Default is based on the input filename <file>.pdf. |
-v | verbose: display html parsing warnings and file not found errors. |
-d | very verbose: display oodles of debugging output; every frame in the tree is printed to stdout. |
Examples:
$ php -f dompdf.php -- my_resume.html
$ php -f dompdf.php -- -b /var/www/ ./web_stuff/index.html
$ echo '<html><body>Hello world!</body>' | php -f dompdf.php -- -
See the API documentation for the interface definition.
dompdf supports two varieties of inline PHP code. All PHP evaluation is controlled by the DOMPDF_ENABLE_PHP configuration option. If it is set to false, then no PHP code is executed. Otherwise, PHP is evaluated in two passes:
The first pass is useful for inserting dynamic data into your PDF. You can do this by embedding <?php ?>
tags in your HTML file, as you would in a normal .php file. This code is evaluated prior to parsing the HTML, so you can echo any text or markup and it will appear in the rendered PDF.
The second pass is useful for performing drawing operations on the underlying PDF class directly. You can do this by embedding PHP code within <script type="text/php"> </script>
tags. This code is evaluated during the rendering phase and you have access to a few internal objects and operations. In particular, the $pdf
variable is the current instance of CPDF_Adapter
. Using this object, you can write and draw directly on the current page. Using the CPDF_Adapter::open_object()
, CPDF_Adapter::close_object()
and CPDF_Adapter::add_object()
methods, you can create text and drawing objects that appear on every page of your PDF (useful for headers &
footers).
The following variables are defined for you during the second pass of PHP execution:
Variable | Description |
---|---|
the current instance of CPDF_Adapter | |
$PAGE_NUM | the current page number |
$PAGE_COUNT | the total number of pages in the document |
For more complete documentation of the CPDF_Adapter API, see either include/cpdf_adapter.cls.php and include/canvas.cls.php directly.
That's it! Have fun! Benj Carson
Copyright (c) 2004-2005 Benj Carson R&OS PDF class (class.pdf.php) Copyright (c) 2001-04 Wayne Munro