Replaced text doesnt wrap properly to the next line

The requirement is to replace a text in pdf document with paragraph. Search text is identified using TextFragmentAbsorber and it finds the word in the document.
TextFragments from TextFragmentAbsorber are iterated to replace the text. New text is assigned to the TextFragment and the document is saved to new location.
The output pdf shows the replaced text at the correct place, but in the first line it shows less content and in the second line the content is getting overflown. WholeWordsHyphenation option is used by the TextFragmentAbsorber.TextReplaceOptions.ReplaceAdjustmentAction. How to resolve the wrapping of the replaced text.

Aspose library version : 22.9

I have attached the code snippet, input pdf screebnshot and output pdf screenshot.

Code Snippet

    public static void ReplaceTextOnAllPages()
    {
        
        // The path to the documents directory.
        string oldFile = @"E:\Sample Applications\PDFEditor\Input PDF\pft-report2.pdf";
        string newFile = @"E:\Sample Applications\PDFEditor\Output PDF\pft-report2.pdf";

        // Open document
        Document pdfDocument = new Document(oldFile);

        // Create TextAbsorber object to find all instances of the input search phrase
        TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("[Interpretation]");
        textFragmentAbsorber.TextReplaceOptions.ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation;
        
        // Accept the absorber for all the pages
        pdfDocument.Pages.Accept(textFragmentAbsorber);

        // Get the extracted text fragments
        TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;

        // Loop through the fragments
        foreach (TextFragment textFragment in textFragmentCollection)
        {
            textFragment.Text = "This is a inserted paragraph, I want to insert this paragraph in the start of document.This is a inserted paragraph, I want to insert this paragraph in the start of document.This is a inserted paragraph, I want to insert this paragraph in the start of document.";
        }
      
        pdfDocument.Save(newFile);

        Process.Start(newFile);
    }

Input PDF :
image.png (45.3 KB)

Output PDF:
image.png (53.2 KB)

1 Like

@josephrony277

Would you please share the source sample PDF as well for our reference? We will test the scenario in our environment and address it accordingly.

pft-report2.pdf (197.8 KB)

Text to be replaced : [Interpretation]

Replace text : This is a inserted paragraph, I want to insert this paragraph in the start of document.This is a inserted paragraph, I want to insert this paragraph in the start of document.This is a inserted paragraph, I want to insert this paragraph in the start of document.

@asad.ali Updated the previous comment with actual pdf. Please provide an update asap. So that we could take a decision on purchase

@josephrony277

It looks like the API is not replacing the text correctly in the PDF. We need to look into it and resolve the issue. For the purpose, we have logged a ticket as PDFNET-52771 in our issue tracking system to further analyze this case. We will look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

Any updates on the ticket

@josephrony277

The ticket has recently been logged in our issue tracking system we are afraid that it is not yet investigated. We will analyze and resolve it on a first come first serve basis. You will be informed via this forum thread as soon as some progress is made towards ticket resolution. Please be patient and spare us some time.

We are sorry for the inconvenience.