Click here to Skip to main content
12,752,054 members (36,985 online)

iTextSharp RAM (memory) overflow

Max Kapustin asked:

Open original thread
Hi. I'm generating a PDF document based on template. The document has multiple pages. The document can have about 5000 pages. When creating the 500-th page I get an overflow RAM (memory). Any idea? Thanks in advance.

public static void CreateBankBlank2012Year(string pdfTemplatePath, string directoryOutPdf, string nameOutPdf, AnnualReportsFilterParameters filterParametrs, string serverPath)
    // Get details salary
    IEnumerable<SalayDetailsForPdf> dataSalaryDetails = (IEnumerable<SalayDetailsForPdf>) GetSalaryData(filterParametrs);

    String fontPath = Path.Combine(serverPath + "\\Fonts", "STSONG.ttf");
    Font font = FontFactory.GetFont(fontPath, BaseFont.IDENTITY_H, 8);

    using (Document document = new Document())
        using (PdfSmartCopy copy = new PdfSmartCopy(
            document, new FileStream(directoryOutPdf + nameOutPdf, FileMode.Create))

            foreach (var data in dataSalaryDetails)                    
                PdfReader reader = new PdfReader(pdfTemplatePath + @"\EmptyTemplateBankBlank_2012.pdf");
                using (var ms = new MemoryStream())
                    using (PdfStamper stamper = new PdfStamper(reader, ms))
                        AcroFields form = stamper.AcroFields;
                                                                                                                            form.SetField("t1_address1", data.Address1);

                        form.SetField("t1_name", data.NameHieroglyphic);

                        // Other field ...

                        stamper.FormFlattening = true;
                    reader = new PdfReader(ms.ToArray());

                    copy.AddPage(copy.GetImportedPage(reader, 1));
Tags: C#, itextsharp


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100