String _dataDir("C:\\Samples\\");
// Load source PDF document
auto document = MakeObject<Document>(_dataDir + u"AddTable.pdf");
// Initializes a new instance of the Table
auto table = MakeObject<Table>();
// Set the table border color as LightGray
table->set_Border(MakeObject<Aspose::Pdf::BorderInfo>(
Aspose::Pdf::BorderSide::All, .5f,
Aspose::Pdf::Color::get_LightGray()));
// Set the border for table cells
table->set_DefaultCellBorder (MakeObject<Aspose::Pdf::BorderInfo>(
Aspose::Pdf::BorderSide::All, .5f,
Aspose::Pdf::Color::get_LightGray()));
// Create a loop to add 10 rows
for (int row_count = 1; row_count < 10; row_count++)
{
// Add row to table
auto row = table->get_Rows()->Add();
// Add table cells
row->get_Cells()->Add(String::Format(u"Column ({0}, 1)", row_count));
row->get_Cells()->Add(String::Format(u"Column ({0}, 2)", row_count));
row->get_Cells()->Add(String::Format(u"Column ({0}, 3)", row_count));
}
// Add table object to first page of input document
document->get_Pages()->idx_get(1)->get_Paragraphs()->Add(table);
// Save updated document containing table object
document->Save(_dataDir + u"document_with_table_out.pdf");