No Preview option in PDF Templates

Thanks Sid
Most appreciated!
:slight_smile:

Youā€™re welcome !! :slight_smile:

can we do like this its generating pdf in custome module

1 ) first We need to add your custom module in to *Type drop down of PDF template module

  • This We can do it by drop down editor from admin , We need to search for pdf_template_type_dom drop down list and add -> option

Item name [ your custom directory name ] : example my custom module is ca_payment
Display label [ your wish ] : in my case i have given Payment
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//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
4 => array ( ā€˜customCodeā€™ => ā€˜ā€™,
),

save it and check if you are not able to see the optin than

open custom/modules//language/en_us.lang.php
add label in this file

$mod_strings = array ( ā€˜LBL_PRINT_AS_PDFā€™ => ā€˜print PDFā€™,);

save it
and check [ now option will be there ]( if option is still not there than delete cache and check )

  1. now all we need to do is call function on click of option
    for this easiest way which i did copy the view.detail.php file from qoues or invoice

and replace it with custom/modules//views/view.detail.php

mostly following function will be there in the file

b_bookViewDetail
display
populateInvoiceTemplates
displayPopupHtml

replace the aos_qotes with your custom module name

Thanks for your steps but its still not working
Actually when i click on print pdf noting is happening

Hi Arpit ,

Make sure u have Pdf template created for respective module ( module which you are trying to add print as pdf option ) under PDF Template module !

Hi,

I have double checked what you said, but it is still not working ā€¦ :frowning:

Hi arpit ,

it would be nice if you can share the details of where you did the changes in files . with some screen shoots . on the your original post .

and you can also make use of Mpdf class unser :

require_once(ā€˜modules/AOS_PDF_Templates/PDF_Lib/mpdf.phpā€™);

My apologies if Iā€™m beating this topic to death but Iā€™ve tried following Sidā€™s instructions (#5953) on creating the functionality of PDF templates working with custom modules but Iā€™ve run into a wall now aka lack of knowledge

1)I have my module(class attendees) available in the PDF template dropdown and it pulls data from the module to create a tempalte,
2) I have a the ā€œGenerate Letterā€ button in the detail view of the Attendees module showing
3) When I click Generate Letter I can view the list of available templates

  1. When I select any template I get the following error

Fatal error: Class ā€˜Atnd_Attendeeā€™ not found in /home/safety456/webapps/suitecrm/modules/AOS_PDF_Templates/formLetterPdf.php on line 39

I;'ve looked at this line which is below but not sure where to go from here. does anyone have any suggestions?

39| $module = new $module_type_create();

Here is the code I used to create the extended view in cusomt/moduleAttendee/views/detailview.php

require_once(ā€˜include/MVC/View/views/view.detail.phpā€™);
class CustomAtnd_AttendeesViewDetail extends ViewDetail{
public function display(){
global $sugar_config;

	//$aop_portal_enabled = !empty($sugar_config['aop']['enable_portal']) && !empty($sugar_config['aop']['enable_aop']);
    //$this->ss->assign("AOP_PORTAL_ENABLED", $aop_portal_enabled);
    
	require_once('modules/AOS_PDF_Templates/formLetter.php');
    formLetter::DVPopupHtml('Atnd_Attendees');
    parent::display();
}

}

Sidenote: This is running on 7.2 Release

You are almost there!

Are you sure ā€˜Atnd_Attendeeā€™ is the exact name of your module and its not ā€˜Atnd_Attendeesā€™? If you look at line 36 you will see $module_type_create = rtrim($module_type,ā€˜sā€™); This line is stripping the ā€˜sā€™ off the the module name and we need this for standard modules but with custom modules it may cause problems. Basically when the ā€˜sā€™ is stripped off your modules name it is no longer recognised. So what I would do is add an if statement to check for your module and not strip the ā€˜sā€™ off.

After line 37 add this:



    if($_REQUEST['module'] == 'Atnd_Attendees'){
        $module_type_create = $_REQUEST['module'];
    }

I also noticed you are not doing this in the custom folder so these changes wont be upgrade safe.

1 Like

Hi Andy,

