Overview
An overview of the PDF framework.
SugarPDF Architecture
The PDF framework leverages the SugarCRM MVC architecture and is built upon the TCPDF library.

TCPDF Class
The TCPDF class, located in ./include/tcpdf/tcpdf.php, is a third party PHP class for generating PDF documents. We use and extend upon this class to generate the PDFs users receive from the system. For more documentation on working with TCPDF, you can visithttp://www.tcpdf.org.
SugarPDF Class
The SugarPDF class, located in ./include/Sugarpdf/Sugarpdf.php, extends the TCPDF class. This is the basis on which we generate all PDFs within Sugar. As we have extended TCPDF, we have overridden the following methods:
- Header : Altered to enable the use of the Sugar image directories for generating the PDF header.
- SetFont : Altered to enable the use of the Sugar Font directories.
- Cell : Altered to apply the prepare_string() function to data being printed by the PDF.
- getNumLines : Adjusted for handling record counts.
Methods added to the class for development use are:
- predisplay : Used to preprocessing before the display method is called. It is intended to setup the general PDF document properties like margin, footer, header, etc.
- display : Performs the actual generating of the PDF. This is where the logic to display output to the PDF is placed.
- process : Calls the predisplay and display methods.
- writeCellTable : Method to print a table using the cell print method of TCPDF
- writeHTMLTable : Method to print a table using the writeHTML print method of TCPDF
SugarPDF View
The ViewSugarpdf class, located in ./include/MVC/View/views/view.sugarpdf.php, is a view used to generate the PDF document. As with all SugarViews, the stock ViewSugarpdf class can be overridden by files in the following directories:
- ./custom/modules/<module>/views/view.sugarpdf.php
- ./modules/<module>/views/view.sugarpdf.php
Modules with a SugarPDF view can be accessed using the following URL format:
http://{sugar url}/index.php?module=<module>&action=sugarpdf&sugarpdf=<template>
As you can see, the view is accepting 3 query string parameters:
- module=<module> : Determines the module containing the PDF generation classes
- action=sugarpdf : Specifies the SugarPDF action view
- sugarpdf=<template> : Specifies the template name for the PDF we want to generate
More information on creating a SugarPDF View can be found in the Generating PDFs section.
SugarPDF Templates
SugarPDF templates are templates used for generating the PDF documents that users receive. The templates can typically be found in the following directory paths:
- ./include/Sugarpdf/sugarpdf/sugarpdf.<template>.php
- ./modules/<module>/sugarpdf/sugarpdf.<template>.php
- ./custom/modules/<module>/sugarpdf/sugarpdf.<template>.php
These template classes extend the Sugarpdf class and are accessed by name via the "sugarpdf" query string parameter when calling the SugarPDF view:
http://{sugar url}/index.php?module=<module>&action=sugarpdf&sugarpdf=<template>
When the SugarPDF action is called, the most relevant SugarPDF template class is selected by the SugarPDF Factory .
SugarPDF Factory
The SugarPDF Factory, located in ./include/Sugarpdf/SugarpdfFactory.php, is used by the SugarPDF view to find the most relevant template class given a module and template name. If a template is not found, then the default SugarPDF class is used.
The template is searched for in the following directories:
- ./custom/modules/<module>/sugarpdf/sugarpdf.<template>.php
- ./modules/<module>/sugarpdf/sugarpdf.<template>.php
- ./custom/include/Sugarpdf/sugarpdf/sugarpdf.<template>.php
- ./include/Sugarpdf/sugarpdf/sugarpdf.<template>.php
- ./include/Sugarpdf/sugarpdf.php
SugarPDF Helpers
To help with the formatting of data for PDF documents, you can use the helper functions located in ./include/Sugarpdf/SugarpdfHelper.php. This file is included by SugarPDF by default and includes several functions you can use in your templates.
Available functions :
- wrapTag, wrapTD, wrapTable, etc. : These functions help to present your data using HTML.
- prepare_string : This function prepares a string for use when PDF printing.
- format_number_sugarpdf : This function is used when formatting numbers or currencies.
Font Manager
The FontManager, located in ./include/Sugarpdf/FontManager.php, is a stand-alone class that manages all the fonts for TCPDF. It contains the ability to:
- List all the available fonts
- Fetch the details for each font
- Add new fonts to the custom font directory from a font or metric file
- Delete a font from the custom font directory
More information can be found in the Font Manager section.