limeMpdf > Documentation

Learn how to use mPDF inside your plugin for LimeSurvey.

Basic usage

Inside your plugin you can directly create a pdf document.

  1. $html = "<p>Some HTML to put in your PDF.</p>";
  2. $limeMpdfHelper = new \limeMpdf\helper\limeMpdfHelper();
  3. /* Send pdf file to browser for download */
  4. $limeMpdfHelper->doPdfContent($html);

Download

For the pdf, plugin use twig files. The PDF generated use header.twig for the header, body.twig for content and footer.twig for footer.
This twig files is inside views/subviews/mpdf, to use your own : create this file inside theme used inside subviews/mpdf directory.

Theme used is the theme by default or the theme of the survey used on constructor

  1. $limeMpdfHelper = new \limeMpdf\helper\limeMpdfHelper($surveyId);

Adapt content and style

All content and css can be updated in your theme. Each twig files get this variables : title,subtiles and aSurveyInfo [1].

The twig file used for content are

  • body.twig : the final content of you PDF, the content are inside content variable.
  • head.twig : the final header set, it‘s empty : no header was set.
  • footer.twig : the final footre set, it‘s empty : no footer was set. By default use date, page number and number of page.

Inside this content you can use twig function, but mPDF helper too, for example {PAGENO}

The default style are loaded via stylesheet.twig, then by default, load style-bootstrap.twig,style-helper.twig and style-custom.twig. Each of this file can be loaded via your template in subviews/mpdf/ directory.

The style-bootstrap is an adapted css to allow usage of some boostrap class in you HTML. See Demo of limeMpdf for some sample.

New tag system

The plugin add some helper tag related to form, you can use

  • <radio> for radio
  • <radio-checked> for checked radio
  • <checkbox> for checkbox
  • <checkbox-checked> for checked checkbox

Available function and variables in limeMpdfHelper

function doPdfContent
Do the pdf with the html set as first variable, second variable is the output of mPdf.
function setOptions
Set one or more mPdf options
function addTag
Add an new know tag. A file must exist with tag name in subviews/mpdf/tags

More usage

The class limeMpdf\helper\Mpdf extend \Mpdf\Mpdf then you can use all mPdf class function or configuration variable.

Download

Get this plugin on gitlab.

Footnotes

[1Same array than LimeSurvey core theme