Skip to content

PdfReader.Open throws NotImplementedException: "File streams are not yet implemented" on PDF generated by ChatGPT #389

Description

@wooly905

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

  1. Create a new .NET 8 console project and reference the latest PDFsharp NuGet package (v6.2.4).
  2. 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.
  3. 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}");

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions