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

Free Support Forum - aspose.com

Replace text in PDF document using C# | horizontal alignment (center) not working

Hi there, thanks for your time looking into my request.

I am replacing text using Aspose.PDF but the horizontal alignment (center ) is not working. Am I doing anything wrong here or is there some issue with API. Please advise. Please see my code below:

public static void DoFindReplaceText(string find, Aspose.Pdf.Document pdfDocument, string replace)
        TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(find);
        TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;

        foreach (TextFragment textFragment in textFragmentCollection)
            textFragment.HorizontalAlignment = HorizontalAlignment.Center;
            textFragment.Text = replace;

Best Regards

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

What is the issue with below code, not sure why Center Alignment is not working, Is it API issue. Please advise?

       TextFragmentAbsorber absorber = new TextFragmentAbsorber("FINDTEXT");          

        absorber.TextFragments[1].Text = "REPLACETEXT";
        absorber.TextFragments[1].HorizontalAlignment = HorizontalAlignment.Center;


Can you please share your sample PDF document with us as well? We will test the scenario in our environment and address it accordingly.