How to Integrate Table with Database (DOM) & Populate Data in PDF using .NET

This technical tip shows how .NET developers can integrate table with database (DOM) and populate data from a database using Aspose.Pdf for .NET. Databases are specially built to store and manage data in a better manner. It's a very common practice for programmers to populate different kinds of objects with data from databases. If you want to populate Table object with data from any data source using Aspose.Pdf for .NET then it is possible too. And it's not only possible but it’s very easy too. Aspose.Pdf for .NET allows developers to import data from, Object Array, DataTable and DataView. This topic would provide information about fetching data from DataTable or DataView.
//your code here...[C#] /* Create a DataTable object (Employee) and add columns to it (Employee_ID, * Employee_Name, Gender). */ DataTable dt = new DataTable("Employee"); dt.Columns.Add("Employee_ID", typeof(Int32)); dt.Columns.Add("Employee_Name", typeof(string)); dt.Columns.Add("Gender", typeof(string)); //Add 2 rows into the DataTable object programmatically DataRow dr = dt.NewRow(); dr[0] = 1; dr[1] = "John Smith"; dr[2] = "Male"; dt.Rows.Add(dr); dr = dt.NewRow(); dr[0] = 2; dr[1] = "Mary Miller"; dr[2] = "Female"; dt.Rows.Add(dr); // Create Document instance Document doc = new Document(); doc.Pages.Add(); // Initializes a new instance of the Table Aspose.Pdf.Table table = new Aspose.Pdf.Table(); //Set column widths of the table table.ColumnWidths = "40 100 100 100"; // 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, 1, 3, 3); // Add table object to first page of input document doc.Pages[1].Paragraphs.Add(table); // Save updated document containing table object doc.Save("c:/pdftest/DataIntegrated.pdf"); [VB.NET] '************************************************************************** '* Create a DataTable object (Employee) and add columns to it (Employee_ID, '* Employee_Name, Gender). '************************************************************************** Dim dt As DataTable = New DataTable("Employee") dt.Columns.Add("Employee_ID", System.Type.GetType("System.Int32")) dt.Columns.Add("Employee_Name", System.Type.GetType("System.String")) dt.Columns.Add("Gender", System.Type.GetType("System.String")) 'Add 2 rows into the DataTable object programmatically Dim dr As DataRow = dt.NewRow() dr(0) = 1 dr(1) = "John Smith" dr(2) = "Male" dt.Rows.Add(dr) dr = dt.NewRow() dr(0) = 2 dr(1) = "Mary Miller" dr(2) = "Female" dt.Rows.Add(dr) ' Create Document instance Dim doc As Document = New Document() doc.Pages.Add() ' Initializes a new instance of the Table Dim table As Aspose.Pdf.Table = New Aspose.Pdf.Table() 'Set column widths of the table table.ColumnWidths = "40 100 100 100" ' Set the table border color as LightGray table.Border = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 0.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, 0.5F, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray)) table.ImportDataTable(dt, True, 0, 1, 3, 3) ' Add table object to first page of input document doc.Pages(1).Paragraphs.Add(table) ' Save updated document containing table object doc.Save("c:/pdftest/DataIntegrated.pdf")

Url: http://www.aspose.com/.net/pdf-component.aspx

Language: C# | User: Sheraz Khan | Created: Nov 19, 2014 | Tags: Add TOC in Existing PDF, Create Table of Contents add headings to manipulate existing PDF files, Load an Set the title for TOC, Aspose.Pdf .NET files .NE