I am using the mailmerge snippet provided in the following link https://docs.aspose.com/display/wordsjava/How+to+Mail+Merge+from+XML+using+IMailMergeDataSource to merge the data in rtf template from the xml file which is stored locally in android mobile internal storage.
I am attaching the source code, data file - xml file,rtf template and the expected pdf output document. I am using Android Studio IDE.
This is my sample code,
Document doc = new Document(filePath); // filePath would return a value as (/storage/emulated/0/TEMPLATE.rtf). We are retrieving the template file from the mobile device storage. javax.xml.parsers.DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder(); org.w3c.dom.Document xmlData = db.parse(new File(xmlPath)); //xmlPath would return a value as (/storage/emulated/0/TEMPLATE.xml). We are retrieving the template file from the mobile device storage. doc.getMailMerge().setPreserveUnusedTags(true); // Note that this class also works with a single repeatable region (and any nested regions). // To merge multiple regions at the same time from a single XML data source, use the XmlMailMergeDataSet class. // e.g doc.getMailMerge().executeWithRegions(new XmlMailMergeDataSet(xmlData)); doc.getMailMerge().executeWithRegions(new XmlMailMergeDataSet(xmlData)); doc.save(outputPath); //(e.g., /storage/emulated/0/TEMPLATE.pdf)
I am not getting any runtime error, however data from the xml file is not merged with rtf template.Template.zip (164.7 KB)