I am using C# to take an Excel file as input and convert it into PDF. There are no images, just data in the form of tables.
Some of the Excel files are very big in size (more than 200,000 rows). Whenever one of these files is converted, the program gives OutOfMemoryException. I tried creating multiple PDFs containing less number of rows using more than 1 PdfDocumentRenderer but that's also not working.
I am using the following code for the conversions:
Code:
PdfDocumentRenderer _pdfRendererDoc1 = new PdfDocumentRenderer(true);
Document _doc1 = new Document();
Style _styleDoc1 = _object.SetStyle(_doc1);
PdfDocument pdfDoc1 = new PdfDocument();
Section _sectionDoc1 = _object.SetSection(_doc1);
Table _tableDoc1 = _object.AddTables(_sectionDoc1);
Row _rowDoc1;
Cell _cellDoc1;
_object.AddColumns(_tableDoc1, colWidth);
for (int row = 1; row <= end.Row; row++)
{
_rowDoc1 = _object.AddRows(_tableDoc1);
int col = 1, pdfCol = 0;
while (pdfCol < numColumns)
{
_cellDoc1 = _rowDoc1.Cells[pdfCol];
pdfCol ++;
col++;
}
}
_pdfRendererDoc1.Document = _doc1;
// Render output file //
_pdfRendererDoc1.RenderDocument();
// Save output file //
_pdfRendererDoc1.Save(outputFileLocation + outputFileName);
Can someone suggest a way out? Can I close a Renderer manually so that the memory is cleared?
Thanks in advance
