forked from dompdf/dompdf
-
Notifications
You must be signed in to change notification settings - Fork 0
DOMPDF and Composer Quick start guide
Kay Strobach edited this page Sep 19, 2013
·
2 revisions
##Installing DOMPDF with Composer
-
Create a file named
composer.json
, and add the DOMPDF package:{ "require": { "dompdf/dompdf": "dev-master" } }
-
From a shell,
cd
into your project folder and runcomposer update
. This should install DOMPDF and the dependencyphp-font-lib
into thevendor
directory.
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!