Uploaded image for project: 'Nuxeo Platform'
  1. Nuxeo Platform
  2. NXP-23080

Freemaker template rendered as plain html

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Not A Bug
    • Affects Version/s: 9.2
    • Fix Version/s: None
    • Component/s: Automation

      Description

      Steps to reproduce:

      • Create a fremarker template to generate a pdf
      BASimulateImport
      <html>
      <head>
          <style type="text/css">
              .coverPageTitle {
                  font-family: Geneva, Tahoma, Verdana, sans-serif;
                  font-size: 20px;
                  font-weight: bold;
                  text-align: center;
              }
      
              .tableClass {
                  width: 100%;
      
                  border-collapse: collapse;
              }
      
              @page {
                  size: 8.5in 11in;
                  font-family: Geneva, Tahoma, Verdana, sans-serif;
                  /* this affects the margin in the printer settings */
                  margin: 40mm 10mm;
              }
      
              body {
                  font-family: Geneva, Tahoma, Verdana, sans-serif;
              }
      
              .contentDiv{
                  margin: 1px 3px;
              }
      
              .thClass{
                  border:1px solid black;
                  background-color: #CCCCCC;
                  text-align:left;padding:0px;
                  overflow:hidden;height:20px;
              }
      
              .tableClass{
                  border:1px solid #000;
                  border-collapse: collapse;
                  width: 100%;
              }
      
              .tdClass{
                  border:1px solid #000;
              }
          </style>
      
          <title>Automatic Import</title>
      </head>
      <body>
          <#list This as doc>
      
              <h1 class="pageTitle">${doc.title}</h1>
      
              <p>
              Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam egestas lectus nibh, non vestibulum dolor tincidunt vitae. Vestibulum nec mattis elit. Nunc 
              vestibulum lacinia magna at commodo. Donec interdum ornare consequat. Donec sit amet venenatis ex. Nullam pretium at nunc vel aliquet. Donec 
              posuere tempus metus. Proin sagittis, odio id venenatis finibus, orci dolor congue nunc, in efficitur ante turpis vel massa. Aliquam gravida turpis et elit 
              mollis pulvinar. Ut feugiat, sem in tempor porta, arcu neque tristique turpis, sed venenatis tortor lorem sit amet massa. Morbi ac lacus sed ante finibus 
              dictum vitae sit amet felis. Ut volutpat mollis tortor sit amet pulvinar.
              </p>
      
              <table class="tableClass">
                  <caption>${doc.title}</caption>
                  <tr>
                      <th class="thClass">
                          <div class="contentDiv">Description</div>
                      </th>
                      <th class="thClass">
                          <div class="contentDiv">Amount</div>
                      </th>
                      <th class="thClass">
                          <div class="contentDiv">Date</div>
                      </th>
                  </tr>
      
                  <tr>
                      <td class="tdClass">
                          <div class="contentDiv">Lorem ipsum dolor sit amet</div>
                      </td>
                      <td class="tdClass">
                          <div class="contentDiv">100 €</div>
                      </td>
                      <td class="tdClass">
                          <div class="contentDiv">23/09/2016</div>
                      </td>             
                  </tr>
      
                  <tr>
                      <td class="tdClass">
                          <div class="contentDiv">Lorem ipsum dolor sit amet</div>
                      </td>
                      <td class="tdClass">
                          <div class="contentDiv">582 €</div>
                      </td>
                      <td class="tdClass">
                          <div class="contentDiv">01/09/2016</div>
                      </td>             
                  </tr>
              </table>
                 
          </#list>
      </body>
      </html>
      
      • Create an automation script to generate a pdf
      BAAutoScriptSimulateLoadContentFromExternalSystem
      function run(input, params) {
        //Recover all the children documents 
        var children = Document.GetChildren(input, {});
        Console.log("Children recovered");
        
        
        if(undefined !== children && children !== null){
          var i=0;
          var title = null;
          var numChildren = children.length;
          Console.log("# Children: " + numChildren);
             
          for(i=0; i<numChildren; i++){
            
            title = children[i].getTitle();
            Console.log("title:" + title);
            
            ////////////////////////////////////////////////////////////////
            // Generate a pdf with a fake content
            ////////////////////////////////////////////////////////////////
            var childBlob = Render.Document(children[i], {
              'template': 'template:BASimulateImport',
              'filename': title + '-import.ftl',
              'mimetype': 'text/xml',
              'type': 'ftl',
            });
            Console.log("----------------------------/\----------------------------" );
            Console.log("Child blob generated" );
            
            var pdf = Blob.ToPDF(childBlob, {});
            Console.log("Child blob converted to PDF" );
            
            
            // /////////////////////////////////////////////////
            // Attach the pdf 
            // /////////////////////////////////////////////////
            Blob.AttachOnDocument(
              pdf, {
      	/*required:true - type: document*/
      	'document': children[i],
      	/*required:false - type: boolean*/
      	'save': true,
              'xpath': 'file:content'
            });      
            Console.log("PDF attached on document" );
      
            
            Document.SetProperty(children[i], {'xpath': 'BARCheckRequest:status', 'save': true , 'value': 'ValidatedWithInfo'});
            Console.log("Child state updated" );
          }   
      
        }
        else{
          Console.log("No children found!!!" );
        }
        
        return input;
      }
      
      • Create a button in Web UI to execute the automation script
      • Reload the config
      • Click on the new button in Web UI

      The pdf is generated, but contains plain html, with the freemarker sentences replaced. The template is not rendered as a web page.

      Project details in private comment

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 4 hours
                  4h