empira / PDFsharp-1.5

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

Crash on get document.AcroForm #114

Open oleg-finka opened 4 years ago

oleg-finka commented 4 years ago

Can't open document.AcroForm

Expected Behavior

it should be null or have some meaningful object value

Actual Behavior

Crashes with an error

Unhandled Exception: System.InvalidCastException: Unable to cast object of type 'PdfSharp.Pdf.PdfNull' to type 'PdfSharp.Pdf.AcroForms.PdfAcroForm'.
   at PdfSharp.Pdf.Advanced.PdfCatalog.get_AcroForm()
   at PdfSharp.Pdf.PdfDocument.get_AcroForm()
   at IssueSubmission.Program.Main() in C:\Users\ofinka\Downloads\PDFsharp-IssueSubmission\IssueSubmission\Program.cs:line 25

It happens not with every pdf, but this one is critical for me.

Steps to Reproduce the Behavior

Just run IssueSubmission main project PDFsharp-IssueSubmission.zip

oleg-finka commented 4 years ago

Debugged a bit. Found that on parsing "/AcroForm" dictionary it can't find related object in irefTable - don't know why. That's why document.AcroForm == null. PdfReader.cs:433 -> Parser.cs:187 -> Parser.cs:393 -> Parser.cs:486

WyrmUK commented 3 years ago

It might be because your Test.pdf contains Javascript. Whereas Adobe (and various other products/libraries) support that, I don't believe it is a standard PDF feature (like XFA isn't a standard PDF feature) so I wouldn't necessarily expect PDFSharp to support it. That said, there should be a graceful or more meaningful handling of it.