empira / PDFsharp-1.5

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

Fails to open PDF document with version 0 #142

Closed tyler-boyd closed 1 year ago

tyler-boyd commented 3 years ago

Hi, first, thanks for all the work on PDFSharp! It's an awesome library and has been very helpful.

Reporting an Issue Here

I am consuming a document generated by someone else using PDFSharp 1.32. I am parsing it with the latest 1.50 version of PDFSharp. I can see that the version header is %PDF-0.0.% in the PDF, and all viewers I tested were able to open it, but PDFSharp was not due to it interpreting version 0.0 the same as an error case.

Expected Behavior

Actual Behavior

Steps to Reproduce the Behavior

I can include an IssueSubmissionTemplate if necessary, but I figure this is a trivial issue. test.pdf

Solutioning

Ideally, PDFSharp shouldn't generate version 0.0 documents (related issue: https://github.com/empira/PDFsharp/issues/127). But since other PDF readers can handle it, I think the real fix would be to change the GetPdfFileVersion function to differentiate between version 0.0 and the error case. It may be as simple as changing the error case return value to -1.

tyler-boyd commented 3 years ago

If anyone is struggling with this and needs a workaround, I've published https://www.nuget.org/packages/PdfSharpTr/0.0.3 which is the latest stable release but with the PdfSharp.dll replaced with the version from building my PR.

ThomasHoevel commented 1 year ago

Version 0.0 is still not supported. We fixed a bug that caused PDFsharp to write files with version 0.0. Please try preview 1 or later of PDFsharp 6.0.0.