0

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

2
  • 2
    Time for 64-bit? What are you merging that's 1000 pages? Commented Mar 5, 2010 at 2:53
  • I tried in 32 bit with 2GB ram and it threw this exception. In 64 bit the server became very slow and I closed the page and reset the IIS Commented Mar 5, 2010 at 2:55

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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 :/
1

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.