If a PdfDocument is loaded and never modified (or it is, depending on what you do), saving it will throw an InvalidOperationException when it shouldn't.
PdfDocument.DoSave immediately checks to see if there are pages within the document:
Code:
if (this.pages == null || this.pages.Count == 0)
throw new InvalidOperationException("Cannot save a PDF document with no pages.");
This looks valid, but if the Pages property is never accessed prior to this, pages will still be null.
Pages property:
Code:
public PdfPages Pages
{
get
{
if (this.pages == null)
this.pages = Catalog.Pages;
return this.pages;
}
}
Though I'm not certain how you wish to solve it, a quick fix would be to make the DoSave method check Pages instead of pages.