2017 © Pedro Peláez
 

symfony-bundle mpdf-port-bundle

A wrapper for mPDF class which allows to use mPDF in Symfony2 projects

image

galmet/mpdf-port-bundle

A wrapper for mPDF class which allows to use mPDF in Symfony2 projects

  • Tuesday, February 4, 2014
  • by galmet
  • Repository
  • 1 Watchers
  • 0 Stars
  • 541 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 20 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Installation

Using Composer (Symfony 2.1+)

  • Add a new line to your composer.json file:
"require": {
        ...
        
        "tfox/mpdf-port-bundle": "1.2.*"
}
  • Run a command
php composer.phar update
  • Add a new line to app/AppKernel.php:
$bundles = array(
  ...
  new TFox\MpdfPortBundle\TFoxMpdfPortBundle(),
)

Using deps-file (Symfony 2.0.x)

  • Add a new entry to your deps file:
[TFoxMpdfPortBundle]
    git=https://github.com/tasmanianfox/MpdfPortBundle.git
    target=/bundles/TFox/MpdfPortBundle 
  • Add a new line to app/AppKernel.php:
new TFox\MpdfPortBundle\TFoxMpdfPortBundle(), 
  • Add a new line to app/autoload.php:
'TFox' => __DIR__.'/../vendor/bundles',
  • Run a command
php bin/vendors install

A Quick Start guide

How to create a Response object

This small example creates a PDF document with format A4 and portrait orientation:, (*1)

$mpdfService = $this->get('tfox.mpdfport');
$html = "Hello World!";
$response = $mpdfService->generatePdfResponse($html);

Generate a variable with PDF content

Sometimes it is necessary to get a variabe which content is PDF document. Obviously, you might generate a response from the previous example and then call a method:, (*2)

$response->getContent()

But there is a shorter way to get a raw content:, (*3)

$mpdfService = $this->get('tfox.mpdfport');
$html = "Hello World!";
$content = $mpdfService->generatePdf($html);

How to get an instance of \mPDF class

If you would like to work with mPDF class itself, you can use a getMpdf method:, (*4)

$mpdfService = $this->get('tfox.mpdfport');
$mPDF = $mpdfService->getMpdf();

Warning

  • By default the bundle adds the two attributes 'utf-8' and 'A4' to the mPDF class constructor. To turn off these options, use the setAddDefaultConstructorArgs method:
$mpdfService->setAddDefaultConstructorArgs(false);
  • As the bundle inserts the first two arguments to the mPDF constructor by default, additional constructor arguments should start from the 3rd argument (default_font_size)., (*5)

  • If the setAddDefaultConstructorArgs(false) method is called, additional arguments for constructor should start from the first one (mode)., (*6)

Additional arguments

As the bundle uses methods of mPDF class, some additional parameters can be added to these methods. There are 3 mPDF methods used in the bundle: * Constructor. Documentation: http://mpdf1.com/manual/index.php?tid=184 * WriteHTML. Documentation: http://mpdf1.com/manual/index.php?tid=121 * Output. Documentation: http://mpdf1.com/manual/index.php?tid=125, (*7)

To pass additional arguments, an array with arguments should be created:, (*8)

$arguments = array(
    'constructorArgs' => array(), //Constructor arguments. Numeric array. Don't forget about points 2 and 3 in Warning section!
    'writeHtmlMode' => null, //$mode argument for WriteHTML method
    'writeHtmlInitialise' => null, //$mode argument for WriteHTML method
    'writeHtmlClose' => null, //$close argument for WriteHTML method
    'outputFilename' => null, //$filename argument for Output method
    'outputDest' => null //$dest argument for Output method
);

It is NOT necessary to have all the keys in array. This array might be passed to the generatePdf and generatePdfResponse methods as the second argument:, (*9)

$mpdfService->generatePdf($html, $arguments);
$mpdfService->generatePdfResponse($html, $arguments);

The Versions

04/02 2014

dev-master

9999999-dev http://github.com/tasmanianfox/MpdfPortBundle

A wrapper for mPDF class which allows to use mPDF in Symfony2 projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergei Beljakov

pdf mpdf

22/01 2014

1.2.2b

1.2.2.0-beta http://github.com/tasmanianfox/MpdfPortBundle

A wrapper for mPDF class which allows to use mPDF in Symfony2 projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergei Beljakov

pdf mpdf

22/01 2014

1.2.1

1.2.1.0 http://github.com/tasmanianfox/MpdfPortBundle

A wrapper for mPDF class which allows to use mPDF in Symfony2 projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergei Beljakov

pdf mpdf

22/01 2014

1.2.0

1.2.0.0 http://github.com/tasmanianfox/MpdfPortBundle

A wrapper for mPDF class which allows to use mPDF in Symfony2 projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergei Beljakov

pdf mpdf

08/01 2014

1.1.1

1.1.1.0 http://github.com/tasmanianfox/MpdfPortBundle

A wrapper for mPDF class which allows to use mPDF in Symfony2 projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergei Beljakov

pdf mpdf

11/05 2013

1.1.0

1.1.0.0 http://github.com/tasmanianfox/MpdfPortBundle

A wrapper for mPDF class which allows to use mPDF in Symfony2 projects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergei Beljakov

pdf mpdf