Hi @don bradman ,
I added the data table without reproducing your problem, I added AddTable1
and GenerateTable1
and used GenerateTable1
to generate the second table in the preview.
Write a separate method for the second table:
GenerateTable1(document, creditNotesDataGrid, totalCreditNotes, "Less Credit Note/Debit Note", BaseColor.WHITE, BaseColor.WHITE);
private iTextSharp.text.Document GenerateTable1(iTextSharp.text.Document document, DataGrid gridView, decimal total, string headerText, BaseColor primaryHeaderBackgroundColor, BaseColor secondaryHeaderBackgroundColor)
{
if (gridView.SelectedItems.Count > 0)
{
var columnsCount = gridView.Columns.Count;
// Generate bills table
return document
.AddTable(columnsCount, table =>
{
table.AddPhrase(headerText, _tableHeaderFont, (cell, phrase) =>
{
cell.BackgroundColor = primaryHeaderBackgroundColor;
cell.Colspan = columnsCount;
cell.HorizontalAlignment = (int)Alignment.Center;
});
})
.AddTable1(gridView, _tableHeaderFont, secondaryHeaderBackgroundColor, _helveticaFontSamllStandard)
.AddTable(columnsCount, table =>
{
table
.AddEmptyCell(columnsCount - 1)
.AddStrongUnderlinedPhrase(total.ToDefaultStringFormat(), _tableHeaderFont);
});
}
return document;
}
public static iTextSharp.text.Document AddTable1(this iTextSharp.text.Document document, DataGrid gridView, iTextSharp.text.Font headerFont, BaseColor headerBackgroundColor, iTextSharp.text.Font bodyFont)
{
var table = new iTextSharp.text.pdf.PdfPTable(gridView.Columns.Count)
{
WidthPercentage = 75
};
table.DefaultCell.Padding = 3;
table.HorizontalAlignment = Element.ALIGN_CENTER;
foreach (DataGridColumn column in gridView.Columns)
{
var cell = new iTextSharp.text.pdf.PdfPCell(new iTextSharp.text.Phrase(column.Header.ToString(), headerFont))
{
BackgroundColor = headerBackgroundColor
};
table.AddCell(cell);
}
foreach (Bills bill in gridView.SelectedItems)
{
if (bill != null)
{
table.AddCell(new iTextSharp.text.Phrase(bill.CndnNo.ToString()));
table.AddCell(new iTextSharp.text.Phrase(bill.Date.ToString()));
table.AddCell(new iTextSharp.text.Phrase(bill.Value.ToString()));
}
}
document.Add(table);
return document;
}
Then add it to The GenerateTable:
// Generate body's paragraph
document.AddParagraph(bodyStartParagraph, _timesRomanNormal, Alignment.Left);
// Generate bills table
GenerateTable(document, billsDataGrid, totalBills, customerName, new BaseColor(255, 255, 30), new BaseColor(137, 220, 165));
// Generate credits table
GenerateTable1(document, creditNotesDataGrid, totalCreditNotes, "Less Credit Note/Debit Note", BaseColor.WHITE, BaseColor.WHITE);
Best Regards,
Jiale
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.