I'm creating a PDF using ITextSharp which is composed of a single PdfTable. Unfortunately for a particular data set, I'm getting an Out of memory Exception due to the large number PdfPCells that are created (I've profiled the memory usage - I've got nearly 1/2 a million cells !)
Is there any way to reduce the memory usage in such a case? I've tried flushing at various points (after each row) and full compression
The PdfWriter is based on a FileStream
Code looks a pretty much like this:
Document document = Document();
FileStream stream = new FileStream(fileName,FileMode.Create);
pdfWriter = PdfWriter.GetInstance(document, stream);
document.Open();
PdfPTable table = new PdfPTable(nbColumnToDisplay);
foreach (GridViewRow row in gridView.Rows)
{
j = 0;
for (int i = 0; i < gridView.HeaderRow.Cells.Count; i++)
{
PdfPCell cell = new PdfPCell( new Phrase( text) );
table.AddCell(cell);
}
}
document.Add(table);
document.Close();
See Question&Answers more detail:os