Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want two coloums in pdf table ..Like student info table stores fields like name ,address ..and it's values ..I want to print field name like 1st column name[field name] and second column value of [name] field then in second row address[field name] and address[value] from table name student info....



This is my code ...

C#
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();
Posted
Updated 12-Aug-15 20:49pm
v4
Comments
So, where is the issue?
aarif moh shaikh 13-Aug-15 2:34am    
What you are getting (error or output) ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900