Skip to content

Latest commit

 

History

History
124 lines (85 loc) · 2.83 KB

README.md

File metadata and controls

124 lines (85 loc) · 2.83 KB

FPDF for use with Symfony2

Latest Stable Version Total Downloads Latest Unstable Version License

Uses FPDF 1.7, tested in Symfony 2.5+

Instalation and Usage

Package available on Composer.

If you're using Composer to manage dependencies, you can use

$ composer require "royopa/fpdf-symfony2": "dev-master"

Or

You can include the following in your composer.json file:

{
    "require": {
        "royopa/fpdf-symfony2": "dev-master"
    }
}

Setup

And those to app/autoload.php:

$classMap = array(
    'Fpdf_' => __DIR__.'/../vendor/royopa/fpdf-symfony2/lib/FPDF/FPDF.php',
    'Fpdi_' => __DIR__.'/../vendor/royopa/fpdf-symfony2/lib/FPDF/FPDI.php'
);
$loader->addClassMap($classMap);    

Usage

<?php

namespace Acme\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class WelcomeController extends Controller
{
    public function indexAction()
    {
        $pdf  = new \FPDF_FPDF();
        $pdi  = new \FPDF_FPDI();

        $pdf->AddPage();
        $pdf->SetFont('Arial','B',16);
        $pdf->Cell(40,10,'Hello World!');
        $pdf->Output();
    }
}

FPDF

FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. FPDF is a open source project: you may use it for any kind of usage and modify it to suit your needs.

On the fpdf homepage you will find links to the documentation, forums and so on.

Example

See my app/autoload.php:

<?php

use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;

/**
 * @var ClassLoader $loader
 */
$loader = require __DIR__.'/../vendor/autoload.php';

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

$classMap = array(
    'Fpdf_' => __DIR__.'/../vendor/royopa/fpdf-symfony2/lib/FPDF/FPDF.php',
    'Fpdi_' => __DIR__.'/../vendor/royopa/fpdf-symfony2/lib/FPDF/FPDI.php'
);
$loader->addClassMap($classMap);

return $loader;

And My Controller:

<?php

namespace Acme\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class WelcomeController extends Controller
{
    public function indexAction()
    {
        $pdf  = new \FPDF_FPDF();
        $pdi  = new \FPDF_FPDI();

        //my code...
    }
}