Thank you for your suggestion. I applied it and the pdf templates are working in my custom module. (you were correct my custom file name is Atnd_Attenddees not Atnd_Attendee as I wrote)


As you mentioned this change is not upgrade safe. knowing this now, I copied the AOS_PDF_Templates folder to the custom folder. However, when I do this Iā€™m getting same error of ā€œ39| $module = new $module_type_create();ā€ even though I included the if statement as directed.

Iā€™m not a programmer but to me it seems that when I click on the pdf template name it does not know to look in custom/module/AOS_PDF_Templates/formLetterPdf.php, thus the same error

I would prefer to make this pdf template feature upgrade safe, How would I go about this if you wouldnā€™t mind sharing?

Thank you again

In the view.detail.php change this line to the custom version of your formLetter.php


require_once('modules/AOS_PDF_Templates/formLetter.php');

to


require_once('custom/modules/AOS_PDF_Templates/formLetter.php');

But to be truly upgrade safe you will have to create a custom version of the view.detail.php in the custom folder of your module and then add the above line to that.

2 Likes

I am trying to get Generate Letter working for Cases module. I have done everything as advised on this and other threads. I get the button and I get the popup showing templates made for Cases module. But when I click one of the templates I get a blank page with url: http://office.advokatibijeljina.com/index.php?entryPoint=formLetter and no dowload.

Is there anything specific when trying to add Generate Letter functionality to one of basic modules like Cases? Any help or clue what I am I doing wrong?

THX!

Hi
Ive been following the guides for adding a generate letter function to a custom module and iā€™ve hit a brick wall, iā€™ve gone over everything a few times and even started from scratch but i seem to hit the same point as bojkic in that the function results in a blank white page:

I have a ā€œgenerate letterā€ button in my custom module detail view,
I have a pdf template set up for the module which shows up as a pop up when you press ā€œgenerate letterā€ but then i just get a white screen.

Iā€™ve checked for errors in the log and in chrome developer consul of which i have attached screen grabs and i have also attached copies of the custom/modules/[custom_module]views and the ListViewSmarty.php that i created in the custom/modules/[custom_module] folder.

If anyone could point me in the right direction iā€™d be really happy as iā€™m feeling pretty dumb right now! :S

Thanks

Have you checked the php error log?

Here is the log, iā€™ve had a look but canā€™t work it out, iā€™ll have a good look over the weekend unless someone spots something obvious?

THanks
Rob

looks like it is a bug in formLetterPdf.php

so any suggestion how to fix it? I have tried many things but with Cases module I always end up with black page /index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DCases%26action%3DDetailView%26record%3D1de544d5-dacd-7347-0a3a-55bb2f306a57

Timelyā€¦ Iā€™m getting exactly the same problem now that Iā€™ve figured out how to actually add the button.

BTW - EVERYTHING on the web talks about ā€œadding 'AOS_GENLET ā€™ => ā€¦ā€ etc. to your detailviewdef.php file in your custom module. Big problem - most custom modules wonā€™t have that file, and if you copy the one from another built-in module, youā€™re going to have a hell of a time rewriting it (your panels, etc.). Worse, if you just add a button to the array without the rest of the code thatā€™s normally in that file, youā€™ll get nothing but the button!

Best way: Find the cache-generated detailviewdef.php file, copy it to your custom metadata directory, and add the button there:

find /yourWebRoot/suitecrm/ -iname detailviewdefs.php | grep YourModuleName
cp eb50-upload/upgrades/temp/0113Y4/SugarModules/modules/YourModuleName/metadata/detailviewdefs.php custom/modules/YourModuleName/metadata/

Bang, it all works (except for this blank screen bug).
Soā€¦ any thoughts on what the bug is in formLetterPdf.php?

I made button work fine, and appropriate list of the templates appears, however when I click on the template I get a blank screenā€¦

Bingoā€¦ formLetterPdf.php has a debug line right up top! (Clever, saves me the effort!) soooā€¦

Fatal error: Class ā€˜your_ModuleNameā€™ not found in /yourWebRoot/suitecrm/modules/AOS_PDF_Templates/formLetterPdf.php on line 39

Anyone know how to properly instantiate and include the class of a custom module youā€™ve built?

Admins? Will?