by Izertis

Create documents in docx, xlsx (MS Office Word and Excel), odt, ods (LibreOffice and OpenOffice) and pdf format without MS Office or others plugins installed from any module and subpanel using templates.

Includes a 30 day guarantee
Try it Now

#1208 - User Photo

Closed General Question created by drichardson Verified Purchase 2 years ago

I've read over the method to merge an image but its a bit confusing. I want to insert the User [photo] into a document. What is the correct method to do this? Is not not recognizong the field 'photo'.

  1. dharma member avatar

    Izertis Provider

    2 years ago

    Hi,

    Did you reviewed the template example "EXAMPLE - Opportunities Notes and Documents Images" associated to the Opportunity module?
    Just to be sure, below I am copying the Images section of the User Manual:


    Images:

    You can use the default 'cf_image_file_path' calculated field for Notes and Documents modules. If attached file to a Note or Document is an image (jpg, png, gif o tiff), we can merge the image to the generated document.
    Example:
    [a_sub1.cf_image_file_path;ope=changepic;default=current;adjust]

    (*) Change an internal picture with a new one:
    When having "ope=changepic" is merged in the template, then will search the first picture located before the field, and then it will change the picture assuming that the value of the field is the path for a picture file on the server.

    They are other complementary parameters that are provided for the changepic parameter:

    Default -- Define the picture that should be used when the expected one is not found. The parameter's value must be the path of a file on the server (default=uploads/empty.jpg) or the keyword "current". If you've set "default=current" then will let the picture of the template if the expected one is not found.
    Adjust -- Adjust the size of the picture in the document. This parameter requires that PHP is configured with the GD extension, which is usually the case. Values for adjust can be on of the followings:
    adjust (or adjust=inside) The picture is adjusted to enter into the picture bounds of the template.
    adjust=samewidth    The picture is adjusted to have the same width than the picture of the template.
    adjust=sameheigth The picture is adjusted to have the same height than the picture of the template.
    adjust=100% (or another percentage)     The picture is adjusted to be proportional to the originial size.

    The component will install the template example "EXAMPLE - Opportunities Notes and Documents Images" associated to the Opportunity module in order to test this kind of variables. This example can be found also in the next path: "modules/DHA_PlantillasDocumentos/examples/Opportunities_Notes_and_Documents_Images.docx"


    Regards,

  2. sinergiacrm member avatar

    sinergiacrm

    3 months ago

    Hi,

    The calculated field cf_image_file_path doesn't appear by the default in the User module.
    We tried to add it manually in the file "modules/DHA_PlantillasDocumentos/DHA_DocumentTemplatesCalculatedFields_base.php" . It does appear properly in the fields list. we add the config properties: ";ope=changepic;default=current;adjust" in the template, BUT the generated document only contains the file path, it doesn't display the image.

    Any thought?

    • dharma member avatar

      Izertis Provider

      3 months ago

      Hi,

      The file "modules/DHA_PlantillasDocumentos/DHA_DocumentTemplatesCalculatedFields_base.php" should not be directly modified because it could be overwritten in future versions. The cf_image_file_path variable is added by default for Notes and Documents only.
      If a variable is required for images from another module, it should be created in its corresponding calculated fields file.

      In your case, if the variable of the image path was created, and this variable is getting the correct value of the image path, and also the variable has been added in the template with the correct configuration (for example [a_sub1.cf_image_file_path;ope=changepic;default=current;adjust] ) probably it is because the substitution process cannot find the word image in which you should substitute that image. Any image should be added to the template, and right next to or below it the variable as described.

      The example template "modules/DHA_PlantillasDocumentos/examples/Opportunities_Notes_and_Documents_Images.docx" is distributed with the component (works for Notes and Documents) and there you can see how it should be.

      Regards

    • sinergiacrm member avatar

      sinergiacrm

      3 months ago

      Hi,

      Thanks for the quick reply.

      I have the following custom code for the field fotografia_c in Contacts module. But still not working:

       ///////////////////////////////////////////////////////////////////////////////////////////////////
         protected function SetCalcFieldsDefs() {
      
            global $app_strings;
      
            $this->CalcFieldsDefs['image_file_path'] = array (
                  'name' => 'image_file_path',
                  'vname' => $this->translate('LBL_IMAGE_FILE_PATH', 'DHA_PlantillasDocumentos'),
                  'type' => 'image_path',
                  'help' => 'Attached image path (only if attached file type is image)',
            );  
         }
      
         ///////////////////////////////////////////////////////////////////////////////////////////////////
         function CalcFields() {
            parent::CalcFields(); 
            $this->SetCalcValue('image_file_path', $this->get_image_path()); 
      
         }
      
         ///////////////////////////////////////////////////////////////////////////////////////////////////   
         protected function get_image_path() {
            global $sugar_config;
      
            $image_path = '';
            $image_path_original = '';
      
            $mime_types = array("image/jpeg", "image/gif", "image/png", "image/tiff", "image/pjpeg", "image/x-png", "image/x-tiff");
      
            $mime_type = strtolower("image/jpeg");
            $id = $this->bean->fotografia_c;
      
            if (!in_array($mime_type, $mime_types)) {
               return '';
            }
      
            $image_path_original = "upload://{$id}";
      
            $templates_dir = $sugar_config['DHA_templates_dir'];
            $templates_dir = $this->Generate_Document_Instance->includeTrailingCharacter ($templates_dir, '/');
            if (!file_exists($templates_dir)) {
               return '';
            } 
            $image_ext = '';
            if ($mime_type == "image/jpeg" || $mime_type == "image/pjpeg")
               $image_ext = 'jpg';
            elseif ($mime_type == "image/gif")
               $image_ext = 'gif';
            elseif ($mime_type == "image/png" || $mime_type == "image/x-png")
               $image_ext = 'png';
            elseif ($mime_type == "image/tiff" || $mime_type == "image/x-tiff")
               $image_ext = 'tiff';
      
            $image_path = $templates_dir . $id . '.' . $image_ext;      
      
            if (copy ($image_path_original, $image_path)) {
               // $this->Generate_Document_Instance->temp_files[] = $image_path;  // esto es para que se borre automaticamente la imagen temporal cuando ya se ha generado el documento
               return $image_path; 
            }
            else {
               return '';
            }
         } 
      

      Any thought?

      Thanks for your help

    • dharma member avatar

      Izertis Provider

      3 months ago

      The first thing to check is that the variable that has been created is correctly returning the path where the image is on disk.
      That is, in the template, instead of
      XX.cf_image_file_path;ope=changepic;default=current;adjust]
      try on
      [XX.cf_image_file_path]
      Where 'XX' is the name of the data set in which the variable is found.

      If the variable is for Contacts module, there are already a calculated fields file provided with the component that should be extended:
      \custom\modules\Contacts\DHA_DocumentTemplatesCalculatedFields.php
      The new contact variables would be added there.
      A possible problem is that being in this case a file supplied by the component, maybe will be overrided in a future update.

  3. sinergiacrm member avatar

    sinergiacrm

    3 months ago

    When [XX.cf_image_file_path] is used, it shows the image path "document_templates/id_of_the_image.extension"

    When [XX.cf_image_file_path;ope=changepic;default=current;adjust] is used, it also shows the same image path. In some test using this option, it doesn't generates the document and shows this error:

    TinyButStrong Error : TBS is not able to merge the field [a.cf_image_file_path;ope=changepic;default=current;adjust] because the entity targeted by parameter 'att' cannot be found.

    TinyButStrong Error Show() Method: The output is cancelled by the OpenTBS plugin because at least one error has occured.

    Although I hope it has something to do with text format and usage of LibreOffice.

    What can we do next?

    Thanks a lot. Hope we are closer.

  4. sinergiacrm member avatar

    sinergiacrm

    3 months ago

    Disregard my last messages. It is working fine now.

    I wasn't including the dummy picture in the template. I fully understood it when I read the spanish documentation that explains it a bit more detailed.

    Thanks for your help.

This case is public. Please leave out any sensitive information such as URLs, passwords, etc.
Saving Comment Saving Comment...
Rating
  • "It has improved our processes so much! Admin cut in half! We send a webform to clients to sign up straight into CRM then generate and print their paperwork to sign."

    Read More Reviews