Skip to content

Can't Open File (PdfSharp.Pdf.IO.ObjectNotAvailableException) #347

Open

Description

@wessleym

Thank you for PDFsharp!

I'm trying to read a file with PDFsharp 6.2.4. To me, the file does not seem corrupt since my PDF reader can open it. Upon calling PdfSharp.Pdf.IO.PdfReader.Open, I get the below exception. I'm including the file: CR1.pdf. Thank you for your help.

Exception:
Type: PdfSharp.Pdf.IO.ObjectNotAvailableException
Message:
Cannot retrieve stream length.
PDFsharp cannot read this PDF file. If you think your file is a valid PDF file please send it to us so that we can fix this bug in the PDF parser.
Stack Trace:
at PdfSharp.Pdf.IO.Lexer.<>c.b__17_0()
at PdfSharp.Internal.SuppressExceptions.HandleError(SuppressExceptions suppressExceptions, Action throwException)
at PdfSharp.Pdf.IO.Lexer.DetermineStreamLength(Int64 start, Int32 searchLength, 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, PdfDocumentOpenMode openMode, PdfReaderOptions options)

Activity

  1. added
    bug
    on Mar 23, 2026
  2. added theissue type on Mar 23, 2026
  3. StLange commented on Mar 23, 2026

    @StLange
    Member

    The error is caused by 12 unnecessary line feeds at the end of a stream before the token "endstream". While unusual, this is a bug in PDFsharp. It will be fixed in the next version.

    Thank you for reporting the bug.

  4. wessleym commented on Mar 25, 2026

    @wessleym
    Author

    @StLange, thank you! My project currently runs files through PdfSharp, and if an ObjectNotAvailableException occurs, it runs it through PdfSharpCore as a backup. But I would rather just use PdfSharp. I intend to return here if it happens again. Is there a private place where I can post these files, or do I just need to include them in the GitHub issue like I did here?

  5. added
    duplicate
    enhancement
    on Mar 26, 2026
  6. ThomasHoevel commented on Mar 30, 2026

    @ThomasHoevel
    Member

    You can use our anonymous upload-only FTP server to upload files directly to our on-premise server.

  7. wessleym commented on Mar 30, 2026

    @wessleym
    Author

    @ThomasHoevel, I see. Thank you!

  8. dojo87 commented on Jul 15, 2026

    @dojo87

    We have observed this issue reoccurring with IBM I generated invoices. It can't find the endstream, which is more than 20 characters away from the specified /Length (Parser.cs code specifies that)

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

    bugduplicateenhancement

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions