empira / PDFsharp-1.5

A .NET library for processing PDF
MIT License
1.28k stars 588 forks source link

Must access PdfDocument.PageCount or PdfDocument.Pages before a save is possible #130

Closed EricMEvans closed 1 year ago

EricMEvans commented 4 years ago

Open a PDF with a mode other than Modify then attempt to save the PDF. You will be presented with an error stating, "Cannot save a PDF document with no pages." Add a line before the save to obtain the PageCount and then a save will succeed.

By default, the _pages object is instantiated on open only when the Modify mode is specified though this object is required for the save. Grabbing the PageCount or Pages will perform the instantiation but only supposed to when CanModify evaluates to true; CanModify is currently hard coded to true.

A PR has been submitted to correct the issue at hand and observes the rules already in place and planned for CanModify.

ThomasHoevel commented 1 year ago

Files opened without the Modify flag cannot be saved.