My task is stuck and it has taken up all the available RAM by the code below after being called several times and running the requested tasks without any problems.
Document document = new Document();
using (FileStream newFileStream = new FileStream(tempFile, FileMode.Create, FileAccess.ReadWrite))
{
PdfCopy writer = new PdfCopy(document, newFileStream);
document.Open();
foreach (var page in pages)
{
PdfReader reader = new PdfReader(Path.Combine(pdfInputPath, page.PdfFileName));
reader.ConsolidateNamedDestinations();
PdfImportedPage importedPage = writer.GetImportedPage(reader, page.Page);
writer.AddPage(importedPage);
reader.Close();
}
writer.Close();
document.Close();
}
what can cause an infinite loop in this piece of code?
and this piece of code also caused an infinite loop
var reader = new PdfReader(pdfFile);
using (var outputPdfStream = new FileStream(finalPDFPath, FileMode.Create, FileAccess.Write, FileShare.None))
{
var stamper = new PdfStamper(reader, outputPdfStream);
int i = 1;
foreach (var page in pages)
{
var pdfContentByte = stamper.GetOverContent(i++);
string value = GetValue();
if (!string.IsNullOrEmpty(value))
{
var img = GetPage(Information, page, layout, pdfContentByte, value, X_DPI, Y_DPI);
//var img = ImgRender(Information, page);
pdfContentByte.AddImage(img);
pdfContentByte.ClosePath();
}
}
logger.Info("Number of pages after generation :" + reader.NumberOfPages);
stamper.Close();
reader.Close();
}