Hi Aspose,
I am trying to create a template xml then fill in the data dynamically.How can I achieve this?
I found the below thread. However, couldn’t find sample.xml file. And how to generate my own xml template file. Please advise.
Working with XML using C#|Aspose.PDF for .NET
Regards,
Su
Hi Su,
Pdf pdf = new Pdf();
pdf.BindXML("E:/Data/Template_new.xml", null);
DataTable getDT = creatDataTable();
//Get the section and then table from the obtained section of the Pdf that
//is built from the XML template
Section section1 = pdf.Sections["Section1"];
Aspose.Pdf.Generator.Table table1 = (Aspose.Pdf.Generator.Table)section1.Paragraphs["Table1"];
table1.ImportDataTable(getDT,true,0,0,5,2);
// Save the document
pdf.Save("E:/Data/XML_As_Template.pdf");
public static DataTable creatDataTable()
{
//Creating a DataTable object
DataTable dt = new DataTable("Sample");
//Adding columns to the DataTable
dt.Columns.Add("Beginning of lease", typeof(Int32));
dt.Columns.Add("End of lease", typeof(Int32));
//Adding rows to the DataTable
DataRow dr = dt.NewRow();
dr[0] = 12;
dr[1] = 11;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 22;
dr[1] = 22;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 41;
dr[1] = 41;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 47;
dr[1] = 40;
dt.Rows.Add(dr);
dr = dt.NewRow();
dr[0] = 28;
dr[1] = 20;
dt.Rows.Add(dr);
//Returning the instance of DataTable object
return dt;
}
Please feel free to contact us for any further assistance.
Best Regards,