Using Custom Data Sources for Advanced Printing

To include a custom data source:

  1. Customize a standard template and use the source code view to add the new fields.
  2. The sections with fields from the custom data source have to be surrounded by the FreeMarker tags <#if ALIAS?has_content> </#if>. The element is required because custom data sources cannot be displayed in the template editor. If you view a preview of the template, the external data source is not shown.
  3. Because FreeMarker supports only XML, JSON data sources have the same restrictions as XML, for example, a property cannot start with a digit. The JSON data source is converted to XML for printing.
  4. You must know what information is included in the external data source and use syntax like the following:

        <?xml version=”1.0″?>

<!DOCTYPE pdf PUBLIC “-//big.faceless.org//report” “report-1.1.dtd”>

<pdf>

<body> Custom Data Sources: <#if XML?has_content> ${XML.book.title}<br /> ${XML.book.chapter[1].title} </#if> <br /> <#if JSON?has_content> ${JSON.book.title}<br /> ${JSON.book.chapter[1].title} </#if> <br /> <#if JSON_STR?has_content> ${JSON_STR.book.title} </#if> <br /> <#if XML_STR?has_content> ${XML_STR.book.title} </#if>

</body>

</pdf> 

renderer.addCustomDataSource({format: render.DataSource.XML_DOC, alias: “XML”, data: xmlObj});

renderer.addCustomDataSource({format: render.DataSource.XML_STRING, alias: “XML_STR”, data: xmlString});

renderer.addCustomDataSource({format: render.DataSource.OBJECT, alias: “JSON”, data: jsonObj});

renderer.addCustomDataSource({format: render.DataSource.JSON, alias: “JSON_STR”, data: jsonString}); 

        

Leave a comment

Your email address will not be published. Required fields are marked *