-
Notifications
You must be signed in to change notification settings - Fork 27
Generate Your First Document
Wei "oldrev" Li edited this page Nov 1, 2017
·
6 revisions
In this sample, I will show you how to use MaltReport to generate your very first document.
var employees = new Employee[]
{
new Employee{ Name = "Micheal Scott", JobTitle = "Branch Manager" },
new Employee{ Name = "Pam Beesly", JobTitle = "Office Administrator" },
new Employee{ Name = "Jim Halpert", JobTitle = "Salesman" },
new Employee{ Name = "Dwight Schrute", JobTitle = "Salesman" },
new Employee{ Name = "Andy Bernard", JobTitle = "Salesman" },
};
var image = new ImageBlob("jpeg", File.ReadAllBytes("Image.jpeg"));
var data = new Dictionary<string, object>()
{
{ "employees", employees },
{ "image", image },
};
var context = new TemplateContext(data);
using (var stream = File.OpenRead("EmployeesTemplate.odt"))
{
var odt = OdfDocument.Load(stream);
var template = new OdtTemplate(odt);
var result = template.Render(context);
var desktopDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var outputFile = Path.Combine(desktopDir, "generated.odt");
result.Save(outputFile);
}