generating pdf template in custom module


I am learning how to generate a pdf template in custom module. For learning simplicity, Im using the Accounts module. So, i have its files in /var/www/html/democrm/custom/modules/Accounts.

Now to generate PDF I have added a button to the bottom of the create account page as shown in the screen shot.

Here is the list of steps ive completed:

In the file /var/www/html/democrm/custom/modules/Accounts/language/en_us.lang.php I’ve added 'LBL_PRINT_AS_PDF' => 'Generate PDF' , label.

Ive added the button to the page using the following code after campaign_name :

3 => 
        array (
          0 => 'campaign_name',
         [b] 4 => array (
            'customCode' => '<input type="button" class="button" onClick="showPopup(\'pdf\');" value="{$MOD.LBL_PRINT_AS_PDF}">',

Next in the file /var/www/html/democrm/custom/modules/Accounts/views/view.detail.php I’ve added the following function:

        public function display(){
global $sugar_config;

//$aop_portal_enabled = !empty($sugar_config) && !empty($sugar_config);
//$this->ss->assign("AOP_PORTAL_ENABLED", $aop_portal_enabled);


in the file /var/www/html/democrm/custom/modules/Accounts/metadata/detailviewdefs.php

Ive added a fourth item:

array (
          0 => 'EDIT',
          1 => 'DUPLICATE',
          2 => 'DELETE',
          3 => 'FIND_DUPLICATES',
          4 =>
array (
'customCode' => '<input type="button" class="button" onClick="showPopup();" value="{$APP.LBL_GENERATE_LETTER}">',

In the file /var/www/html/democrm/custom/modules/Accounts/metadata/editviewdefs.php

Ive added the following code in 6:

 array (
          0 => 'campaign_name',
        6 => array(
               0 => array(
			'name' => 'GenerateQuote',
            'studio' => 'visible',
            //'label' => 'Quotation',
            'customCode' => '<input type="button" value="Generate PDF">',

Since Im new to this, I did not make my own module from scratch and tried to custmise the existing one (Accounts) with Generate pdf button but no luck. I searched all forums and refered to books but still nothing is working. My Generate pdf button as shown in the pic is not doing anything. Can anyone pls guide me where Im wrong?
ANy help will be greatly appreciated.

please take a look at this file

best regards


Thank you Mike. I am progressing with this. However, now my problem has changed. When I click on Print pdf, a blank screen comes with url index.php?entryPoint=generatePdf

I have searched all forums but didnt find a solution. My permissions are fine and there are no error logs in sugarcrm.log
Can you pls help me?
Thanks in advance

Got it.

The PDF link worked a treat, and was able to create the PDF in the custom module.

However, when generating the letter, the auto-linked modules
custom_module_created_by, custom_module_modified_user field information is available in the PDF
while the manually linked modules do not:
aos_quotes_custom_module fileds when linked in the PDF template maker, shows the variable names in the output PDF instead of their values.

Any ideas?

This is from the quote $cuz_swms_cuz_SWMS_1_billing_address_street
This is from thre quote also $cuz_swms_cuz_SWMS_1_name_billing_account
This is also from the quote $cuz_swms_cuz_swms_1_name_total_amt
This is from the Users (created by): User1
This is from the Users (modified by); User1

Well I tracked the problem to file modules/AOS_PDF_Templates/generatePDF.php lines 120 and 121, where the variable names are changed from aos_invoices and aos_quotes to $module_name. commenting these lines out fixes the problem.
Then, I am amazed to discover another instance of SuiteCRM doesn’t seem to suffer from this problem!?! (despite the same code being there in generatePdf. Ah well. Moving on…

Hi @mikebeck, the link you provided is awesome.
But i’m still not able to insert variables from related modules.

Use case: i’m building the PDF functionality for Meetings module
where i have a relationship 1:1 with a custom module: LS_Rapporti

The relationship name is: meetings_ls_rapporti_1

Values of all fields coming from that relationship, like: $meetings_ls_rapporti_1_name_description
are not printed: Result is empty.

Did anyone succeded with printing related modules variables?

It’s actually working for me on some deployments but not on others, although I cannot fathom why. Go through your apache/php logs to see why it doesn’t

The link to the instructions is going to a 404 error page. Anyone got a copy of the document, or a link that works?

I thought this may happen, so I saved it…

Thank you!

Hello All,

This add-on may help you guys. DocParser add-on not only parses related module data but also allow you to download a word document or PDF Document.
You just need to create Template and set relation data into that. and additionally, you will have options like Sorting, Numbering, record limit and an additional blank column for further process. If you want to have generated a document in bulk download, you have an option in list view to generate a mail merged document and download as a single zip.

Hello, plz the link of the docment dosn’t work, I need this document. thank you

Here you go


thank you for your answer :+1:

I’m glad I was able to help.

If any of you is still looking for ways to reference variables from related modules in PDF’s, have a look at my PowerReplacer add-on. If enough people sponsor me, it will eventually be donated into core SuiteCRM. There are also many additional advantages (like the ability to send the templated PDF directly form the Email in a campaign, without the need to generate and attach individually).

That’s great @pgr! Thank you!
I didn’t have any problems with reference variables from related modules. But I do have a problem with the filed assigned_user, which is not on drop down.
I tried adding manually $cases_assigned_user but no luck.
Does anybody have the same problem?
Thank you

I know this is an old thread, but it’s the first search result for people looking to add the PDF templates functionality to custom modules.

So I thought I’d post here a link to a PR that adds this automatically to basically every module:

I hope that gets merged soon

Good morning,
Thanks for the proposed changes to automatically generate PDFs from custom modules.
From the link provided above, I was able to add the personalized modules to the PDF model builder.
I just looked at the proposed change on Github and am wondering about displaying data from custom modules that are linked as currently they are not showing.
And if we want to make a loop (like for the products in the quotes and invoices), I think that the file /modules/AOS_PDF_Templates.php/generatePDF.php must also be modified, because this file retrieves the products by SQL query to display them specifically in a table in the PDF template for quotes or invoices.
It’s retrieving information from linked modules that I’m currently struggling to display in the generated PDF.

Will the changes proposed in the github make it possible to display the fields of the different linked modules, including with links 1 to N?

Thank you for your enlightenment

I think the PR adds the existing functionality to more modules, meaning: you can call it from more modules.

But it does not change the kinds of things that you can reference inside the templates; what you’re asking about are ways to fetch data from related modules, but that is not a current possibility unless you code it into the PHP files, as you mention.

My PowerReplacer add-on (see link in a post above) was created to address these limitations.