dompdf/dompdf


HTML to PDF converter (PHP5)

http://dompdf.github.com/

License: LGPL-2.1

Language: PHP

Keywords: css, dompdf, font, html, html-to-pdf, pdf-generation, php


Dompdf

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Dompdf is an HTML to PDF converter

At its heart, dompdf is (mostly) a CSS 2.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.

This document applies to the latest stable code which may not reflect the current release. For released code please navigate to the appropriate tag.


Check out the demo and ask any question on StackOverflow or on the Google Groups.

Follow us on Twitter or Follow us on Google+.


Features

  • Handles most CSS 2.1 and a few CSS3 properties, including @import, @media & @page rules
  • 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)
  • No dependencies on external PDF libraries, thanks to the R&OS PDF class
  • Inline PHP support
  • Basic SVG support

Requirements

  • PHP version 5.4.0 or higher
  • DOM extension
  • GD extension
  • MBString extension
  • php-font-lib
  • php-svg-lib

Recommendations

  • OPcache (OPcache, XCache, APC, etc.): improves performance
  • IMagick or GMagick extension: improves image processing performance

Visit the wiki for more information: https://github.com/dompdf/dompdf/wiki/Requirements

About Fonts & Character Encoding

PDF documents internally support the following fonts: Helvetica, Times-Roman, Courier, Zapf-Dingbats, & Symbol. These fonts only support Windows ANSI encoding. In order for a PDF to display characters that are not available in Windows ANSI you must supply an external font. Dompdf will embed any referenced font in the PDF so long as it has been pre-loaded or is accessible to dompdf and reference in CSS @font-face rules. See the font overview for more information on how to use fonts.

The DejaVu TrueType fonts have been pre-installed to give dompdf decent Unicode character coverage by default. To use the DejaVu fonts reference the font in your stylesheet, e.g. body { font-family: DejaVu Sans; } (for DejaVu Sans). The following DejaVu 2.34 fonts are available: DejaVu Sans, DejaVu Serif, and DejaVu Sans Mono.

Easy Installation

Install with composer

To install with Composer, simply require the latest version of this package.

composer require dompdf/dompdf

Make sure that the autoload file from Composer is loaded.

// somewhere early in your project's loading, require the Composer autoloader
// see: http://getcomposer.org/doc/00-intro.md
require 'vendor/autoload.php';

Download and install

Download an archive of dompdf and extract it into the directory where dompdf will reside

Use the packaged release autoloader to load dompdf, libraries, and helper functions in your PHP:

// include autoloader
require_once 'dompdf/autoload.inc.php';

Install with git

From the command line, switch to the directory where dompdf will reside and run the following commands:

git clone https://github.com/dompdf/dompdf.git
cd dompdf

git clone https://github.com/PhenX/php-font-lib.git lib/php-font-lib
cd lib/php-font-lib
git checkout 0.5.1
cd ..

git clone https://github.com/PhenX/php-svg-lib.git php-svg-lib
cd php-svg-lib
git checkout v0.3

Require dompdf, libraries, and helper functions in your PHP:

require_once 'dompdf/lib/html5lib/Parser.php';
require_once 'dompdf/lib/php-font-lib/src/FontLib/Autoloader.php';
require_once 'dompdf/lib/php-svg-lib/src/autoload.php';
require_once 'dompdf/src/Autoloader.php';
Dompdf\Autoloader::register();

Quick Start

Just pass your HTML in to dompdf and stream the output:

// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');

// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');

// Render the HTML as PDF
$dompdf->render();

// Output the generated PDF to Browser
$dompdf->stream();

Setting Options

Set options during dompdf instantiation:

use Dompdf\Dompdf;
use Dompdf\Options;

$options = new Options();
$options->set('defaultFont', 'Courier');
$dompdf = new Dompdf($options);

or at run time

use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->set_option('defaultFont', 'Courier');

See Dompdf\Options for a list of available options.

Limitations (Known Issues)

  • Dompdf is not particularly tolerant to poorly-formed HTML input. To avoid any unexpected rendering issues you should either enable the built-in HTML5 parser at runtime ($dompdf->set_option('isHtml5ParserEnabled', true);) or run your HTML through a HTML validator/cleaner (such as Tidy or the W3C Markup Validation Service).
  • Large files or large tables can take a while to render.
  • CSS float is in development and may not produce the desired result

Donate button

If you find this project useful, please consider making a donation. Any funds donated will be used to help further development on this project.)

Project Statistics

Sourcerank 17
Repository Size 15.1 MB
Stars 6,044
Forks 1,232
Watchers 292
Open issues 680
Dependencies 8
Contributors 79
Tags 12
Created
Last updated
Last pushed

Top Contributors See all

Brian Sweeney Fabien Ménager Gabriel Bull Barry vd. Heuvel Andrew Scott Simon Berger flaviencrochard indreka Woody Gilk Mellthas Tom Lankhorst Edd Turtle Adrian Macneil Andreas Thomas Landauer Marco Napetti alxndrmlr Marijn van der Werf Samuel Vogel Bruno De Barros

Packages Referencing this Repo

dompdf/dompdf
DOMPDF is a CSS 2.1 compliant HTML to PDF converter
Latest release v0.8.2 - Updated - 6.04K stars
dompdf
HTML to PDF converter (PHP5)
Latest release v0.8.2 - Published - 6.04K stars

Recent Tags See all

v0.8.2 November 26, 2017
v0.8.1 September 14, 2017
v0.8.0 February 16, 2017
v0.7.0 May 11, 2016
v0.7.0-beta3 January 22, 2016
v0.6.2 December 07, 2015
v0.7.0-beta2 September 25, 2015
v0.7.0-beta May 01, 2015
v0.6.1 March 11, 2014
v0.6.0 February 07, 2014
v0.5.2 August 16, 2013
v0.6.0-b3 August 14, 2013

Interesting Forks See all

pruno/dompdf
HTML to PDF converter (PHP5)
PHP - LGPL-2.1 - Updated - 2 stars
pancakeapp/dompdf
HTML to PDF converter (PHP5)
PHP - LGPL-2.1 - Updated - 1 stars
blickyer/dompdf
HTML to PDF converter (PHP5)
PHP - Published - 1 stars
MattRogowski/dompdf
HTML to PDF converter (PHP5)
PHP - Last pushed - 1 stars
jaevic/dompdf
HTML to PDF converter (PHP5)
PHP - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2017-09-21 11:16:28 UTC

Login to resync this repository