PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

PdfDocument.DoSave throws exception (when it shouldn't)
https://forum.pdfsharp.net/viewtopic.php?f=3&t=874
Page 1 of 1

Author:  rversaw [ Wed Sep 16, 2009 7:54 pm ]
Post subject:  PdfDocument.DoSave throws exception (when it shouldn't)

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.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/