How to Reduce Memory Consumption of PDFptable with Many Cells

ITextSharp Out of memory exception merging multiple pdf

Since this is a large amount of stuff I'd recommend writing directly to a FileStream instead of a MemoryStream. This might be an actual case where an Out of Memory Exception might literally mean "Out of Memory".

Also, as Bruno pointed out, the "smart" part of PdfSmartCopy unfortunately comes at the cost of memory, too. Switching to PdfCopy should reduce memory pressure although your final PDF might be larger.

Java iText PdfPTable larger than 6 columns

Suppose that this works (it does work, I know):

PdfPTable table = new PdfPTable(6);
table.addCell("1");
table.addCell("2");
table.addCell("3");
table.addCell("4");
table.addCell("5");
table.addCell("6");
document.add(table);

In this case, a table with a single row and 6 columns will be added.

If you change this snippet like this, no table will be added:

PdfPTable table = new PdfPTable(7);
table.addCell("1");
table.addCell("2");
table.addCell("3");
table.addCell("4");
table.addCell("5");
table.addCell("6");
document.add(table);

This table won't be added, because there is only a single row in it, and incomplete rows aren't rendered.

You have two options, either you add:

table.completeRow();

Or you add:

table.addCell("7");

right before adding the table to the document.

There is no reason why you could add a table with 6 columns but not a table with 7 columns. Width isn't an issue: if you don't define an absolute width for the columns, then iText will calculate the exact width of each column automatically.

I don't know if I have a document with a table that has 7 columns, but I do have an example of a table that has 8: see the SimpleTable example and simple_table.pdf.



Related Topics



Leave a reply



Submit