Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate PDF or Word Reports from JSON data using Template in C#
// Generate PDF Report from JSON data using TXT template in C# with GroupDocs.Assembly API
// Define datasource, template, and output report files.
const string strDataSource = "dataPath/ManagerData.json";
const string strDocumentTemplate = "templatePath/template.txt";
const string strDocumentReport = "reportsPath/reportFromJSON.pdf";
// Instantiate JSON data source
JsonDataSource dataSource = new JsonDataSource(CommonUtilities.GetDataSourceDocument(strDataSource));
// Generate Report
DocumentAssembler assembler = new DocumentAssembler();
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate),
CommonUtilities.SetDestinationDocument(strDocumentReport),
new DataSourceInfo(dataSource, "managers"));
// Generate Word Report from JSON data using DOCX template in C# with GroupDocs.Assembly API
// Define datasource, template, and output report files.
const string strDataSource = "dataPath/ManagerData.json";
const string strDocumentTemplate = "templatePath/template.docx";
const string strDocumentReport = "reportsPath/reportFromJSON.docx";
// Instantiate JSON data source
JsonDataSource dataSource = new JsonDataSource(CommonUtilities.GetDataSourceDocument(strDataSource));
// Generate Report
DocumentAssembler assembler = new DocumentAssembler();
assembler.AssembleDocument(CommonUtilities.GetSourceDocument(strDocumentTemplate),
CommonUtilities.SetDestinationDocument(strDocumentReport),
new DataSourceInfo(dataSource, "managers"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment