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

Free Support Forum - aspose.com

Aspose.PDF cannot support Regexp Group when search and replace string

Description

Aspose.PDF cannot support Regexp Group (like $0,$1…) when search and replace string with regexp.

Env

  • Windows 10 .NET 4.7
  • Aspose.PDF for .NET 22.12

Code

    var doc = new Aspose.Pdf.Document(@"C:\Users\XCL\Desktop\test\source.pdf");
    var textFragmentAbsorber = new TextFragmentAbsorber("(world)", new TextSearchOptions(true));
    doc.Pages.Accept(textFragmentAbsorber);
    TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
    foreach (TextFragment textFragment in textFragmentCollection)
    {
        textFragment.Text = "=$0=";// $0 is not woking.
    }
    doc.Save(@"C:\Users\XCL\Desktop\test\target.pdf");

Before

image.png (34.2 KB)

After

image.png (33.7 KB)

Test Files

test.zip (153.5 KB)

@xucongli1989

It seems that you want to use substitutions in replacement patterns. We have logged a ticket as PDFNET-53375 in our issue tracking system to support substitutions within replacement patterns.

Could you please share your expected output PDF file here for our reference? We will then provide you more information on it.

Yes, thanks a lot.

Expect Result

expect.pdf (213.8 KB)

image.png (17.9 KB)

@xucongli1989

Thanks for sharing the PDF. We will inform you once there is an update available on your issue.