FileStream fs = new FileStream("abc.pdf", FileMode.Create, FileAccess.Write, FileShare.None); Document doc = new Document(iTextSharp.text.PageSize.A4, 36, 36, 63, 10); //left ,right,top,bottom PdfWriter writer = PdfWriter.GetInstance(doc, fs); doc.Open(); string strDSN = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\diy.mdb"; string strSQL = "SELECT * FROM project where ID='" + dbProjID + "'"; OleDbConnection myConn = new OleDbConnection(strDSN); OleDbDataAdapter myCmd = new OleDbDataAdapter(strSQL, myConn); myConn.Open(); DataSet dtSet = new DataSet(); myCmd.Fill(dtSet, "Developer"); DataTable dTable = dtSet.Tables[0]; // Now start putting content into the PDF file created //***************************ADDING TABLE IN PDF FILE ********************************* //add first cell PdfPTable table = new PdfPTable(2); table.WidthPercentage = 98; table.SpacingBefore = 20f; //table.PaddingTop= PdfPCell cell = new PdfPCell(new Phrase("Customer Information")); cell.BackgroundColor = new BaseColor(0, 0, 250); cell.Colspan = 2; cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right (for heading allignment) table.AddCell(cell); foreach (DataRow dtRow in dTable.Rows) { table.AddCell (dtRow.Table.ToString()); // table.AddCell(dtRow[i].ToString()); } doc.Add(table); myConn.Close(); doc.Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)