Print pdf in custom module

Hi, i have used this to create a pdf print menu to my custom module. the menu “print PDF” appears, but it still not working. when i click on nothing happens. any idea ?

Welcome to community!

Look at the discussion: Print button in subpanel
Please write if isn’t enough information there.

this AddingPrintPDFtocustomModule.pdf was usefull .
my problem was solved after adding
in ** function display()**
thanks !

I’m stuck on the same issue I added your suggestion to public function but doesn’t seem to work, even after repair and rebuild, in SuiteCRM 8 is modules/… ok or do I need public/legacy/modules/…

Ok I’m getting somewhere…

 public function display()
		require_once('modules/AOS_PDF_Templates/formLetter.php'); formLetter::DVPopupHtml('PLNE_Planes');

Gets me the template popup. The PDF Parser starts, but now I get…

Warning: copy(upload//9bb5fd2b-8a83-4351-7157-627e92f74bd6_photo): failed to open stream: No such file or directory in /home/XXXXXXXXXXX/public_html/lancair/public/legacy/modules/AOS_PDF_Templates/templateParser.php on line 103
TCPDF ERROR: Some data has already been output, can't send PDF file

I have an image field in the module Line 103 in the parser refers to the URL. I’m thinking maybe the upload// with two slashes is the problem.

I tested with a image field in Contacts in SuiteCRM 7 and works with an image. Hmmm.

Ok, I’ve got this totally working if I comment out the …elseif type = Image part of the code so the image is the issue…

There’s something wrong with it. I managed to remove the first slash, so that works, however it’s not getting the file ID right either and the _photo is not the fieldname. It should be _image1 it seems to be inserting the field “type” when it should be outputting the field name. If I change it to $focus->$fieldName I get the contents of the field (the filename). Trying to get the field name.

Anyone see what’s going on here?

elseif ($field_def['type'] == 'image') {
                   $secureLink = $sugar_config['site_url'] . '/' . "public/" . $focus->id . '_' . $fieldName;
                 //   $file_location = $sugar_config['upload_dir'] . '/' . $focus->id . '_' . $fieldName;
				 $file_location = $sugar_config['upload_dir'] . '' . $focus->id . '_' . $fieldName;
                    // create a copy with correct extension by mime type
                    if (!file_exists('public')) {
                        sugar_mkdir('public', 0777);
                    if (!copy($file_location, "public/{$focus->id}".  '_' . (string)$fieldName)) {
                        $secureLink = $sugar_config['site_url'] . '/'. $file_location;

                    if (empty($focus->{$fieldName})) {
                        $repl_arr[$key . "_" . $fieldName] = "";
                    } else {
                        $link = $secureLink;
                        $repl_arr[$key . "_" . $fieldName] = '<img src="' . $link . '" width="' . $field_def['width'] . '" height="' . $field_def['height'] . '"/>';

The problem line is actual the $file_location I think.

It’s outputting:

It’s outputing upload//(created by userid)_(field type)

when it should be outputting:
upload/(file id)_(field name)

Strangely, in my SuiteCRM 7 installation, this works fine for a non custom module. In SuiteCRM 8 I tested with Quotes (had to find a legacy module that supports images) and images don’t work if you add to the quote header either in 8.

What do you have in site_url? Check both config.php and config_override.php.

Do you have a trailing slash there perhaps?

Thanks @pgr I checked that and is OK. The extra slash isn’t the major issue here. For some reason it’s not constructing the URL correctly. It should be upload/fieldID_fieldname and for some reason it’s constructing: upload/userid_filetype

I think it’s the $filelocation definition but just can’t seem to figure it out. Little above my PHP skills I’m not understanding completely how $focus works. $fieldName gives me the field type (photo)of the field, when I think it should be outputing the field name. If I try subbing in $focus ->$fieldName again, I’m thinking I should get the field name but get the contents of the field (the filename).

Other than image fields, I’ve pretty much got the PDF printing working for custom post types. I’d love to make a video for everyone on this one, seems pretty common, but I’m stuck on the image field not working.

It totally works with an image in SuiteCRM. 7

OK thanks for you help @pgr.

After more testing (I tried a million things to get it to work). It only worked because I copied the files into the /public/ directory. When I tried a second one, it didn’t work. Therefore, the file location is the problem. Found a bug and solved it.

in /legacy/modules/AOS_PDF_Templetes/templateParser.php


$secureLink = $sugar_config['site_url'] . '/' . "public/" . $focus->id . '_' . $fieldName;


$secureLink = $sugar_config['site_url'] . '/' . "public/legacy/public/" . $focus->id . '_' . $fieldName;

PDF’s now show images!!!

Stay tuned for instructional video and documentation. Some of the past threads have a few errors in them I’ve cleaned up and the documentation needs to be slightly changed for SuiteCRM 8 (file locations).

Here’s the issue on Github I just created:


1 Like