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

Free Support Forum - aspose.com

How to replace existing table row text with hyperlink in PDF during creating index page

Hi,

I want to replace text with a hyperlink, inside an existing table’s row, to create index page in PDF

templateTable.Range.Replace(Constants.sectionTitle, sectionName);

This line will replace text with text, but not text with a hyperlink. Provide an alternative for the same,

Thanks

@keyurgohil,

You can search the target text phrase, and then update this text with a hyperlink. Please try the following code. If this does not help, then kindly send all details of your scenario, including source PDF and code. We will investigate your scenario and share our findings with you.
C#

// Open document
Document pdfDocument = new Document(dataDir + "input.pdf");
// Create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("SomeText");

// 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)
{
    // Update text and other properties
    textFragment.Text = "Click here to Sign";
    // Create Link annotation object
    LinkAnnotation link = new LinkAnnotation(textFragment.Page, textFragment.Rectangle);
    // Create border object for LinkAnnotation
    Border border = new Border(link);
    // Set the border width value as 0
    border.Width = 0;
    // Set the border for LinkAnnotation
    link.Border = border;
    // Specify the link type as remote URI
    link.Action = new GoToURIAction("www.aspose.com");
    // Add link annotation to annotations collection of first page of PDF file
    textFragment.Page.Annotations.Add(link);
}
pdfDocument.Save(dataDir + "Output.pdf", SaveFormat.Pdf);

@imran.rafique,

Thanks for quick replay, but this will add an external hyperlink, and my requirement is to add an internal hyperlink, To create clickable indexes to navigate in the PDF.

I have tried with LocalHyperlink but not working,

Thanks

Hi @imran.rafique,

What am I doing is?

  • want to add Internal Hyperlink to navigate from indexes to section in PDF file using LocalHyperLink.

Here is my code…

           // Open PDF
           Document indexPdfDocument = new Document();                
           indexPdfDocument = new Document(indexPdfFilePath);

            // Create TextAbsorber object to find all instances of the input search phrase
            TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("Section 1");

            // Accept the absorber for all the pages
            indexPdfDocument.Pages.Accept(textFragmentAbsorber);

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

            foreach (TextFragment text in textFragmentCollection)
            {
                //TextFragment text = textFragmentCollection[1];

                // Create Text Fragment instance
                //TextFragment text = new TextFragment("link page number test to page 1");
                // Create local hyperlink instance
                LocalHyperlink link = new LocalHyperlink() {
                    // Set target page for link instance
                    TargetPageNumber = 2                        
                };
                // Set TextFragment hyperlink
                text.Hyperlink = link;
                // Add text to paragraphs collection of Page
                text.Page.Paragraphs.Add(text);
            }
            
             // Save
            indexPdfDocument.Save(indexPdfFilePath);

While creating indexes, I am using a pre-defined template, So I want to replace that text “Section 1” with the created link,

Now what is the issue?

  • Unable to replace Hyperlink with Text in table’s row of PDF.

  • The above code will add that link and it’s clickable too, but not placed properly,

I have attached source PDF and resulting PDF of above code.

Thanks

Resulting.PDF (239.2 KB)

Source.pdf (303.2 KB)

@keyurgohil,

The output of source PDF and code does not match with the resulting PDF. Kindly review and share the complete details, so that we could replicate the same problem in our environment.

Please elaborate with the help of a snapshot.

SampleFile.zip (10.3 KB)

Hello,
We have a document which has table and content in the document.
In the table, we’ve normal text and that text we want to convert into a link (within the document).
Please find attached sample document which has a link which we want to add (replace existing text with hyperlink )

Sample code which I provide should work as it is you just need to provide file path and aspose license.

Any argent helps much appreciated.

Thanks.

@keyurgohil,

We managed to replicate the problem of not being able to add local hyperlink to the text of the table’s cell. It has been logged under the ticket ID PDFNET-44349 in our bug tracking system. We have linked your post to this ticket and will keep you informed regarding any available updates.

How can I track the progress of PDFNET-44349? I am the development manager on the original project that Keyur was working on. Keyur is no longer on the project, so I need to be able to track when the defect has been fixed.

Regards

Gregg

@gregglinnell,

Thank you for the details. The linked ticket ID PDFNET-44349 is pending for the analysis and not resolved yet. We will investigate this issue as per the development schedules. You can ask for the progress here and we will notify you once it is fixed.

The issues you have found earlier (filed as PDFNET-44349) have been fixed in Aspose.PDF for .NET 18.11.