Welcome Guest Search | Active Topics | Sign In | Register

Receiving OutofMemoryException when generating pdf for more than 60000 records Options
NetWeb
Posted: Friday, August 23, 2013 7:52:33 AM
Rank: Newbie
Groups: Member

Joined: 8/23/2013
Posts: 1
Hi All,

I need to create pdf file for the grid that contains more than 60,000 records. I write the code for creating PDF table for obtained list and then writes it to PDF. This works good for 12,000 records but it is giving OutofMemoyException for large number of records.

Following is the code for this.
public ActionResult PrintData()
{
IList<Customers> custSearch = new List<Customers>();
CustomerObjectList custList = new CustomerObjectList ();
string fileName = DateTime.Now.ToString("MM-dd-yyyy hh-mm-ss-ff") + ".pdf";

custSearch = custList.GetCustomer();

if (custSearch != null)
{
PdfDocument doc = new PdfDocument();
AcmPageLayout pageLayout = new AcmPageLayout(new AcmPadding(0.5f));

AcmRender render = new AcmRender(doc, pageLayout);
render.SetDefPageSize(new System.Drawing.SizeF(11f, 8.5f));

AcmStyleSheet styleSheet = new AcmStyleSheet();

AcmStyle textFont = new AcmStyle();
textFont.FontSize = 8f;

textFont.Name = "fontsize8";
styleSheet.Add(textFont);

AcmTable table = new AcmTable(1.5f, 1.8f, 1.8f, 1.8f, 1.8f, -1f);
table.CellPadding = 0.05f;
table.GridLineType = AcmGridLineType.All;
table.StyleSheet = styleSheet;
table.GridLineInfo = new AcmLineInfo(AcmLineStyle.Solid, System.Drawing.Color.Black, 0.01f);

AcmTableRow hrow = new AcmTableRow();
AcmTableCell cell = new AcmTableCell(new AcmText("Customer #"));
cell.StyleName = "fontsize8";
hrow.Cells.Add(cell);
cell = new AcmTableCell(new AcmText("Customer Name"));
cell.StyleName = "fontsize8";
hrow.Cells.Add(cell);
cell = new AcmTableCell(new AcmText("Parent Name"));
cell.StyleName = "fontsize8";
hrow.Cells.Add(cell);
cell = new AcmTableCell(new AcmText("Primary Sales Relationship"));
cell.StyleName = "fontsize8";
hrow.Cells.Add(cell);
cell = new AcmTableCell(new AcmText("Industry"));
cell.StyleName = "fontsize8";
hrow.Cells.Add(cell);
cell = new AcmTableCell(new AcmText("SIC Code"));
cell.StyleName = "fontsize8";
hrow.Cells.Add(cell);
table.Rows.Add(hrow);

for (int i = 0; i < custSearch.Count; i++)
{
AcmTableRow row = new AcmTableRow();
cell = new AcmTableCell(
new AcmText(custSearch[i].CustomerNumber));
cell.StyleName = "fontsize8";
row.Cells.Add(cell);

cell = new AcmTableCell(new AcmText(custSearch[i].CustomerName));
cell.StyleName = "fontsize8";
row.Cells.Add(cell);

cell = new AcmTableCell(new AcmText(custSearch[i].ParentName));
cell.StyleName = "fontsize8";
row.Cells.Add(cell);

cell = new AcmTableCell(new AcmText(custSearch[i].SalesRelationship));
cell.StyleName = "fontsize8";
row.Cells.Add(cell);

cell = new AcmTableCell(new AcmText(custSearch[i].SICCodeValue));
cell.StyleName = "fontsize8";
row.Cells.Add(cell);

cell = new AcmTableCell(new AcmText(custSearch[i].Industry));
cell.StyleName = "fontsize8";
row.Cells.Add(cell);

table.Rows.Add(row);
}

render.Render(table);

doc.Save("c:\\" + fileName);

return View("Index", custSearch);
}
else
{
return View("Index", null);
}
}

I would like to request help in resolving this issue.

Thank you.

Best Regards,
Romesh
eo_support
Posted: Friday, August 23, 2013 9:13:12 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

Your code looks fine. There isn't much you can do when you hit OutOfMemoryException. You can try to use the HTML to PDF feature to see whether it works for you.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.