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开发者_C百科 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
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.
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)
精彩评论