pdf-bundle
, (*1)
Installation
- Install KwizerPdfBundle
- Enable the bundle
Install KwizerPdfBundle
Add the following dependency to your composer.json file:
``` json
{
"require": {
"kwizer15/pdf-bundle": "1.0.*"
}
}, (*2)
Update vendors
``` bash
$ php composer.phar update
Enable the bundle
``` php
<?php
// app/AppKernel.php, (*3)
public function registerBundles()
{
$bundles = array(
// ...
new Kwizer\PdfBundle\KwizerPdfBundle(),
);
}, (*4)
## Using the bundle
### Hello World
#### The document
``` php
<?php
// src/Acme/DemoBundle/PdfDocument/MyPdf.php
namespace Acme\DemoBundle\PdfDocument;
class MyDocument extends \Kwizer\PdfBundle\Core\AbstractPdfDocument
{
public function buildContent()
{
$this->builder->cell('Hello World !!!');
}
}
Controller
``` php
<?php
// src/Acme/DemoBundle/Controller/MyController.php, (*5)
...
use Symfony\Component\HttpFoundation\Response;
use Acme\DemoBundle\PdfDocument\MyDocument;, (*6)
class MyController extends Controller
{
public function myAction()
{
$response = new Response();
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-Disposition', 'inline; filename=my.pdf');
$pdf = $this->get('kwizer.pdf.factory')->createPdf(new MyDocument());
$response->setContent($pdf);, (*7)
return $response;
}
}
```, (*8)