We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Formatting is messed up when text from PDF is replaced with Aspose.Pdf

image.png (20.0 KB)

var pdfDocument = new Aspose.Pdf.Document(@"./Test.pdf");
var pdfContentEditor = new Aspose.Pdf.Facades.PdfContentEditor();

        pdfContentEditor.TextReplaceOptions.ReplaceScope = TextReplaceOptions.Scope.REPLACE_ALL;

        pdfContentEditor.ReplaceText("the", "TEST!!");


i have added above code to replace text. text is replaced correctly but formatting is messed up. can you help me with this?


Thanks for contacting support.

Would you please share the sample input PDF document with us so that we can test the scenario in our environment and address it accordingly.

sure. Please check below PDF
Test.pdf (83.0 KB)

Formatting is messed up in this PDF.
Test_FormatingMessedup.pdf (140.6 KB)

@asad.ali have you found any solution for above problem?


Thanks for sharing sample PDF documents.

We have tested the scenario in our environment using Aspose.PDF DOM approach (it is recommended approach) and Aspose.PDF for .NET 18.10. We were able to notice the similar issue that you mentioned. Therefore, we have logged an issue as PDFNET-45620 in our issue tracking system for the sake of correction. We will further look into details of the issue and keep you posted with the status of its rectification. Please spare us little time.

For you reference, following is the code snippet used for testing:

var doc = new Aspose.Pdf.Document(dataDir + "Testforrepl.pdf");
TextFragmentAbsorber absorber = new TextFragmentAbsorber("the");
foreach(TextFragment textfragment in absorber.TextFragments)
 textfragment.Text = "Test";
doc.Save(dataDir + @"FindAndReplace_out.pdf"); 

We are sorry for the inconvenience.

ok.Thanks for your reply.

@asad.ali can you give me rough idea how long it will take to fix above issue?


Thanks for your inquiry.

The issue has just been logged in our issue tracking system and it is pending for analysis due to other pending issues in the queue which were logged previously than yours. Please note that issues under free/normal support model are resolved on first come first serve basis and have low priority unlike the paid/priority support where issues are dealt with high priority. As soon as we have some definite updates regarding issue resolution, we will let you know. Please spare us little time.

We are sorry for the inconvenience.