Free Support Forum - aspose.com

Create Template and fill in data dynamically

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.
http://www.aspose.com/docs/display/pdfnet/Load+data+in+XML+Template+and+convert+to+PDF


Regards,
Su

Hi Su,


Thanks for your inquiry. Please find sample XML(Aspose.Pdf XSD schema compliant) and sample code to fill it, Please note this approach is using old generator(Aspose.Pdf.Generator) it will be obsolete in future. We are shifting to new generator (Aspose.Pdf), it is more efficient and improved. It can be used for both creating a PDF document form scratch or manipulate existing one.

We have created a feature request PDFNEWNET-39380 for subjected feature in new generator. We will notify you as soon as it is implemented in new generator, so you can migrate to it accordingly.

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,