|
//Create the pdfdocument
PdfDocument document = new PdfDocument();
//Add the page
PdfPage page = document.Pages.Add();
//Get product
IEnumerable collection = GetProducts();
// Create a PdfGrid.
PdfGrid pdfGrid = new PdfGrid();
//Assign data source.
pdfGrid.DataSource = collection;
//Draw PdfGrid.
pdfGrid.Draw(page, new PointF(30, 70));
//Sample for adding rows manually
PdfGrid table = new PdfGrid();
table.Columns.Add(3);
PdfGridRow row1 = table.Rows.Add();
row1.Cells[0].Value = "Column 1";
row1.Cells[1].Value = "Column 2";
row1.Cells[2].Value = "Column 3";
// Draw PdfGrid
table.Draw(page, new PointF(30, 150));
//Save and close the document.
MemoryStream stream = new MemoryStream();
document.Save(stream);
private List<Product> GetProducts()
{
List<Product> collection = new List<Product>();
Product product = new Product();
//Add Row values
product.Name = "Computer";
product.Description = "Computer";
product.Quantity = "12";
//Add Row values
collection.Add(product);
product = new Product();
product.Name = "Mobile";
product.Description = "Android Mobile";
product.Quantity = "34";
//Add Row values
collection.Add(product);
product = new Product();
product.Name = "Ipod";
product.Description = "Apple";
product.Quantity = "12";
collection.Add(product);
return collection;
}
|