We are doing it since last 3 years to create pdf. but it take too much time ( approx 2 minutes) for 100 pages. some time we have to use 200 to 250 pages.
Steps are
1. Genrate image by using
Get ASP.NET C# 2.0 Website Thumbnail Screenshot[
^]
2. Read all all images and create PDF using
PdfWriter.GetInstance
and
iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance('ImagePathOnDisk');
it is very slow because
Step 1. A. Get Bitmap Image (100 time loop for 100 images)
B. Write it on Server Disk (100 images)
Step 2. A. Read From Server local (100 times loop for 100 images)
B. Create PDF (1 File)
C. Write on Server Disk (i file)
I want to improve this.
Idea is that i want to all images in server memory (say array of memoryStream) use them to create PDF and finally release memory of memoryStream array.
I Implemented
1.
MemoryStream[] arrBmp;
2. in loop while create image i am saving it in server memory
MemoryStream ms = new MemoryStream();
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
arrBmp[k] = ms;
3. at the time of creating PDF using loop
iTextSharp.text.Image pic = iTextSharp.text.Image.GetInstance(arrBmp[k]);
at this point there is an error "Index was outside the bounds of the array."
even i have 4 element in arrBmp[] but it throws error at k = 0 also.
NOTE:- step 2 and 3 are in different methods.
Q.1 why this error?
Q.2 Is it write way?
Q. what else i can do to increase performance?