Introduction:
This artcle,we will discuss about how to export a dataset into PDF using iTEXTSHARP dll.
Main:
Step 1:Please download iTextSharp dll.
Step 2: Please add reference to yours Project.(using iTextSharp)
Sometimes we need to export a dataset or datagrid into PDF for Reporting purpose.We can easily export dataset into PDF using iTEXTSHARP dll.
Code:
iTextSharp.Text.Document = new iTextSharp.Text.Document(PageSize.A4.Rotate(),80,50,30,65); MemoryStream ms=new MemoryStream(); PdfWriter writer=PdfWriter.GetInstance(doc,ms); doc.open(); DataSet Pdfds=new Dataset(); Pdfds=(DataSet) Cache["Report"]; for (int table=0;table<Pdfds.Tables.Count;table++) { iTextSharp.text.Table PdfTable = new iTextSharp.text.Table(Pdfds.Tables[0].Columns.Count); for(int icol=0;icol<Pdfds.Tables[0].Columns.Count;icol++) { PdfTable.AddCell(Pdfds.Tables[0].Columns[icol].ColumnName.ToString(),new Point(0,icol)); } for(int row=0;Pdfds.Tables[0].Rows.Count;row++) { for(int column=0;column<Pdfds.Tables[0].Columns.Count;column++) { PdfTable.AddCell(Pdfds.Tables[0].Rows[row][column].ToString()); } } doc.Add(pdfTable); } doc.Close(); |
Conclusion:
Hope,this helps,
Happy Coding.
1 Comments.