Quotes: Problems with PDF Creation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tobias
    Senior Member
    • May 2016
    • 229

    Quotes: Problems with PDF Creation

    We currently face the following issues:
    1. <p style="margin-top:6em;"> is being ignored (i.e., no top margin printed on PDF)
    2. {{#if lead.salutationName == 'foo'}}foo{{/if}} is always true (i.e., "foo" always printed on PDF)
    3. <p style="font-family:'Open Sans'> is being ignored (i.e., default font family printed on PDF)
    Your help is much appreciated.
    Last edited by tobias; 09-06-2017, 03:20 PM.
  • tobias
    Senior Member
    • May 2016
    • 229

    #2
    We sorted out 1) by using simple line-breaks.
    We accept 3) since Open Sans is not supported by the core version of TCPDF (https://tcpdf.org/docs/fonts/).

    This leaves us with 2) and that's really important for business communication in German language.

    Any ideas?

    Comment

    • tanya
      Senior Member
      • Jun 2014
      • 4308

      #3
      Hello

      {{#if}} checks only, if parameter is not empty (false, undefined, null, "", 0, or [])

      Comment

      • tobias
        Senior Member
        • May 2016
        • 229

        #4
        Ok, and how can we check if lead.salutationName == 'foo' in a template?

        Comment

        • tanya
          Senior Member
          • Jun 2014
          • 4308

          #5
          As I see, it needs some development


          An extremely fast PHP implementation of handlebars ( http://handlebarsjs.com/ ) and mustache ( http://mustache.github.io/ ), - zordius/lightncandy

          Comment

          • tobias
            Senior Member
            • May 2016
            • 229

            #6
            Ok, so what you suggest is to update application/Espo/Core/Htmlizer/Htmlizer.php as follows.

            Old:

            Code:
                  $code = \LightnCandy::compile($template, [
                        'helpers' => [
                            'file' => function ($context, $options) {
                                if (count($context) && $context[0]) {
                                    $id = $context[0];
                                    return "?entryPoint=attachment&id=" . $id;
                                }
                            }
                        ]
                    ]);
            New:

            Code:
                    $code = \LightnCandy::compile($template, [
                        'helpers' => [
                            'file' => function ($context, $options) {
                                if (count($context) && $context[0]) {
                                    $id = $context[0];
                                    return "?entryPoint=attachment&id=" . $id;
                                }
                            },
                            'ifcond' => function() {
                                // Get arguments
                                $args = func_get_args();
                                $context = $args[count($args) - 1];
                                if( (string) $args[0] === (string) $args[1] ) {
                                    // Arguments match, render it
                                    return $context['fn']();
                                } else {
                                    // If an {{else}} exists, render that instead; otherwise, render nothing
                                    return $context['inverse'] ? $context['inverse']() : '';
                                }
                            }
                        ]
                    ]);

            Comment

            • tanya
              Senior Member
              • Jun 2014
              • 4308

              #7
              This solution is not upgrade safe. Check, if this file wasn't touched with each upgrade. Maybe this functionality will be add in the future (not sure about the name of function will be the same as yours)

              Comment

              • tobias
                Senior Member
                • May 2016
                • 229

                #8
                Any ideas how to make this patch upgrade safe?

                We really need this to work to properly generate our business documents (quotes, invoices etc.). So if there's no other way, we need to check/re-patch with every update.

                Comment

                • tanya
                  Senior Member
                  • Jun 2014
                  • 4308

                  #9
                  No simple way... You can create own pdf builder, extends existing one. Too many manipulation for this... You upgrade crm not so often... For now easier to check, if file was changed. it's not so big probability, that file was modified in an upgrade
                  Last edited by tanya; 09-11-2017, 12:57 PM.

                  Comment

                  • tobias
                    Senior Member
                    • May 2016
                    • 229

                    #10
                    We've added the above code. However, the template would ignore the following code:
                    Code:
                    {{#ifcond lead.salutationName 'foo'}}foo{{/ifcond}}
                    Any suggestions?

                    Comment

                    • tobias
                      Senior Member
                      • May 2016
                      • 229

                      #11
                      Sorry to push again, but we really need this to work.

                      How would you call your own custom function "file" in a template? This should be the same as our custom function "ifcond", right?

                      Comment

                      • tanya
                        Senior Member
                        • Jun 2014
                        • 4308

                        #12

                        From the next version will be available ifEqual and IfNotEqual helpers
                        https://github.com/espocrm/espocrm/c...80a319fdeb7b91

                        Comment

                        • tobias
                          Senior Member
                          • May 2016
                          • 229

                          #13
                          Works a treat - thanks so much

                          Comment

                          Working...