ststeiger / PdfSharpCore

Port of the PdfSharp library to .NET Core - largely removed GDI+ (only missing GetFontData - which can be replaced with freetype2)
Other
1.07k stars 239 forks source link

Unexpected EOF with PdfReader.Open(PdfDocumentOpenMode.Import) when opening a PDF with a textbox and slash #311

Open nh104622 opened 1 year ago

nh104622 commented 1 year ago

Basically title. When I try to take in an existing PDF byte array then open up a memory stream to read the PDF then Call PDFReader.Open(...), I get an error message with the below external stack trace. The issue goes away when I take out the slashes in a date text field of the editable PDF. The example PDF has a date in the format of: 01/01/1970 in a textbox. Is there any way around this issue?

using var stream = new MemoryStream(pdfData);
using var doc = PdfReader.Open(stream, PdfDocumentOpenMode.Import);

Stack Trace: ICSharpCode.SharpZipLib.SharpZipBaseException: Unexpected EOF at ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream.Fill at ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream.Read at PdfSharpCore.Pdf.Filters.FlateDecode.Decode at PdfSharpCore.Pdf.Filters.Filtering.Decode at PdfSharpCore.Pdf.PdfDictionary+PdfStream.get_UnfilteredValue at PdfSharpCore.Pdf.IO.Parser.ReadXRefStream at PdfSharpCore.Pdf.IO.Parser.ReadXRefTableAndTrailer at PdfSharpCore.Pdf.IO.Parser.ReadTrailer at PdfSharpCore.Pdf.IO.PdfReader.Open

nh104622 commented 1 year ago

An update on this issue, I still have this problem with an inconvenient workaround. Basically this PDF I am trying to import has editable fields and generates the above exception when calling PdfReader.Open(...). The workaround is to manually edit one of the fields using Adobe then undo my change and save it. For some reason this seems to work when re-running my application with the above code.

Does anyone have any insights on what could be happening here? This happens with multiple documents.

toolgood commented 2 months ago

https://github.com/ststeiger/PdfSharpCore/issues/451 The same issue