Hello!

I generate a PDF document based on templates. The document consists of several pages (maybe more than 5000). When I create the 500th page, I get a memory overflow. Any ideas? Thanks for the tips!

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)) ) { document.Open(); 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)) { stamper.AcroFields.AddSubstitutionFont(font.BaseFont); 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)); } } } } } 
  • @Maximus, please use Cyrillic. - Nicolas Chabanovsky

1 answer 1

Preempt the created 499 pages onto a disk, after the tenth iteration, merge the documents into one 5,000 page.

  • one
    @Mike PDF, the user who asked the question, of course, will receive a notification by email, but, most likely, this question is no longer worth two and a half years later. - etki
  • four
    @Etki better late than never. - Mike PDF