Reputation: 77
Getting issue when I am binding my report for create PDF using itextsharp, when my report have more than 80 or 100 row its start from second page it skip first page but less than that its works from first page. Here my code of adding report with issue screen-short
Code :
table = new PdfPTable(2);
table.TotalWidth = Size;
table.LockedWidth = true;
table.DefaultCell.Border = Rectangle.NO_BORDER;
table.SetWidths(new float[] { 265f, 265f });
insideTable1 = new PdfPTable(1);
insideTable1.TotalWidth = 260f;
insideTable1.LockedWidth = true;
insideTable1.DefaultCell.Border = Rectangle.NO_BORDER;
insideTable1.SetWidths(new float[] { 260f });
insideTable11 = new PdfPTable(widthArry);
insideTable11.TotalWidth = 260f;
insideTable11.LockedWidth = true;
insideTable11.SetWidths(widthArry);
for (int a = 0; a < colindexid.Count; a = a + 1)
{
#region addcolumnHeadeName
if (colindexid[a].ToString() == Convert.ToString(0))
{
phrase = new Phrase();
phrase.Add(new Chunk(H1, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
cell.FixedHeight = 15f;
insideTable11.AddCell(cell);
}
else if (colindexid[a].ToString() == Convert.ToString(1))
{
phrase = new Phrase();
phrase.Add(new Chunk(H2, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
cell.FixedHeight = 15f;
insideTable11.AddCell(cell);
}
else if (colindexid[a].ToString() == Convert.ToString(2))
{
phrase = new Phrase();
phrase.Add(new Chunk(H3, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
cell.FixedHeight = 15f;
insideTable11.AddCell(cell);
}
else if (colindexid[a].ToString() == Convert.ToString(3))
{
phrase = new Phrase();
phrase.Add(new Chunk(H4, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
cell.FixedHeight = 15f;
insideTable11.AddCell(cell);
}
#endregion addcolumnHeadeName
}
for (int i = 1; i <= 51; i++)
{
cnt++;
string Name = "";
#region addrow
if (colindexid.Contains(Convert.ToInt32(0)))
{
phrase = new Phrase();
phrase.Add(new Chunk(cnt.ToString(), f));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable11.AddCell(cell);
}
else
{
}
if (colindexid.Contains(Convert.ToInt32(1)))
{
phrase = new Phrase();
phrase.Add(new Chunk("E1", f));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable11.AddCell(cell);
}
else
{
}
if (colindexid.Contains(Convert.ToInt32(2)))
{
phrase = new Phrase();
//string SName = "";
//if (!string.IsNullOrEmpty(Name.ToLower()))
//{
// SName = textInfo.ToTitleCase(Name.ToLower());
//}
phrase.Add(new Chunk("Ravi Shah", f));
cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable11.AddCell(cell);
}
else
{
}
if (colindexid.Contains(Convert.ToInt32(3)))
{
//string SC = "";
//if (!string.IsNullOrEmpty(itm.ServiceCategory.ToLower()))
//{
// SC = textInfo.ToTitleCase(itm.ServiceCategory.ToLower());
//}
//string ST = "";
//if (!string.IsNullOrEmpty(itm.ServiceType.ToLower()))
//{
// ST = textInfo.ToTitleCase(itm.ServiceType.ToLower());
//}
phrase = new Phrase();
phrase.Add(new Chunk("Teacher" + "\n", f));
phrase.Add(new Chunk("" + "\n", FontFactory.GetFont("Arial Unicode MS,Arial", 5, iTextSharp.text.Color.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable11.AddCell(cell);
}
else
{
}
#endregion addrow
}
insideTable1.AddCell(insideTable11);
table.AddCell(insideTable1);
insideTable2 = new PdfPTable(1);
insideTable2.TotalWidth = 260f;
insideTable2.LockedWidth = true;
insideTable2.DefaultCell.Border = Rectangle.NO_BORDER;
insideTable2.SetWidths(new float[] { 260f });
insideTable22 = new PdfPTable(widthArry);
insideTable22.TotalWidth = 260f;
insideTable22.LockedWidth = true;
insideTable22.SetWidths(widthArry);
for (int a = 0; a < colindexid.Count; a = a + 1)
{
#region addcolumnHeadeName
if (colindexid[a].ToString() == Convert.ToString(0))
{
phrase = new Phrase();
phrase.Add(new Chunk(H1, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
cell.FixedHeight = 15f;
insideTable22.AddCell(cell);
}
else if (colindexid[a].ToString() == Convert.ToString(1))
{
phrase = new Phrase();
phrase.Add(new Chunk(H2, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
cell.FixedHeight = 15f;
insideTable22.AddCell(cell);
}
else if (colindexid[a].ToString() == Convert.ToString(2))
{
phrase = new Phrase();
phrase.Add(new Chunk(H3, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
cell.FixedHeight = 15f;
insideTable22.AddCell(cell);
}
else if (colindexid[a].ToString() == Convert.ToString(3))
{
phrase = new Phrase();
phrase.Add(new Chunk(H4, FontFactory.GetFont("Arial Unicode MS,Arial", 6, iTextSharp.text.Font.BOLD, iTextSharp.text.Color.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
cell.FixedHeight = 15f;
insideTable22.AddCell(cell);
}
#endregion addcolumnHeadeName
}
for (int i = 1; i <= 50; i++)
{
cnt++;
string Name = "";
#region addrow
if (colindexid.Contains(Convert.ToInt32(0)))
{
phrase = new Phrase();
phrase.Add(new Chunk(cnt.ToString(), f));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable22.AddCell(cell);
}
else
{
}
if (colindexid.Contains(Convert.ToInt32(1)))
{
phrase = new Phrase();
phrase.Add(new Chunk("M1", f));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable22.AddCell(cell);
}
else
{
}
if (colindexid.Contains(Convert.ToInt32(2)))
{
phrase = new Phrase();
//string SName = "";
//if (!string.IsNullOrEmpty(Name.ToLower()))
//{
// SName = textInfo.ToTitleCase(Name.ToLower());
//}
phrase.Add(new Chunk("Raj Patel", f));
cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable22.AddCell(cell);
}
else
{
}
if (colindexid.Contains(Convert.ToInt32(3)))
{
//string SC = "";
//if (!string.IsNullOrEmpty(itm.ServiceCategory.ToLower()))
//{
// SC = textInfo.ToTitleCase(itm.ServiceCategory.ToLower());
//}
//string ST = "";
//if (!string.IsNullOrEmpty(itm.ServiceType.ToLower()))
//{
// ST = textInfo.ToTitleCase(itm.ServiceType.ToLower());
//}
phrase = new Phrase();
phrase.Add(new Chunk("Sir" + "\n", f));
phrase.Add(new Chunk("" + "\n", FontFactory.GetFont("Arial Unicode MS,Arial", 5, iTextSharp.text.Color.BLACK)));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable22.AddCell(cell);
}
else
{
}
#endregion addrow
}
if (result11.Count == result22.Count + 1)
{
#region addrow
if (colindexid.Contains(Convert.ToInt32(0)))
{
phrase = new Phrase();
phrase.Add(new Chunk("", f));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable22.AddCell(cell);
}
else
{
}
if (colindexid.Contains(Convert.ToInt32(1)))
{
phrase = new Phrase();
phrase.Add(new Chunk("", f));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable22.AddCell(cell);
}
else
{
}
if (colindexid.Contains(Convert.ToInt32(2)))
{
phrase = new Phrase();
phrase.Add(new Chunk("", f));
cell = PhraseCell(phrase, PdfPCell.ALIGN_CENTER);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable22.AddCell(cell);
}
else
{
}
if (colindexid.Contains(Convert.ToInt32(3)))
{
phrase = new Phrase();
phrase.Add(new Chunk("", f));
cell = PhraseCell(phrase, PdfPCell.ALIGN_LEFT);
cell.BorderColor = new iTextSharp.text.Color(229, 229, 229);
insideTable22.AddCell(cell);
}
else
{
}
#endregion addrow
}
insideTable2.AddCell(insideTable22);
table.AddCell(insideTable2);
document.Add(table);
Thank you..
Upvotes: 1
Views: 133
Reputation: 77606
Add this line:
table.SplitLate = false;
The default for SplitLate
is true
which means that iTextSharp will try to add full rows to a page. If a row doesn't fit, it will skip to the next page. This explains the behavior you noticed.
Upvotes: 1