Free Support Forum - aspose.com

After replacing the text, the length of the hyperlink line is not updating - Aspose PDF .net

After_Replace_Text.png (121.8 KB)
Before_Replace_Text.png (83.4 KB)

2 screenshots are attached, one is before replace and other after replace.

There are 2 issues highlighted in screenshots,

  1. Length of the hyperlink line (i.e blue line) after replacing text is same as before, it is not updating. (In the screen shot i have replaced “ICC” with “ICC replaced”)
  2. If there are multiple hyperlinks in a line, all the hyperlinks formats are gone even if the one hyperlink text is replaced.

Below is the code that i’m using to replace Text,

PdfContentEditor pdfContentEditor = new PdfContentEditor();
pdfContentEditor.BindPdf(Pdfdocument);

        pdfContentEditor.TextReplaceOptions.ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation;
        pdfContentEditor.TextEditOptions.ToAttemptGetUnderlineFromSource = true;

        // Replace text on all pages
        pdfContentEditor.ReplaceText(sentence, pageNo, newText);

Please do the needful and it is quite urgent.
Please let me know if you need any other details.
Thank you

@lakshmips,

Kindly send us your source PDF document. We will investigate your scenario in our environment, and share our findings with you.

Hi Imran,

PDF file is attached

Steve Smith.pdf (587.6 KB)

@lakshmips,

We managed to replicate the said issues in our environment. It has been logged under the ticket ID PDFNET-44488 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

Hi Imran,

I have one more issue, text is overlapping with next word or link when the replace text is performed. I have attached the screenshot taken after replacing text.

I’m using the same pdf as above and code is also same.

TextOverlap_After_Replace.png (77.4 KB)

@lakshmips,

We have tested your scenario with the latest version 18.4 of Aspose.PDF for .NET API, and could not replicate the problem of overlapping text in our environment. However, we can find the problem of displaced underline of the text. It has been logged under the ticket ID PDFNET-44505 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates. This is the output PDF: Output18.4.pdf (587.6 KB)

Can you please share the code snippet that was used to replicate?
Thanks

@lakshmips,

In reference to the ticket ID PDFNET-44505, this is the code snippet:
C#

string dataDir = @"C:\Pdf\test765\";
Document pdfDocument = new Document(dataDir + "Steve Smith.pdf");
PdfContentEditor pdfContentEditor = new PdfContentEditor();
pdfContentEditor.BindPdf(pdfDocument);

pdfContentEditor.TextReplaceOptions.ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation;
pdfContentEditor.TextEditOptions.ToAttemptGetUnderlineFromSource = true;
// Replace text on all pages
pdfContentEditor.ReplaceText("ICC Player Rankings", 3, "BCCI Player Rankings");
pdfContentEditor.Save(dataDir + "Output18.4.pdf");

Hi Imran,

In reference to the ticket ID PDFNET-44505,
If i replace the text with long string it is going of the page, please refer the attachment. (For example : “ICC” is replaced with “International Cricket Council”)
Same code and same PDF file has been used.

Any updates on the ticket PDFNET-44488, it is quite urgent. Please do the needful

@lakshmips,

We have recorded this information under the same ticket ID PDFNET-44505 and let you know once a significant progress has been made in this regard. In reference to the linked ticket ID PDFNET-44488, it is pending for the analysis and not resolved yet. It is difficult to share an estimate before the completion of the analysis phase.

Hi Imran,

I have one more issue, after replacing the text is overlapping with next words, please refer the attachment for the output. I have replaced “Dhoni” with “DhoniMSD”.
Replace_Text_Fragment.png (127.6 KB)

Source pdf is attached.
MS Dhoni.pdf (518.6 KB)

I’m using the following code.

// Create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(@"(?i)" + Regex.Escape(sentence), new TextSearchOptions(true));

            // Accept the absorber for all the pages
            Pdfdocument.Pages[pageNo].Accept(textFragmentAbsorber);

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

            // Loop through the fragments
            foreach (TextFragment textFragment in textFragmentCollection)
            {
                foreach (TextSegment textSegment in textFragment.Segments)
                {
                    if (textSegment.Text.ToLower() == originalText.ToLower())
                    {
                        textSegment.Text = newText;
                    }
                }
            }

            if (textFragmentCollection.Count > 0)
            {
                Pdfdocument.ProcessParagraphs();
                Pdfdocument.Save(FileName);
            }

@lakshmips,

We managed to replicate the problem of text overlapping in our environment. It has been logged under the ticket ID PDFNET-44550 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

Hi Imran,

Any updates on below tickets? It is been more than a month since the issues were raised.
PDFNET-44550
PDFNET-44505
PDFNET-44488

@lakshmips,

The linked ticket IDs PDFNET-44550, PDFNET-44505 and PDFNET-44488 are pending for the analysis and not resolved yet. We will investigate as per the development schedules, and notify you regarding each fix.