Hi,
I’m trying to create a document from dynamic xml source and associated template document with LINQ Reporting Engine in Java
The scenario is: Given folder with data.xml
, images
, barcodes
, qr's
and templates in docx (with fields mapped to xml tags)
to generate a final document with all components
The current implementation is using MailMerge Fields with IFieldMergingCallback:
var dataDir = "src/main/resources/";
Document doc = new Document(dataDir + "template1.docx");
var ds = new DataSet();
ds.readXml(xmlNode); //Xml node of first "ID" element as bytearray
doc.getMailMerge().setFieldMergingCallback(mergeFieldCustom);
doc.getMailMerge().executeWithRegions(ds);
doc.save(dataDir + "generated.docx");
IFieldMergingCallback is used with a scope to implement custom functions defined inside the template document (ex custom text formats, number formats, replace functions, required fields etc…)
data.xml content has dynamic structure and generated from “outside”:
<General>
<Data>
<ID templateName="template1.docx">
<documentId>documentId1</documentId>
<text>Some text field</text>
<image1>images/image1.png</image1> #Image loaded using IFieldMergingCallback
<image2>images/image2.png</image2> #Image loaded using IFieldMergingCallback
<qrcode>BARCODE CONTENT IN TEXT</qrcode> #QR code rendered as image in template using IFieldMergingCallback
</ID>
<ID templateName="template2.docx">
<documentId>documentId2</documentId>
<text>Some text field</text>
<image1>images/image3.png</image1>
<image2>images/image4.png</image2>
<qrcode>BARCODE CONTENT IN TEXT</qrcode>
</ID>
</Data>
</General>
Template content:
Text:
{{ MERGEFIELD text }}
Expected: Some text field
Image1:
{{ MERGEFIELD IMAGE_image1 }}
Expected: [image]
Image2:
{{ MERGEFIELD IMAGE_image2 }}
Expected: [image]
Qr:
{{ MERGEFIELD QR_qr_code}}
Expected: [barcode image]
Formatted Text in uppercase:
{{ MERGEFIELD $FF(text, "UPPERCASE") }}
Expected: SOME TEXT FIELD
Required field:
{{ MERGEFIELD REQUIRED_not_existing_field }}
Expected: *EXCEPTION*
Now i’m trying to migrate this functionality to Reporting Engine and my questions are:
- Is it possible to use someting similar to IFieldMergingCallback?
- Is it possible to extend custom tag inside a document template (something like
<<qrcode [expression] -params>>
)? - Any example of using custom types methioned in this answer: How to use custom tag for LINQ Reporting Engine using .NET - #2 by tahir.manzoor
Thanks.