How to Create a Custom Print PDF Template for Any Module in SuiteCRM

Home » Mississauga Digital Agency Blog » How to Create a Custom Print PDF Template for Any Module in SuiteCRM
Print pdf for custom module in SuiteCRM

One of the powerful features of SuiteCRM is the ability to generate print-ready PDFs directly from the CRM interface. While standard modules like Accounts and Invoices include this feature out of the box, you may need to enable this functionality for custom modules—such as a “Products” module for generating product data sheets. In this guide, I’ll show you how to set up custom PDF templates and integrate the “Print PDF” function into any custom module in SuiteCRM.

Note: This guide works with SuiteCRM 7. For SuiteCRM 8, you’ll need to configure the module as a “Legacy” module for the functionality to work.

Step 1: Add Your Custom Module to the PDF Template Type Dropdown

The first step is to make your custom module available in the “Type” dropdown of the PDF template module.

  1. Go to Admin > Dropdown Editor.
  2. Search for the dropdown list named pdf_template_type_dom.
  3. Add a new option:
    • Item Name: This should match your module’s directory name exactly. You can find this by checking your module folder under modules/ via FTP or your server’s file manager.
    • Display Label: Enter a user-friendly name for your module (e.g., “Products”).
  4. Save the changes.

Step 2: Add the “Print PDF” Option to the Module’s Detail View

To include the “Print PDF” button in your module’s detail view:

  1. Locate detailviewdefs.php:
    • File path: custom/modules/<your_module>/metadata/detailviewdefs.php.
  2. Add the button to the buttons array: Add the following code snippet to the buttons array in the file:
array (
    'customCode' => '<input type="button" class="button" onClick="showPopup(\'pdf\');" value="{$MOD.LBL_PRINT_AS_PDF}">'
),
  1. Create the Button Label:
  • Open (or create) the file: custom/modules/<your_module>/language/en_us.lang.php.
  • Add the label definition:
$mod_strings = array (
    'LBL_PRINT_AS_PDF' => 'Print PDF',
);
  1. Perform a Quick Repair and Rebuild:
  • Go to Admin > Repair > Quick Repair and Rebuild to refresh the changes.

Step 3: Implement the PDF Generation Logic

The final step is to link the “Print PDF” button to the PDF generation logic.

  1. Copy the view.detail.php File:
modules/AOS_Quotes/views/view.detail.php
  • Paste it into your custom module directory:
custom/modules/<your_module>/views/view.detail.php
  1. Update the Module-Specific References:
  • Replace all instances of the source module name (e.g., AOS_Quotes) with your module’s name (e.g., Products).
  1. Modify the PDF Template Query:
  • Update the query in the populateInvoiceTemplates function to filter templates by your module’s type:
$sql = "SELECT id, name FROM aos_pdf_templates WHERE deleted = 0 AND type='your_module' AND active = 1";
  1. Perform a Final Quick Repair and Rebuild:
  • Go to Admin > Repair > Quick Repair and Rebuild again to finalize the changes.

Step 4: Create a PDF Template

Now that your module supports PDF generation, you need to create a PDF template.

  1. Go to Admin > PDF Templates.
  2. Click “Create” and choose your custom module from the “Type” dropdown.
  3. Design your template using the available fields and formatting options.

Notes for SuiteCRM 8 Users

If you’re working in SuiteCRM 8, the PDF generation may not work unless your custom module is set to “Legacy.” Additionally, you might encounter an issue in the templateParser.php file.

To resolve this:

  1. Open the file: /legacy/modules/AOS_PDF_Templates/templateParser.php.
  2. Locate the following line:
$secureLink = $sugar_config['site_url'] . '/' . "public/" . $focus->id . '_' . $fieldName;
  1. Update it to:
$secureLink = $sugar_config['site_url'] . '/' . "public/legacy/public/" . $focus->id . '_' . $fieldName;

Testing and Troubleshooting

  1. Create or edit a record in your custom module.
  2. Use the “Print PDF” button to verify that the PDF is generated using your template.
  3. If the button doesn’t appear:
    • Double-check the detailviewdefs.php and en_us.lang.php files for syntax errors.
    • Clear the cache and perform a Repair and Rebuild.

Adding custom PDF generation to your modules in SuiteCRM can enhance reporting and provide professional, print-ready documents for your custom workflows. By following this guide, you’ll be able to implement this feature with ease while keeping your customizations upgrade-safe.

,
About the Author