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.
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.
- Go to Admin > Dropdown Editor.
- Search for the dropdown list named
pdf_template_type_dom
. - 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”).
- Item Name: This should match your module’s directory name exactly. You can find this by checking your module folder under
- 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:
- Locate
detailviewdefs.php
:- File path:
custom/modules/<your_module>/metadata/detailviewdefs.php
.
- File path:
- Add the button to the
buttons
array: Add the following code snippet to thebuttons
array in the file:
array (
'customCode' => '<input type="button" class="button" onClick="showPopup(\'pdf\');" value="{$MOD.LBL_PRINT_AS_PDF}">'
),
- 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',
);
- 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.
- 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
- 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
).
- 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";
- 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.
- Go to Admin > PDF Templates.
- Click “Create” and choose your custom module from the “Type” dropdown.
- 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:
- Open the file:
/legacy/modules/AOS_PDF_Templates/templateParser.php
. - Locate the following line:
$secureLink = $sugar_config['site_url'] . '/' . "public/" . $focus->id . '_' . $fieldName;
- Update it to:
$secureLink = $sugar_config['site_url'] . '/' . "public/legacy/public/" . $focus->id . '_' . $fieldName;
Testing and Troubleshooting
- Create or edit a record in your custom module.
- Use the “Print PDF” button to verify that the PDF is generated using your template.
- If the button doesn’t appear:
- Double-check the
detailviewdefs.php
anden_us.lang.php
files for syntax errors. - Clear the cache and perform a Repair and Rebuild.
- Double-check the
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.