I tried to load the attached file and iterate over pdf.AcroForm.Fields. At first I encountered an error:
No appropriate constructor found for type: PdfAcroFieldCollection at PdfSharp.Pdf.PdfDictionary.DictionaryElements.CreateArray(Type type, PdfArray oldArray)
So I added a constructor it was looking for:
public PdfAcroFieldCollection(PdfDocument document): base(document){ }
Error "solved", but next one appeared:
'Object already in table.' at PdfSharp.Pdf.Advanced.PdfCrossReferenceTable.Add(PdfObject value)
I tried to change Add to ObjectTable[value.ObjectID]=value.ReferenceNotNull;, then there was no exception, but pdf.AcroForm.Fields were empty.
Steps to reproduce:
dotnet new console -n PdfSharpBug
cd PdfSharpBug
dotnet add package PdfSharp
code .
using System.Net;
using PdfSharp.Pdf.Advanced;
using PdfSharp.Pdf.IO;
using (var ms = new MemoryStream(new WebClient().DownloadData("https://github.com/user-attachments/files/17873789/21a352e0-dd03-4855-a1e5-82fb3690493c.pdf")))
using (var pdf = PdfReader.Open(ms, PdfDocumentOpenMode.Import))
{
foreach (PdfReference fieldReference in pdf.AcroForm.Fields)
{
Console.WriteLine(fieldReference.ToString());
}
}
dotnet run
Observed result:
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
at PdfSharp.Pdf.PdfDictionary.DictionaryElements.CreateArray(Type type, PdfArray oldArray)
at PdfSharp.Pdf.PdfDictionary.DictionaryElements.GetValue(String key, VCF options)
at PdfSharp.Pdf.AcroForms.PdfAcroForm.get_Fields()
at Program.$(String[] args) in C:\git\PdfSharpBug\Program.cs:line 8
I tried to load the attached file and iterate over pdf.AcroForm.Fields. At first I encountered an error:
No appropriate constructor found for type: PdfAcroFieldCollection at PdfSharp.Pdf.PdfDictionary.DictionaryElements.CreateArray(Type type, PdfArray oldArray)
So I added a constructor it was looking for: public PdfAcroFieldCollection(PdfDocument document): base(document){ }
Error "solved", but next one appeared: 'Object already in table.' at PdfSharp.Pdf.Advanced.PdfCrossReferenceTable.Add(PdfObject value)
I tried to change Add to ObjectTable[value.ObjectID]=value.ReferenceNotNull;, then there was no exception, but pdf.AcroForm.Fields were empty.
21a352e0-dd03-4855-a1e5-82fb3690493c.pdf
Steps to reproduce: dotnet new console -n PdfSharpBug cd PdfSharpBug dotnet add package PdfSharp code .
dotnet run
Observed result: Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at PdfSharp.Pdf.PdfDictionary.DictionaryElements.CreateArray(Type type, PdfArray oldArray) at PdfSharp.Pdf.PdfDictionary.DictionaryElements.GetValue(String key, VCF options) at PdfSharp.Pdf.AcroForms.PdfAcroForm.get_Fields() at Program.$(String[] args) in C:\git\PdfSharpBug\Program.cs:line 8