empira / PDFsharp-1.5

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

New Document Has PDF Version 0 #127

Closed timk259 closed 1 year ago

timk259 commented 4 years ago

When closing a PDF file that was created by PDFSharp, Adobe Reader prompts for unsaved changes, depending on how the file was created. It was observed that for files that cause this problem the PDF version number in the file is zero.

Expected Behavior

Opening and closing a PDF in another applications (such as Adobe Reader) without making changes should not result in a prompt about unsaved changes.

Actual Behavior

The unsaved-changes prompt occurs depending on which constructor was used in the code that creates the document. When using the code below, the prompt occurs for the third file but not the first two.

Steps to Reproduce the Behavior

Example code:

PdfDocument document1 = new PdfDocument(); document1.AddPage(); document1.Save("test1.pdf");

PdfDocument document2 = new PdfDocument("test2.pdf"); document2.AddPage(); document2.Close();

using (var outputStream = new FileStream("test3.pdf", FileMode.Create, FileAccess.ReadWrite)) { PdfDocument document3 = new PdfDocument(outputStream); document3.AddPage(); document3.Close(); }

TH-Soft commented 4 years ago

Do all three files from your sample code have PDF version 0? Which version of Adobe Reader do you use?

timk259 commented 4 years ago

Only the third file has version 0; the first two have version 1.4.

I have Adobe Acrobat Reader DC version 2020.009.20067.

ThomasHoevel commented 1 year ago

The bug was fixed and PDFsharp no longer creates files with version 0.0 using the code above.