Free Support Forum -

How to dynamically insert/update rows of a table in a pdf template file

I would like to have a pdf template file with a table with 2 columns, let us say one column is question number and other one is Comments. However, the number of rows could be dynamic depend on the data I get from our database.

For ex: sometimes the data could be something like the following and sometimes we could have 30 or 40 rows in the table.

Question Number Comments

2 Q2 comments

5 Comments for Q5.

The question is how do we create this pdf template file (consider our team don’t have much experience in pdf) and then dynamically update this table?

Hi Danny,

Thanks for your inquiry. Yes you can create PDF with a Table and can populate Table object with data from any data source using Aspose.Pdf for .NET. Please check a sample code snippet as following for the purpose. Hopefully it will help you to accomplish the requirements.

string outFile = myDir + “DynamicTable.pdf”;<o:p></o:p>

DataTable dt = new DataTable("Questions");

dt.Columns.Add("Question_Number", typeof(Int32));

dt.Columns.Add("Comments", typeof(string));

//Add 2 rows into the DataTable object programmatically

DataRow dr = dt.NewRow();

dr[0] =1;

dr[1] = "Comments of 1st question";


dr = dt.NewRow();

dr[0] = 2;

dr[1] = "Comments of 2nd question";


// Load source PDF document

Document doc = new Document();


// Initializes a new instance of the Table

Aspose.Pdf.Table table = new Aspose.Pdf.Table();

//Set column widths of the table

table.ColumnWidths = "100 300";

// Set the table border color as LightGray

table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

// set the border for table cells

table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));

table.ImportDataTable(dt, true, 0, 0,3,3);

// Add table object to first page of input document


// Save updated document containing table object


Please feel free to contact us for any further assistance.

Best Regards,

Thanks a lot for the quick reply. The situation I have is that we would like to have a template pdf file that has lots of static text and a table (with question number and comments columns) that could have dynamic number of rows. We want the Visual designer to format and style it and create a template pdf file for us. Then run a console program using pdf API to update the generated pdf file, basically populating the table using the dataset from DB or a xml file. It is kind of “mail merge”. Is there anyway to do this in Aspose.pdf?

Hi Danny,

Thanks for your inquiry. I am afraid Aspose.Pdf does not support mail merge functionality. Our another API, Aspose.Words, support the mail merge feature. As as workaround you can create a template in Word, use mail merge functionality using data from database and finally convert DOC/DOCX to PDF. If it fulfill your requirements then we can guide you about the Aspose.Words feature.

Best Regards,

Is this feature available as of yet to aspose.pdf? Or would it be coming in a future release? Along with the capabilities of reading from a table?

Hi Clifford,

Thanks for contacting support.

I am afraid the current release of Aspose.Pdf for .NET does not support the feature to manipulate tables in existing PDF files. However for the sake of implementation, we already have
logged this requirement in our issue tracking system under New Features list as
PDFNEWNET-36802. We will further investigate this requirement in details
and will keep you updated on the status of a correction.

We apologize for your inconvenience.

The issues you have found earlier (filed as PDFNEWNET-36802) have been fixed in Aspose.Pdf for .NET 10.6.0.

This message was posted using Notification2Forum from Downloads module by Aspose Notifier.