I have a document with a table and I’d like to add a Local Hyper Link to one of the table cells in each row.
I get the table, get the cell, get the TextFragment, create a local hyperlink add it to the text fragment,
No errors but no hyperlink.
Is there a working example of this ?
None of the examples I’ve seen involve a table cell in an existing document resulting in a hyperlink to a page in the document.
Dave
@dwgrooms,
Kindly send us the complete details of your use case, including source PDF and code. We will investigate and share our findings with you. Please refer to this help topic: Create hyperlink to pages in same PDF
Program.zip (80.5 KB)
Here’s some code based on your samples.
Let me know what I’m missing
@dwgrooms,
The Hyperlink property of the TextFragment class is for the newly added text. You can use LinkAnnotation for an existing PDF. Please try the following code:
[C#]
string dataDir = @"C:\Pdf\test351\";
Document doc = new Document(dataDir + "PDFIssue.pdf");
// from Manipulate Table Sample
TableAbsorber absorber = new TableAbsorber();
absorber.Visit(doc.Pages[1]);
for (int j = 1; j < absorber.TableList[0].RowList.Count; ++j)
{
TextFragment text = absorber.TableList[0].RowList[j].CellList[2].TextFragments[1];
int pageno = 0;
Int32.TryParse(text.Text, out pageno);
LinkAnnotation annotation = new LinkAnnotation(text.Page, text.Rectangle);
annotation.Action = new GoToAction(new XYZExplicitDestination(doc.Pages[pageno], 0, doc.Pages[pageno].Rect.Height, 0));
text.Page.Annotations.Add(annotation);
}
doc.Save(dataDir + "Output.pdf");