System.IO.EndOfStreamException when ReplaceText

PdfContentEditor pdfContentEditor = new PdfContentEditor();
pdfContentEditor.BindPdf(enumerateFile.FullName);
// Replace text on all pages
pdfContentEditor.ReplaceText(“xxx”, “1111”); // throw System.IO.EndOfStreamException
// Save output PDF
pdfContentEditor.Save(Path.Combine(textBox4.Text, enumerateFile.Name));

System.IO.EndOfStreamException
HResult=0x80070026
Message=无法在流的结尾之外进行读取。
Source=mscorlib
StackTrace:
在 System.IO.BinaryReader.ReadByte()
在 ​ . ()
在 ..( , & , )
在 .. ( , & )
在 . ( , & )
在 .. ( , & )
在 . ( , & )
在 . ( )
在 .(Int32 , Int32 )
在 . (Int32 , Int32 )
在 . ()
在 .( )
在 .(String )
在 .​ ()
在 ​ …ctor( )
在 . ()
在 Aspose.Pdf.Page…ctor( )
在 Aspose.Pdf.PageCollection.(Int32 )
在 Aspose.Pdf.PageCollection.(Int32 )
在 Aspose.Pdf.Text.TextFragmentAbsorber.Visit(Document pdf)
在 Aspose.Pdf.Facades.PdfContentEditor.ReplaceText(String srcString, Int32 thePage, String destString, TextState textState)
在 Aspose.Pdf.Facades.PdfContentEditor.ReplaceText(String srcString, String destString)

I use 18.4 from nuget 22.zip (521.0 KB) I upload the file else

@lsl

Thank you for contacting support.

We have worked with the data shared by you but we have not been able to reproduce it in our environment. Please check if this error appears with all files or if it is a file specific error. Also try commenting out the line of code containing ReplaceText method and observe whether the problem persists or not. In case the problem persists, please share your environment details with us.

Moreover, please note that Aspose.Pdf.Facades is an old model and soon it is going to be obsolete, which is why we always recommend to use DOM (Document Object Model) approach that is more advanced. So, please follow the DOM approach explained in the documentation article Replace Text in a PDF Document, instead of using ReplaceText method of Facades model.

It about 5% happened above error in my pdfs, also I try your DOM (Document Object Model) and got another error
pdfDocument.Pages.Accept(textFragmentAbsorber); // throw System.NullReferenceException

q1: it is not a random error, for a special pdf, got error every time
q2:Even if there was no exception,the replace result was wrong// I have 4 chinese char ,replace 2 of them,result is some english char…
may be you can have a try to change your OS language to chinese

@lsl

About 5% occurrences of the problem, you face this issue with every file but the issue does not appear 95 times out of 100 times. Please clarify if you are mentioning such a situation by saying 5%. Moreover, we have not been able to reproduce EndOfStreamException or NullReferenceException even after changing the OS Language to Chinese (Traditional , Hong Kong SAR). Kindly create a sample application reproducing these exceptions and share a ZIP file with us, so that we may investigate further to help you out.

Please ensure using Aspose.PDF for .NET 18.5 in your environment, and mention your environment details while sharing the source and generated PDF file that has incorrect replacement of 2 characters instead of 4 characters.

I get same error when use 18.5 and I upload demo code and pdf
asposepdf.zip (3.0 MB)

my operation video Rec 0010.zip (1.4 MB)

@lsl

Thank you for sharing requested data.

We have been able to reproduce the issues reported by you and following tickets have been logged in our issue management system for further investigation and resolution.

PDFNET-44692: For occurrence of NullReferenceException
PDFNET-44693: For incorrect text replaced in generated PDF file

The ticket IDs have been linked with this thread so that you will receive notification as soon as the tickets are resolved.

We are sorry for the inconvenience.

any update?..

@lsl

The issues reported by you are pending for investigations owing to previously logged and critical issues. Your tickets will be scheduled on their due turn that can take several months. We appreciate your patience and comprehension in this regard.

However, we also offer Paid Support, where issues are used to be investigated with higher priority. Our customers, who have paid support subscription, report their issue there which are meant to be investigated urgently. In case your reported issue is a blocker, you may please consider subscribing for Paid Support. For further information, please visit Paid Support FAQs.