PdfContentEditor.ReplaceText closes Stream?

There is no verbiage in the online docs about this method? The following code results in closing the Stream the PdfContentEditor is bound to and the last line throwing an exception the a closed stream cannot be written to. Not sure what to do?

PdfContentEditor editor = new PdfContentEditor();

this._doc.Position = 0;

editor.BindPdf(this._doc);

editor.ReplaceText(this.GetWatermarkText(watermarkName), String.Empty);

editor.Save(this._doc);


This message was posted using Page2Forum from ReplaceText Method - Aspose.Pdf.Kit for .NET

Hi Shannon,

You’re using the same input stream as output stream as well; please try to use a different memory stream to save the output file.

I hope this helps. If you have any further questions, please do let us know.
Regards,

I have tried using a separate input and output stream, using a temporary memory stream, binding with filepath, binding with filestream and saving with filepath, binding with filepath and saving with filestream etc, etc, etc. HOURS of attempts, and NOTHING works.

Can you please provide some code showing how to:

  1. Bind the PdfContentEditor to a existing Pdf
  2. Replace a text string using ReplaceText() method
  3. Save the altered Pdf to a new file

This has been a very frustrating endeavor, and there is almost ZERO documentation available, and no solution that I can find anywhere. Thank you in advance for your help.

Hi,

Sorry for replying you late.

Please take a look over the following code snippet which demonstrates the feature of ReplaceText feature of PdfContentEditor class. I have also attached the source PDF and the resultant PDF that I have generated after this operation has been performed.

[C#]

// create an object of PdfContentEditor
PdfContentEditor editor = new PdfContentEditor();
// bind the source PDF document
editor.BindPdf(@"d:/pdftest/Source_ReplaceText_Test.pdf");
// specify the source string that needs to be replaced with target string
editor.ReplaceText("dog", "Cat");
// save the updated PDF document
editor.Save(@"d:/pdftest/Resultant_After_ReplaceText.pdf");

In case it does not satisfy your requirements or you have any further query, please feel free to contact. We apologize for your inconvenience.

PS, Please note that this feature is in Beta version and might not deliver 100% accurate results.