custom module pdf letter generation

I have done the below steps:

Here’s a detailed guide to how to generate a PDF out of a custom module for future reference :wink:

  1. Add your Custom Module in the Type dropdown of PDF Template. This will help you select your custom module for creating a sample. You do this by editing the “'pdf_template_type_dom” through the dropdown editor from the admin panel. The “item name” must be the name of the module directory.
  2. Add the default “Generate Letter” link in the actions dropdown in the detail view page of the custom module. To do this, you have to first edit the /custom/modules/Custom_Module/metadata/detailviewdefs.php file of the custom module and include

array (
‘customCode’ => ‘’,

in the buttons array.

  1. Next on, add the generate letter functionality. To do this, edit the view.detail.php file in custom/module//Custom_Module/views directory. If there is no such file or directory create it. You can look at to how to create the file. Now add the following piece of code in the display() method,


Now, generate letter option seems visible but when i click on that noting is happen .
might be it is unable to call any function

please help…

HI ,

i if i assume correctly you are trying to add print as PDF option in custom module

see the post

See the last post it works for me !

i hope this helps !

Thanks for your time and support

As you suggested

please find the attached screenshot for the files which i have modified to add the print pdf functionality

Hi arpit ,

As i have suggested the post , i think you did not follow the third step :dry:

anyways try to add this to function displaypopuphtml(); and populateQuotetemplates()

here it is

    function populateQuoteTemplates(){
        global $app_list_strings, $current_user;
        $sql = "SELECT id, name FROM aos_pdf_templates WHERE deleted=0 AND type='o_order' 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'];

    function displayPopupHtml(){
        global $app_list_strings,$app_strings, $mod_strings;
        $templates = array_keys($app_list_strings['template_ddown_c_list']);

        echo '  <div id="popupDiv_ara" style="display:none;position:fixed;top: 39%; left: 41%;opacity:1;z-index:9999;background:#FFFFFF;">
                <form id="popupForm" action="index.php?entryPoint=generatePdf" method="post">
                <table style="border: #000 solid 2px;padding-left:40px;padding-right:40px;padding-top:10px;padding-bottom:10px;font-size:110%;" >
                    <tr height="20">
                        <td colspan="2">
            foreach($templates as $template){

                $template = str_replace('^','',$template);
                $js = "document.getElementById('popupDivBack_ara').style.display='none';document.getElementById('popupDiv_ara').style.display='none';var form=document.getElementById('popupForm');if(form!=null){form.templateID.value='".$template."';form.submit();}else{alert('Error!');}";
                echo '<tr height="20">
                <td width="17" valign="center"><a href="#" onclick="'.$js.'"><img src="themes/default/images/txt_image_inline.gif" width="16" height="16" /></a></td>
                <td><b><a href="#" onclick="'.$js.'">'.$app_list_strings['template_ddown_c_list'][$template].'</a></b></td></tr>';
        echo '      <input type="hidden" name="templateID" value="" />
                <input type="hidden" name="task" value="pdf" />
                <input type="hidden" name="module" value="'.$_REQUEST['module'].'" />
                <input type="hidden" name="uid" value="'.$this->bean->id.'" />
                <tr style="height:10px;"><tr><tr><td colspan="2"><button style=" display: block;margin-left: auto;margin-right: auto" onclick="document.getElementById(\'popupDivBack_ara\').style.display=\'none\';document.getElementById(\'popupDiv_ara\').style.display=\'none\';return false;">Cancel</button></td></tr>
                <div id="popupDivBack_ara" onclick="\'none\';document.getElementById(\'popupDiv_ara\').style.display=\'none\';" style="top:0px;left:0px;position:fixed;height:100%;width:100%;background:#000000;opacity:0.5;display:none;vertical-align:middle;text-align:center;z-index:9998;">
                    function showPopup(task){
                        var form=document.getElementById(\'popupForm\');
                        var ppd=document.getElementById(\'popupDivBack_ara\');
                        var ppd2=document.getElementById(\'popupDiv_ara\');
                        if('.count($templates).' == 1){
                        }else if(form!=null && ppd!=null && ppd2!=null){
            echo '<script>
                function showPopup(task){

and don’t forget to call it under display function like this


don’t forget to generate PDFtemplate for respective module under PDFtemplate module !

you can also include the file above the class .

and add file mpdf.php if you are useing it !

and i hope u need to understand the solution and use it according to your needs . the post link is working fine try to understand it instead of copy paste !