Reputation: 113
I am using iText 7 for creating a table inside the PDF file. I have successfully created the table but the table's bottom border is not being drawn.
Screenshot of the Result:
My Code:
private void Convert()
{
String dest = "D:/addingTable.pdf";
var table = new Table(1, true);
Border b = new SolidBorder(ColorConstants.RED, 5);
table.SetBorder(b);
using (var writer = new PdfWriter(dest))
{
using (var pdf = new PdfDocument(writer))
{
var doc = new Document(pdf);
var name = new Paragraph("Hello World!").SetFontColor(ColorConstants.BLUE).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetFontSize(13);
table.AddCell(new Cell().Add(name));
doc.Add(table);
}
}
Process.Start(dest);
}
Upvotes: 4
Views: 2133
Reputation: 95918
You explicitly create the Table
with largeTable
support set to true
:
var table = new Table(1, true);
This allows to add large tables to a PDF without the whole table structure having to reside in memory at the same time: You can add it piecewise and flush all aggregated data every once in a while.
[add first few rows]
doc.Add(table);
[add next few rows]
table.Flush();
[add next few rows]
table.Flush();
...
[add final rows]
table.Complete();
In your code you forgot the final
table.Complete();
(or you simply did not want to create the table with largeTable
support to start with).
Upvotes: 2