While I haven't tried this specifically, this was what I meant. If the following still leaks memory, then it's worth a look.
If I'm wrong here, please correct me, I'd like to know that.
Code:
foreach (myFile in Directory.GetFiles(myPath))
{
using (PdfDocument document = new PdfDocument())
{
using (PdfDocument tmpImpDoc = PdfReader.Open(myFile, PdfDocumentOpenMode.Import))
{
foreach (PdfPage importPage in TmpImpDoc.Pages)
{
document.AddPage(importPage);
}
}
document.Save(@"C:\new\" + Path.GetFileName(myFile));
document = null; // explicitly Tell CLR " I'm not using this anymore "
tmpImpDoc = null; // ...
}
}