Developer Documentation

This documentation apply to GLPI >= 0.83 only.

Generating PDF for a new type provided by a plugin

To declare a plugin handle PDF export for a type, it must declare in the plugin_pdf hook:

   $PLUGIN_HOOKS['plugin_pdf']['PluginFooBar'] = 'PluginFooBarPDF';

Which means, class PluginFooBarPDF will handled PDF export of PluginFooBar object.

The PluginFooBarPDF class must extends PluginPdfCommon and provides, at least:

  • __construct, the constructor
       function __construct(PluginFooBar $obj=NULL) {
          $this->obj = ($obj ? $obj : new PluginFooBar());
  • displayTabContentForPDF, the export for 1 tab
       static function displayTabContentForPDF(PluginPdfSimplePDF $pdf, CommonGLPI $item, $tab) {
          switch ($tab) {
             case '_main_' :
             default :
                return false;
          return true;
Tips :
  • see others plugins for code sample, mainly appliances.
  • PDF plugin provides function to render lot or common part (ticket, notes, document, history, ...)

Add plugin information to GLPI (or other plugin) types

The PDF plugin export the same tab than defined for display.

Only standard tab are managed (returned by getTabNameForItem() method)

The plugin type must have the displayTabContentForPDF method (else tab are not proposed to export)

 * Render tab managed by our plugin
 * @param $pdf  : a simplePDF object
 * @param $item : the computer
 * @param $tab  : number
 * @return name of function to be called to render the PDF 
static function displayTabContentForPDF(PluginPdfSimplePDF $pdf, CommonGLPI $item, $tab) {

   if ($item->getType()==COMPUTER_TYPE) {
      self::pdfForComputer($pdf, $item);
      return true
   return false;

And the method called to render

 * Render PDF of data provided by foo plugin to computer
 * @param $pdf : a simplePDF object
 * @param $item : the computer
 * @return nothing (buf PDF)
static function pdfForComputer(PluginPdfSimplePDF $pdf, CommonGLPI $item) {
   $pdf->displayTitle('<b>A great example</b>');

The SimplePDF class

This class provides simple methods to render PDF without need to know which backend (library) is used internally.

Here is a little sample code

$pdf->setHeader("The page header sample");

# Start a page

# Create a 2 columns layout (args are colums size in %)

# Display a tile line (dark background)
$pdf->displayTitle("first", "second");

# Display a ligne (light background)
$pdf->displayLine("first", "second");

# Display a "comment" line (only 1 column, multi-line)
$pdf->displayText("A long text\nwhich expand\non 3 lines");

# White separator space    

# generate the PDF

Quite simple ?