Developed with love by KnpLabs Hire us for your project!
27

MpdfPortBundle

by tasmanianfox

MpdfBundle is a wrapper service which allows to use mPDF class in your Symfony2 project. The main benefit of MpdfPortbundle is a possibility to generate...

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:
$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:
$response->getContent()

But there is a shorter way to get a raw content:
$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:
$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).

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

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

To pass additional arguments, an array with arguments should be created:
$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:
$mpdfService->generatePdf($html, $arguments);
$mpdfService->generatePdfResponse($html, $arguments);

t_fox_mpdf_port:      []
  • Merge pull request #14 from yashmika/master
    By tasmanianfox, 1 year ago
  • ContructArgs arrar_merge array order bug
    By , 1 year ago
  • ContructArgs passing bug
    By yashmika, 1 year ago
  • Update MpdfService.php
    By yashmika, 1 year ago
  • Fixed the name of a variable
    By tasmanianfox, 2 years ago
  • Fixed an error with mPdf default output parameter
    By Sergei Beljakov, 2 years ago
  • Merge pull request #12 from muxx/master
    By tasmanianfox, 2 years ago
  • Set `dest` to S for always returning content by mpdf
    By muxx, 2 years ago
  • Silent generation of the PDF
    By muxx, 2 years ago
  • Merge pull request #10 from markitosgv/patch-2
    By tasmanianfox, 2 years ago
  • Delete MpdfPortBundle.php
    By , 2 years ago
  • Merge pull request #9 from markitosgv/patch-1
    By tasmanianfox, 2 years ago
  • Update composer.json
    By markitosgv, 2 years ago
  • Updated composer
    By TFox, 2 years ago
  • Removed include for mpdf.php as soos as it is loaded by autoloader
    By TFox, 2 years ago
  • solved conflicts
    By TFox, 3 years ago
  • fixed composer.json
    By TFox, 3 years ago
  • Removed mpdf component from bundle. Mpdf is currently loaded from composer.
    By U-REX\TFox, 3 years ago
  • Merge pull request #7 from markitosgv/master
    By tasmanianfox, 3 years ago
  • Delete MpdfService.php~
    By markitosgv, 3 years ago
  • Delete composer.json~
    By markitosgv, 3 years ago
  • Add composer.json support for MPDF library and fix include_once route to new mPDF directory
    By z50mgome, 3 years ago
  • Merge pull request #6 from sirgix/master
    By tasmanianfox, 3 years ago
  • Allow use of preexisting mpdf instance
    By , 3 years ago
  • Allow use of existing mpdf instance
    By sirgix, 3 years ago
  • Lol fixed a stupid mistake in a description file
    By tasmanianfox, 3 years ago
  • Merge pull request #2 from nurikabe/master
    By tasmanianfox, 3 years ago
  • Japanese font support.
    By nurikabe, 3 years ago
  • Merge pull request #1 from BillyTom/master
    By tasmanianfox, 3 years ago
  • Updated Readme.md
    By , 3 years ago