Home All Groups Group Topic Archive Search About

System.OutOfMemoryException while Creating PDF files

Author
23 Oct 2007 10:08 AM
Aryan
Hi,

I am using C# with framework 2.0 and creating PDF files on-fly, along
with this I am using Windows 2003 Server.

I am using Byte[] to take the data input and then save into pdf format
on harddrive location.

Now after creating few successful pdf files, I am getting
"System.OutOfMemoryException".

Is this problem coming because of large data is been sent to Byte[] to
create PDF file or something else could be the cause.

If so, then how to resolve this issue??

Thanks in Advance,

Manoj

Author
23 Oct 2007 10:58 AM
Kevin Spencer
Don't read the entire file into a byte array. Instead, process it in
manageable chunks, reading a smaller chunk of the file at a time.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

Show quote
"Aryan" <manoj241***@gmail.com> wrote in message
news:1193134132.818741.239850@i38g2000prf.googlegroups.com...
> Hi,
>
> I am using C# with framework 2.0 and creating PDF files on-fly, along
> with this I am using Windows 2003 Server.
>
> I am using Byte[] to take the data input and then save into pdf format
> on harddrive location.
>
> Now after creating few successful pdf files, I am getting
> "System.OutOfMemoryException".
>
> Is this problem coming because of large data is been sent to Byte[] to
> create PDF file or something else could be the cause.
>
> If so, then how to resolve this issue??
>
> Thanks in Advance,
>
> Manoj
>
Author
23 Oct 2007 1:01 PM
Aryan
Keven, Thanks for prompt reply.

Here is the sample code snippet.

I am using SQLReport Server 2005 to get the data.

Byte[] results;
ReportExecutionService rsExec;
results = rsExec.Render(format, deviceInfo,
                        out extension, out encode,
                        out mimeType, out warnings, out streamIDs);

SavePDF(results, filename); // calling SavePDF method to save the
result array output in PDF form.

private bool SavePDF(Byte[] results, string fileName)
        {
            try
            {

                using (FileStream stream = File.OpenWrite(fileName))
                {
                    stream.Write(results, 0, results.Length);
                    stream.Close();
                    stream.Dispose();
                }

                return true;
            }
            catch(Exception ex)
            {
                throw;
            }
        }


Now,
1> If I get large stream from ReportExecutionService then how to split
it in chunks and create a pdf file(say pdf has something around 3000 /
5000 pages in it)

Thanks in Advance.
Manoj

AddThis Social Bookmark Button