我正在使用 iTextSharp 创建 PDF,并且正在创建多个在我的代码中内联运行的表。当我用我收藏的值填充表格时,我不知道表格会有多长时间。而且我不希望一张桌子碰到或穿过下一张。这是我到目前为止所拥有的,但是如果表格进入下一页,它会与我放置在下一行代码中的表格重叠,并带有分页符 -NewPage()-
// Page 1 Searches
doc.NewPage();
cb.BeginText();
centerText(cb, "HeaderText for Searches", 300, 760, _fontbold, 18);
cb.EndText();
PdfPTable tableSearches = new PdfPTable(4);
PdfPCell cellSearches = new PdfPCell();
cellSearches.BackgroundColor = BaseColor.WHITE;
cellSearches.Phrase = new Phrase("Company");
tableSearches.AddCell(cellLKQ);
cellSearches.Phrase = new Phrase("Contact");
tableSearches.AddCell(cellLKQ);
cellSearches.Phrase = new Phrase("Phone Number");
tableSearches.AddCell(cellLKQ);
cellSearches.Phrase = new Phrase("Amount");
tableSearches.AddCell(cellLKQ);
//loop through the records in facilities collection and add row
foreach (var m in facilities)
{
cellSearches.BackgroundColor = BaseColor.LIGHT_GRAY;
cellSearches.Phrase = new Phrase(m.Facility);
tableSearches.AddCell(cellSearches);
cellSearches.Phrase = new Phrase(m.FacilityContact);
tableSearches.AddCell(cellSearches);
cellSearches.Phrase = new Phrase(m.Phone);
tableSearches.AddCell(cellSearches);
cellSearches.Phrase = new Phrase(m.SalvageQuote.ToString());
tableSearches.AddCell(cellSearches);
}
doc.Add(tableSearches);
//Page 2? AM Searches
doc.NewPage();
cb.BeginText();
centerText(cb, "HeaderText AM Searches", 300, 760, _fontbold, 18);
cb.EndText();
PdfPTable tableAM = new PdfPTable(4);
PdfPCell cellAM = new PdfPCell();
cellAM.BackgroundColor = BaseColor.WHITE;
cellAM.Phrase = new Phrase("Company");
tableAM.AddCell(cellAM);
cellAM.Phrase = new Phrase("Contact");
tableAM.AddCell(cellAM);
cellAM.Phrase = new Phrase("Phone Number");
tableAM.AddCell(cellAM);
cellAM.Phrase = new Phrase("Amount");
tableAM.AddCell(cellAM);
//loop through the records and add row
foreach (var m in amfacilities)
{
cellAM.BackgroundColor = BaseColor.CYAN;
cellAM.Phrase = new Phrase(m.Facility);
tableAM.AddCell(cellAM);
cellAM.Phrase = new Phrase(m.FacilityContact);
tableAM.AddCell(cellAM);
cellAM.Phrase = new Phrase(m.Phone);
tableAM.AddCell(cellAM);
cellLKQ.Phrase = new Phrase(m.SalvageQuote.ToString());
tableAM.AddCell(cellAM);
}
doc.Add(tableAM);
//Page 3? Another Table
doc.NewPage();
// Code for next table