Hi,
We are using aspose.pdf version 22.7.0.
When we are trying to replace element tag with string.empty, it is not replacing both the element but when we try to replace any one element it is working fine.
Below is the code snippet we are using to replace the element.
{
using var doc = new Document(@"sample.pdf");
List<TextFragment> textFragments = new List<TextFragment>();
List<string> replaceTexts = new List<string>();
//this is not getting replaced in file
replaceTexts.Add("$_physSig");
replaceTexts.Add("$_sigDate");
//this is getting replaced but it adds additional word "$_"
//replaceTexts.Add("physSig");
//replaceTexts.Add("sigDate");
replaceTexts.ForEach(replaceText =>
{
TextFragmentAbsorber absorber = new TextFragmentAbsorber(replaceText)
{
TextReplaceOptions = new TextReplaceOptions(TextReplaceOptions.ReplaceAdjustment.None)
};
doc.Pages.Accept(absorber);
textFragments.AddRange(absorber.TextFragments.ToList());
});
foreach (TextFragment textFragment in textFragments)
{
var item = replaceTexts.FirstOrDefault(x => string.Equals(x, textFragment.Text, StringComparison.InvariantCultureIgnoreCase));
if (item == null)
continue;
textFragment.Text = string.Empty;
}
doc.Save(@"replaced.pdf");
}
Attached is the document for which we are facing an issue.
sample1.pdf (263.7 KB)
Note : We have tested with aspose.pdf version 22.7.0 as well as 23.7.0. And in both version we are facing the same issue.