Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active March 19, 2021 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GroupDocsGists/7aa7fe4f1a969e13339ace6ba8c51906 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/7aa7fe4f1a969e13339ace6ba8c51906 to your computer and use it in GitHub Desktop.
Generate PDF or Word Report from JSON data using Template in Java
// Generate PDF Report from JSON data using TXT template in Java with GroupDocs.Assembly API
// Define datasource, template, and output report files.
String jsonFilePath = "dataPath/ManagerData.json";
String templateFilePath = "templatePath/template.txt";
String reportFilePath = "reportsPath/reportFromJSON.pdf";
// Instantiate JSON data source
JsonDataSource datasource= new JsonDataSource(jsonFilePath);
DataSourceInfo dataSourceInfo = new DataSourceInfo(datasource,"managers");
// Generate Report
DocumentAssembler assembler = new DocumentAssembler();
assembler.assembleDocument(templateFilePath,reportFilePath,dataSourceInfo);
// Generate Word Report from JSON data using DOCX template in Java with GroupDocs.Assembly API
// Define datasource, template, and output report files.
String jsonFilePath = "dataPath/ManagerData.json";
String templateFilePath = "templatePath/template.docx";
String reportFilePath = "reportsPath/reportFromJSON.docx";
// Instantiate JSON data source
JsonDataSource datasource= new JsonDataSource(jsonFilePath);
DataSourceInfo dataSourceInfo = new DataSourceInfo(datasource,"managers");
// Generate Report
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