Expected Behavior
PdfReader.Open() should successfully open and parse the PDF file, returning a PdfDocument with the correct page count and content, the same way other PDF libraries (e.g. Python pypdf) can open this file without error.
Actual Behavior
PdfReader.Open() throws a NotImplementedException while reading the indirect objects of the file, regardless of whether PdfDocumentOpenMode.Import or PdfDocumentOpenMode.ReadOnly is used:
NotImplementedException: File streams are not yet implemented.
at PdfSharp.Pdf.IO.Parser.GetStreamLength(PdfDictionary dict, SuppressExceptions suppressObjectOrderExceptions)
at PdfSharp.Pdf.IO.Parser.ReadDictionaryStream(PdfDictionary dict, SuppressExceptions suppressObjectOrderExceptions)
at PdfSharp.Pdf.IO.Parser.ReadObjectInternal(PdfObject pdfObject, PdfObjectID objectID, Boolean includeReferences, Boolean fromObjectStream, SuppressExceptions suppressObjectOrderExceptions)
at PdfSharp.Pdf.IO.Parser.ReadIndirectObject(PdfReference pdfReference, SuppressExceptions suppressObjectOrderExceptions, Boolean withoutDecrypting)
at PdfSharp.Pdf.IO.Parser.ReadAllIndirectObjects()
at PdfSharp.Pdf.IO.PdfReader.OpenFromStream(Stream stream, String password, PdfDocumentOpenMode openMode, PdfPasswordProvider passwordProvider, PdfReaderOptions options)
at PdfSharp.Pdf.IO.PdfReader.OpenFromFile(String path, String password, PdfDocumentOpenMode openMode, PdfPasswordProvider passwordProvider)
at PdfSharp.Pdf.IO.PdfReader.Open(String path, String password, PdfDocumentOpenMode openMode, PdfPasswordProvider passwordProvider, PdfReaderOptions options)
at PdfSharp.Pdf.IO.PdfReader.Open(String path, PdfDocumentOpenMode openMode, PdfReaderOptions options)
Steps to Reproduce the Behavior
- Create a new .NET 8 console project and reference the latest PDFsharp NuGet package (v6.2.4).
- Obtain the attached PDF file (
duck.pdf), which was generated/exported by ChatGPT (OpenAI). The file also contains an embedded C2PA content-provenance manifest, which may use a stream/file-specification structure PDFsharp does not yet support.
- Run the following code:
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
var path = @"duck.pdf"; // a pdf file generated by ChatGPT
using var document = PdfReader.Open(path, PdfDocumentOpenMode.Import);
Console.WriteLine($"Page count: {document.PageCount}");
Expected Behavior
PdfReader.Open()should successfully open and parse the PDF file, returning aPdfDocumentwith the correct page count and content, the same way other PDF libraries (e.g. Pythonpypdf) can open this file without error.Actual Behavior
PdfReader.Open()throws aNotImplementedExceptionwhile reading the indirect objects of the file, regardless of whetherPdfDocumentOpenMode.ImportorPdfDocumentOpenMode.ReadOnlyis used:Steps to Reproduce the Behavior
duck.pdf), which was generated/exported by ChatGPT (OpenAI). The file also contains an embedded C2PA content-provenance manifest, which may use a stream/file-specification structure PDFsharp does not yet support.