Jump to content
Fi8sVrs

dompdf - HTML to PDF converter

Recommended Posts

  • Active Members
Posted

dompdf is an HTML to PDF converter. At its heart, dompdf is (mostly) 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.

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

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

Requirements

  • PHP 5.0+ (5.3 recommended)
  • MBString extension
  • DOM extension (bundled with PHP 5)
  • Some fonts. PDFs internally support Helvetica, Times-Roman, Courier & Zapf-Dingbats, but if you wish to use other fonts you will need to install some fonts. dompdf supports the same fonts as the underlying R&OS PDF class: Type 1 (.pfb with the corresponding .afm) and TrueType (.ttf). At the minimum, you should probably have the Microsoft core fonts. See the font installation instructions.

Easy Installation

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
git submodule init
git submodule update

Install with composer

Add dompdf to composer.json

{

"require" : {

"dompdf/dompdf" : "dev-master"

}

}

From the command line run composer update to install dompdf to the vendor directory.

Download and install

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

Limitations (Known Issues)

  • not particularly tolerant to poorly-formed HTML input (using Tidy first may help).
  • large files or large tables can take a while to render
  • CSS float is not supported (but is in the works).
  • If you find this project useful, please consider making a donation.

Source: https://github.com/dompdf/dompdf

Posted

Poate are cineva nevoie, o clasa basic de wrapper


<?php

class Model_Helper_Pdf {

public static function getString($html = "", $paper = 'A4', $orientation = 'portrait') {
require_once( self::_getDomPDFDirectory() . "dompdf_config.inc.php");

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper($paper, $orientation);
$dompdf->render();

return $dompdf->output();
}

public static function generate($html = "", $paper = 'A4', $orientation = 'portrait') {
require_once( self::_getDomPDFDirectory() . "dompdf_config.inc.php");

$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->set_paper($paper, $orientation);
$dompdf->render();

$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
}

private static function _getDomPDFDirectory() {
$dompdf_directory = dirname(APPLICATION_PATH).DIRECTORY_SEPARATOR."library/dompdf".DIRECTORY_SEPARATOR;

if(!is_dir($dompdf_directory)){
exit("Application Error . DomPdf Library missing");
}

return $dompdf_directory;
}
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...