Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Created July 10, 2021 09:53
Show Gist options
  • Save GroupDocsGists/836ca189a2cb4d2a7e5283c47a5a70ce to your computer and use it in GitHub Desktop.
Save GroupDocsGists/836ca189a2cb4d2a7e5283c47a5a70ce to your computer and use it in GitHub Desktop.
Convert XML data to Generate PDF and Word Reports using Template in Java
// Generate PDF Report from XML data using TXT template in Java
// Define datasource, template, and output report files.
String xmlDataSource = "dataPath/Managers.xml";
String templateFilePath = "templatePath/template.txt";
String reportFilePath = "reportsPath/PDFreportFromXML.pdf";
// Load XML data source
XmlDataSource datasource = new XmlDataSource(xmlDataSource);
DataSourceInfo dataSourceInfo = new DataSourceInfo(datasource,"managers");
// Assemble document to generate PDF
DocumentAssembler assembler = new DocumentAssembler();
assembler.assembleDocument(templateFilePath, reportFilePath,dataSourceInfo);
// Generate MS Word Report from XML data using text template in Java
// Define datasource, template, and output report files.
String xmlDataSource = "dataPath/Managers.xml";
String templateFilePath = "templatePath/template.docx";
String reportFilePath = "reportsPath/WordReportFromXML.docx";
//Instantiate XML data source
XmlDataSource datasource = new XmlDataSource(xmlDataSource);
DataSourceInfo dataSourceInfo = new DataSourceInfo(datasource,"managers");
//Assemble document
DocumentAssembler assembler = new DocumentAssembler();
assembler.assembleDocument(templateFilePath, reportFilePath,dataSourceInfo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment