Skip to content

DOMPDF and Composer Quick start guide

Kay Strobach edited this page Sep 19, 2013 · 2 revisions

##Installing DOMPDF with Composer

  1. Ensure Composer is installed on your system.

  2. Create a file named composer.json, and add the DOMPDF package:

    {
    	"require": {
    		"dompdf/dompdf": "dev-master"
    	}
    }
  3. From a shell, cd into your project folder and run composer update. This should install DOMPDF and the dependency php-font-lib into the vendor directory.

Sample PHP

Time to write some PHP! We'll use Composer Autoloading. Here's some boilerplate to get you started:

<?php

// Composer's auto-loading functionality
require "vendor/autoload.php";

// inhibit DOMPDF's auto-loader
define('DOMPDF_ENABLE_AUTOLOAD', false);

//include the DOMPDF config file (required)
require 'vendor/dompdf/dompdf/dompdf_config.inc.php';

//if you get errors about missing classes please also add:
require_once('vendor/dompdf/dompdf/include/autoload.inc.php');


//generate some PDFs!
$dompdf = new DOMPDF();     //if you use namespaces you may use new \DOMPDF()
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf", array("Attachment"=>0));

That's it!

Clone this wiki locally