Skip to content

Instantly share code, notes, and snippets.

@GroupDocsGists
Last active March 19, 2021 17:37
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/25951e2128f390c6ba1980c1bdaaa9c9 to your computer and use it in GitHub Desktop.
Save GroupDocsGists/25951e2128f390c6ba1980c1bdaaa9c9 to your computer and use it in GitHub Desktop.
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