Skip to content


Subversion checkout URL

You can clone with
Download ZIP
DOM PDF for Silverstripe
PHP C Perl JavaScript Shell CSS Other
Branch: master
Failed to load latest commit information.
_config Add instructions and template for quickly getting started
dompdf Removed .SVN files
templates Add instructions and template for quickly getting started
.gitignore add composer Add instructions and template for quickly getting started
_config.php Updated to 0.6
composer.json add composer

PDF Generation via DOMPDF Library


  • HTML string (which could be rendered template)
  • HTML File


  • PDF File location
  • SS File
  • PDF binary stream to browser

Quickly getting started

Find the ID number of a page (ie 1) and go to; /pdf/1

Customize your tempalte by copying DefaultPDF to your theme directory.

View raw output by going to; /pdf/1?show

Example usage

$pdf = new SS_DOMPDF();


The $pdf->streamdebug(); function is useful for quickly viewing pdfs, particularly if your browser supports displaying pdfs, rather than downloading.

You can check your html before it is converted like this:

echo $mydataobject->renderWith('MyTemplate');die();

Once this has been installed then you need to; parse your PDF templates to a .html file get dompdf to convert the saved .html file

A more advanced solution would be something like;

class CustomPage_Controller extends Page_Controller {

public function mypdf(){
    if($member = Member::currentUser()){

        if(!file_exists(ASSETS_PATH."/private")) mkdir(ASSETS_PATH."/private");

        require_once 'Zend/Date.php';
        $defaultDateFormat =Zend_Date::now()->toString($member->DateFormat);
        $defaultTimeFormat = Zend_Date::now()->toString($member->TimeFormat);           

        $content = $this->customise(array(
            'Member'    => $member

        $baseFile = preg_replace('/\\.pdf$/','',$filename);

        $fh = fopen($baseFile, "w+") or user_error("Couldn't open $baseFile.html for writing", E_USER_ERROR);
        fwrite($fh, $content) or user_error("Couldn't write content to $baseFile.html", E_USER_ERROR);

        $dompdf = new SS_DOMPDF();

        if ( isset($base_path) ) {$dompdf->set_base_path($base_path);}

        $orientation = "portrait";

        $dompdf->set_paper($paper, $orientation);

        $outfile = substr("{$member->FullName()}_{$defaultDateFormat}_{$defaultTimeFormat}", 0, 250).".pdf";


* You may also like this 'test' function
public function testpdf(){
    if($member = Member::currentUser()){
        require_once 'Zend/Date.php';
        $defaultDateFormat =Zend_Date::now()->toString($member->DateFormat);
        $defaultTimeFormat = Zend_Date::now()->toString($member->TimeFormat);           

        $content = $this->customise(array(
            'Member'    => $member
        return $content;


Something went wrong with that request. Please try again.