Have written the following coding which reads data from a MySQL database and
inserts it into a two column table:
Document doc = new Document();
PdfWriter.GetInstance(doc, new System.IO.FileStream("Test.pdf",
System.IO.FileMode.Create));
doc.Open();
PdfPTable table = new PdfPTable(2);
//actual width of table in points
table.TotalWidth = 216f;
//fix the absolute width of the table
table.LockedWidth = true;
//relative col widths in proportions - 1/3 and 2/3
float[] widths = new float[] { 1f, 2f };
table.SetWidths(widths);
table.HorizontalAlignment = 0;
//leave a gap before and after the table
table.SpacingBefore = 20f;
table.SpacingAfter = 30f;
PdfPCell cell = new PdfPCell(new Phrase("Products 2"));
cell.Colspan = 2;
cell.Border = 0;
cell.HorizontalAlignment = 1;
table.AddCell(cell);
String MyConString =
"SERVER=xxxxx;DATABASE=xxx;UID=xxx;PASSWORD=xxxx;";
// Create the Connectionstring
// PersistSecurityInfo = false means that the password is not displayed
in the
// connectionstring of the MySqlCommand.
//
MySqlConnectionStringBuilder connBuilder = new
MySqlConnectionStringBuilder();
connBuilder.Database ="lifenet";
connBuilder.Password ="keizer0321";
connBuilder.PersistSecurityInfo = false;
connBuilder.Server = "MySQLB15.webcontrolcenter.com";
connBuilder.UseCompression = true;
connBuilder.UserID = "bogorman";
// Create the connection
MySqlConnection conn = new
MySqlConnection(connBuilder.ConnectionString);
// Create the select command
MySqlCommand comm = new MySqlCommand(
"SELECT tblschools.fldSchool_ID, fldContact " +
"FROM tblschools " +
"RIGHT JOIN tblselectedschools ON tblschools.fldSCHOOL_ID =
tblselectedschools.fldSCHOOL_ID " +
"WHERE tblselectedschools.fldUserID = @userID " +
"AND tblselectedschools.fldSelected = @selected " +
"ORDER BY fldName", conn);
comm.Parameters.AddWithValue("userID", 2);
comm.Parameters.AddWithValue("selected", 1);
try {
// Open and execute the command
conn.Open();
using (MySqlDataReader reader = comm.ExecuteReader()) {
while (reader.Read()) {
table.AddCell(reader[0].ToString());
table.AddCell(reader[1].ToString());
}
}
doc.Add(table);
doc.Close();
} finally {
conn.Dispose();
comm.Dispose();
}
I am a complete newcomer to itext. How can I create a three column table and
insert "name and address" data into it, e.g:
Name 1 Name 2
Name3
Address11 Address21
Address31
Address12 Address22
Address32
Address13 Address23
Address33
Address14 Address24
Address34
Address15 Address25
Address35
Name4
.......
I realise that the SELECT statement will have to be modified to produce the
names and address lines but how can a three column table be created and the
data inserted as above?
Also, How can I ensure that as new pages are generated the top and bottom
page margins will be the same?
Would be most grateful for anyone's help. Have searched the net but cannot
find any suitable coding.
--
View this message in context:
http://www.nabble.com/Creating-3-column-table-to-generate-mailing-labels-tp23025916p23025916.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php