The following code throws a null reference exception after two pages:
var pageNr = 1;
var pdfDocument = new Document(GetFilePath(fileName));
foreach (Page page in pdfDocument.Pages)
{
using (var pageDocument = new Document())
{
pageDocument.Pages.Add(page);
pageDocument.Save(GetFilePath(fileName + “-page-” + pageNr));
}
pageNr++;
}
After two iterations the page object is null. Works for any PDF I tested.
If I remove the save action, the iteration works fine.
I already found an alternative in PdfFileEditor.Extract, but this code whould work anyway.