How to customize the Sugar PDF Manager

cedricmourizard —  April 25, 2016

Here is another guest post from Cédric Mourizard from the Elite SugarCRM Partner Synolia.  Cedric is a well recognized expert on the Sugar PDF Manager.

In regard to some recent questions from Sugar Community stalwart, Francesca Shiekh, we will address some questions about how to deal with the PDF Manager that was originally introduced in Sugar 6.

A Common Use Case

In this article we want to resolve this common use case for customizing the PDF manager. When following up on a meeting, you want to be able to generate an attractive summary document that lists all the meeting details included lists of those who were invited or attended.

We will customize the PDF manager so that we can print a meeting summary for any Meeting record that will have all contacts and invited users listed.

Understanding PDF Manager and extending it

Sugar uses two important 3rd party libraries as part of the PDF Manager implementation. Note that Sugar uses TinyMCE 3.5.8 and TCPdf 4.6.013.  These are not the latest available versions of these libraries.

The architecture of the SugarPDF API is described in the Developer Guide.  It can be customized in the usual way by creating your custom code at a special location under Sugar’s custom directory. We need to create a file at custom/modules/Meetings/sugarpdf/sugarpdf.pdfmanager.php where we can implement our logic to add related record information for the meeting:


require_once 'include/Sugarpdf/sugarpdf/sugarpdf.pdfmanager.php';

class MeetingsSugarpdfPdfmanager extends SugarpdfPdfmanager
    public function preDisplay()

        $previewMode = false;
        if (!empty($_REQUEST['pdf_preview']) && $_REQUEST['pdf_preview'] == 1) {
            $previewMode = true;

        if ($previewMode === false) {

            // Select links to add
            $linksToLoad = array('contacts', 'users');

            foreach ($linksToLoad as $linkName) {
                /** @var Meeting $this->bean */
                $linkedBeans = $this->bean->$linkName->getBeans();

                // Prepare data
                $linkedData = array();
                foreach ($linkedBeans as $linkedBean) {
                    $linkedData[] = PdfManagerHelper::parseBeanFields($linkedBean, true);

                // Assign data to template
                $this->ss->assign($linkName, $linkedData);

Now we can create our PDF template based on the Meeting module with the PDF Manager which can be found in the Administration panel:

<h1>Meeting Summary</h1>
{if isset($contacts) and $contacts|@count gt 0}
<h2>Contact Guests</h2>
<table style="width: 100%;" border="0">
<!-- {foreach from=$contacts item="contact"} -->
<td>Email {$contact.email1}</td>
<!--  {/foreach} --></tbody>
{/if} {if isset($users) and $users|@count gt 0}
<h2>User Guests</h2>
<table style="width: 100%;" border="0">
<!-- {foreach from=$users item="user"} -->
<!-- {/foreach} --></tbody>

Hey! When I copy and paste this code into the WYSIWYG editor it doesn’t appear the same! What is going on here?

You are right! By default TinyMCE will add an HTML p tag on every line. To avoid that you can adapt the configuration by creating a file at custom/include/tinyMCEDefaultConfig.php


$defaultConfig = array(
    'forced_root_block' => '',

Want to learn more about TinyMCE configuration in Sugar? Do not hesitate to read the world famous Sugar Developer Guide section on Modifying TinyMCE Editor!

Tips for your own Templates

You can follow some of these tips when you are thinking about creating a new template:

  • Use HTML comment tag to add Smarty operators where you want
  • Use inline styles instead of a CSS declaration
  • Remember that PDF generation is performed using the language selected by the current user

Do not forget to perform a Quick Repair and Rebuild to make your customizations available for the application.

Enjoy your new PDF summary for your meetings!

8 responses to How to customize the Sugar PDF Manager


    Thank you for the tips Cédric Mourizard. I was able to leverage the customizable sugarpdf.pdfmanager.php to include module specific css files in the document and use wkhtmltopdf instead of tcpdf for a cleaner PDF output.

      cedricmourizard April 25, 2016 at 1:18 pm

      You are very welcome, links to gist are missed on the article and matt will update to re-add them.


        Not sure why the Gist integration isn’t working. I’ve included the code in the post directly now. Apologies!

    fheidenstecker April 4, 2017 at 9:04 am

    Hi tthere, i am trying to get this to work for a costum module. It is related with accounts and notes. It is not working. I am not sure about the link name, where do i find it. I tried your example for meetings, it works out of the box !


    Hi Cédric,

    Manny thanks for this great article ; it was very useful for me.

    I also want to complete my usage with :

    – the possibility to also create your own smarty variable

    in the PHP file
    // populate the variable
    $mynewfields[‘key1′] = “my value is cool’;
    $mynewfields[‘key2’] = // I can do whatever I want (query any bean, any external source etc.)
    // push the variable to the smarty template
    $this->ss->assign(‘mynewfields’, $mynewfields);

    in the PDF / Smarty template

    {$mynewfields.key1} etc.

    – remove the smarty security if you want to use smarty debug instruction

    in the PHP file
    $this->ss->security = false;

    in the PDF / Smarty template
    {$var|@var_dump} or {$var|@print_r}

    One more time, many thanks Cédric.

      cedricmourizard August 10, 2017 at 12:21 am

      Thanks Frédéric for these additional tips!


      I have also used my own variables to allow for conditionally nested templates. I have a PDFDocument built as a combination of PDFDocuments. Before assigning the smarty variables I parse the HTML to replace the template markers with the templates themselves. Similarly, I have documents that are assembled with product-dependent PDFtemplates (a template multiselect in the Product catalog specifies which PDFtemplates to include for which product): If product A is included in the related products then append Documents A, C, D (as specified in the catalog) to the generated HTML before the smarty assignments and the generation of the PDF.