Click here to Skip to main content
15,843,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I'm generating pdf using itextsharp. for pages upto 100, it is downloading. But for pages more than 100, It is giving me outOfMemory Exception 'Insufficient memory to continue the execution of the program.' Please provide me solution for the problem:

I'm inserting my data in PdfPTable. Here is my code in short:

pdfPage page = new pdfPage();

string attachment = "attachment; filename=" + PDF_Name + ".pdf";
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/pdf";

iTextSharp.text.Document doc = new iTextSharp.text.Document();
PdfWriter writer = PdfWriter.GetInstance(doc, Response.OutputStream);
for (int i = 0; i < dt.Rows.Count; i++)

PdfPTable tablePage1 = new PdfPTable(2);
           if (i != (dt.Rows.Count - 1))
           writer.PageEvent = page;


pdfPage is my class for applying header and footer to every page of pdf.

please provide me solution.

Thanx in advance,
Updated 4-Feb-14 20:03pm

1 solution

You need to use a memory streamer so that all of the info does not get stored into memory as a pdf file as it grows.

Here are an example you can go look at:
Creating PDF documents with iTextSharp[+]
Share this answer
Dipali_Wagh 5-Feb-14 1:49am    
but your code is for mvc
Dipali_Wagh 5-Feb-14 2:03am    
I tried it.
but not working
thatraja 5-Feb-14 2:51am    
Always give complete details like error no, message, etc.,
CBadger 5-Feb-14 5:50am    
What is wrong? The memory stream should be used... What did you try and what did not work. Could you update your question so I have better idea what you are asking :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900