No Preview option in PDF Templates

Hi,

There is no preview option in the detail view of the PDF Templates module. How do I generate the PDFs and preview them, I have created a PDF template but I see no option to view the preview or download the template as PDF. I’ve googled with this issue but with no success.

I’ve included a snapshot of it.

Hi sid,

This is not standard functionality but sounds like a nice feature. Please place it in the suggestion box if you get time!

Thanks,

Will.

I dont see the point in previewing, just generate a PDF in a dummy quote or invoice and you will see what it looks like.

Thanks Will, Andy

I need to generate PDF out of a custom module. How do I go about doing that? I’ve looked at http://support.sugarcrm.com/02_Documentation/04_Sugar_Developer/Sugar_Developer_Guide_6.5/02_Application_Framework/SugarPDF/01_Generating_PDFs/ but not sure how to make it work. Please guide.

Thanks.

That is a completely different question than you asked originally ;).

The answer is you dont, not unless you custom code it yourself.

The PDF templates only work with Quotes, Invoices, Accounts, Leads and Contacts as standard functionality.

To generate a pdf from a custom module requries quite a bit of work.

Also that link you posted is to the sugar PDF template generation the one in SuiteCRM is different as sugar’s pdf generator was not included in CE.

Oh !! I have a demo on 2nd. Can you give me a lead on how and where can I start?

The basic steps you will have to carry out:

Create a custom a copy of generatePdf.php here:

custom/modules/AOS_PDF_Templates/generatePdf.php

Rename the copy MyCustomPdf.php

Then create a custom button on your custom module that calls the functions in your custom copy of MyCustomPdf.php.
(this will involve creating a custom controller and adding a custom action that includes MyCustomPdf.php)

edit MyCustomPdf.php to work with the fields in your custom module.

Create custom/modules/AOS_PDF_Templates/views/view.edit.php

edit the view.edit.php to include fields from your custom module so that they can be added to a pdf template.

Create a new pdf template for your module

Phew !! :slight_smile:

Thanks Andy will try it right away!!

And please post a guide with as much info as you can for future reference :smiley:

Thanks for lead Andy. Apologies for the late reply. The deadline got extended so got some time to explore. :wink:

I did it using the default “Generate Letter” option in the detail view of Accounts. First had to create the template and then included the “Generate Letter” option in my custom module and it generated the PDF for me. The only hitch though is I have several user entered line items in a particular subpanel. How do I include that in the PDF Template.

You will have to edit or create a new version of FormLetterPDF.php and alter the code in their to include the line items. Look at how its done in quotes and invoices and as I described above.

SpudR,
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

‘AOS_GENLET’ =>
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 http://archive.h2ik.co/2012/03/sugarcrm-upgrade-safe-way-to-extend-views/ to how to create the file. Now add the following piece of code in the display() method,

require_once(‘modules/AOS_PDF_Templates/formLetter.php’);
formLetter::DVPopupHtml(‘Custom_Module’);

And Voila !! This generates a PDF from a custom module in a custom designed template.
Hope this helps !!

Andy,
Will look into it.

Will,
I got what Andy was trying to say in #5725 as there is no point in providing a preview option in PDF Templates as ultimately you’ll have to select the record against which you need a PDF. So I guess it’s one and the same thing to go to the record and generate a PDF rather than have it generated from PDF Template. So didn’t include it in the Suggestion Box :slight_smile: .

Hi Andy,

I made some changes in the formLetterPdf.php file and have attached the zip file. Please check if it’s the correct method to proceed. It’s more of a workaround but as of now don’t have much time so have to go with it. There’s just a minor issue.

Whenever I output the $template->description, it shows me the template text with the html tags, but when I pass the $addTable variable it doesn’t output the tags and displays the table directly. Also if I remove the “Strip out html tags” in $search will it cause any abnormal behavior in the PDF output.

Hi,

I’m going forward with the customization I’ve done as attached in the post above.

But there seems to be a bug when the Generate Letter option is selected from the Custom Module. It doesn’t seem to take the Security Suite permissions, because if I do not assign a PDF Template to a particular user who has only owner rights, it still shows up on clicking the Generate Letter option.

I think you will have to write the code yourself that checks for security Suite permissions, its not hard but I cant remember exaclty how its done off hand.

No problem. I’ll give it a try. Also I would really appreciate if you could take some time out and check the zip file I attached a couple of posts earlier to check if it’s the correct flow I’ve created or if I need to change it.

it looks ok on first glance but Id really need to try and run it to fully understand whats going on and then advise you but I dont have time for that today.

1 Like

Okay no problem :slight_smile: