You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't Open File (PdfSharp.Pdf.IO.ObjectNotAvailableException) #347
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)
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.
@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?
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)
Activity
StLange commentedon Mar 23, 2026
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.
wessleym commentedon Mar 25, 2026
@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?
ThomasHoevel commentedon Mar 30, 2026
You can use our anonymous upload-only FTP server to upload files directly to our on-premise server.
wessleym commentedon Mar 30, 2026
@ThomasHoevel, I see. Thank you!
dojo87 commentedon Jul 15, 2026
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)