In 3 col x 7 row table cannot add less than 21 records
I am using itextsharp to create a pdf containing a table with the above format and then read text from a mySQL database into its cells. Everything works ok unless:
a) there are less than 21 records in the recordset. I then get the error "the document has no pages"
b) if there are more than 21 records in the recordset and total number of records in the recordset is not a multiple of 21, the pdf is created but the last page is missing (i.e. the one which should contain less than 21 records).
The part of the coding which reads in the data is:
try {
// Open and execute the command
conn.Open();
using (MySqlDataReader reader = comm.ExecuteReader())
{
while (reader.Read())
{
string text = string.Format(
"{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}\r\n{5}\r\n{6}",
reader["fldContact"],
reader["Name"],
reader["ad1"],
reader["ad2"],
reader["ad3"],
reader["ad4"],
reader["ad5"]);
Phrase myPhrase = new Phrase(text, times);
table.AddCell(myPhrase);
}
}
doc.Add(table);
}
finally
{
// Close should always be called now
// If the PDF has no contents, an exception will not be caught,
// but at least the file will be closed (and unlocked)
try
{
doc.Close();
}
finally
{
// Also make sure the underlying stream is closed
// You could delete the file here if it's empty
docStream.Close();
}
conn.Dispose();
comm.Dispose();
}
fldContact, Name, ad1, ad2, ad3, ad4 and ad5 are fields in the recordset. I have run the debugger in VS2005 and checked that the data is correct. It is.
Would very much appreciate anyones help on this.