Adding Print PDF Function to any module in SuiteCRM.
1 ) First We need to add your custom module in to *Type drop down of PDF template module
This We can do it by going to Admin > Drop Down Editor, We need to search for
pdf_template_type_dom drop down list and add -> option
Item name [ your custom directory name ] : To find the proper name path, FTP into the SuiteCRM server
and go to modules and use the exact name used on your module file
Display label [ Whatever name you want ]
Save it .
2 ) After this We need Print as pdf option in our details view page of custom module
- to add option in details view page open detailviewdefs.php
we can find this file under /custom/modules/<your module>/metadata/detailviewdefs.php
we need to add option in to buttons array
array (
'buttons' =>
array (
0 => 'EDIT',
1 => 'DUPLICATE',
2 => 'DELETE',
3 => 'FIND_DUPLICATES',
// add option like this (may vary slightly but function is the same, if list is different exclude “4 =>”)
4 => array ( 'customCode' => '<input type="button" class="button" onClick="showPopup(\'pdf\');"
value="{$MOD.LBL_PRINT_AS_PDF}">',
),
save it and check if you are not able to see the option. <-optional but recommended to make sure
everything is good at this point.
open custom/modules/<your module>/language/en_us.lang.php
add label in this file
$mod_strings = array ( 'LBL_PRINT_AS_PDF' => 'print PDF',);
If “$mod_strings = array (“ function exists, simply add:
'LBL_PRINT_AS_PDF' => 'print PDF',
To the array function.
Save it.
and check [ now option will be there ]( if option is still not there than delete cache and check )
3) now all we need to do is call function on click of option
for this, the easiest way is to copy the view.detail.php file from quotes or invoice module (see directory
below)
and replace it in the directory
custom/modules/<your module>/views/view.detail.php
You will replace existing module name with the module you are editing in a few spots:
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
require_once('include/MVC/View/views/view.detail.php');
class CasesViewDetail extends ViewDetail {
function CasesViewDetail(){
parent::ViewDetail();
}
function display(){
$this->populateInvoiceTemplates();
$this->displayPopupHtml();
parent::display();
}
function populateInvoiceTemplates(){
global $app_list_strings;
$sql = "SELECT id, name FROM aos_pdf_templates WHERE deleted = 0 AND
type='Cases' AND active = 1";
$res = $this->bean->db->query($sql);
$app_list_strings['template_ddown_c_list'] = array();
while($row = $this->bean->db->fetchByAssoc($res)){
$app_list_strings['template_ddown_c_list'][$row['id']] = $row['name'];
}
}
Replace the within the code, all within the first 30 line, the highlighted module names above with the
module you want to add.
After you are finished go to Admin > Repair > Quick Repair and Rebuild and let finish
Final step is to create a PDF Template for the desired module. Then test by creating or editing a record
and use the edit > Print PDF function.
Note: If any directory of file does not exist within the “custom” add the proper directories and file where
needed. Do not edit files outside of the “custom” directory because edits outside of this, are not upgrade
safe.