tags:

views:

95

answers:

2

Hello, I have a ASP.net 3.5 web application developed in VB.net I am using iTextsharp component to generate PDF document from the ASP.net page.

I am retreving the PDF documents stored in the db and merging them into one PDF. using the memorystream.

But when I try to merge around 1000 pdfs with each containing 2 pages, I am getting Outofmemory exception.

Any suggestions and do you think this is correct approach??

Please help

+1  A: 

I believe the correct approach is to rethink how you're accomplishing your goal.

Why are you having a web page compile 1000 PDFs into one PDF?

Can this not be setup as a job to create the "latest version" of this huge PDF, that is run once daily, and the page you have simply serves the latest version?

And yes this would run slowly even on 64 bit with 4 gigs of RAM, because this is not the job of a web request, it's the job of some type of scheduled service.

Update: In response to your comment, you could perhaps create a temporary loading page that says your file is being generated, and push the work into a background thread. When the thread completes, the loading page starts the download for the full document. Unless you can do what I suggest in my comment, I doubt you can speed things up very much more. Only thing you can do is make the wait more user friendly.

Perhaps even use a bit of AJAX and give them a status bar with "Merging page 106 of 1000". They will see progress and be less frustrated.

A beefier machine would be the only way to help, and 64 bit is required to avoid out of memory.

Aequitarum Custos
The reason why I have it in web application is that, users have option to select PDFs to be printed from the gridview(more than 5000 records). and on button click all the PDFs are merged into one. This is the business requirement. I would appreciate if you can let me know if there is any better way.
acadia
Ouch, those kind of business requirements can cause a load of trouble. If you are in control of the code generating those PDFs to begin with, and have access to the raw data, I would advise generating a completely new PDF based on raw data rather than existing PDFs. I am going to bet you don't have that luxury though so I am at a loss as to what to tell you :/
Aequitarum Custos
+1  A: 

Despite the fact that it will be really slow (Research Async ASP.NET Pages), why don't you just merge the files to the filesystem instead of to a MemoryStream?

Then when you are done you can use Response.TransmitFile(string filename)

bendewey