Free Support Forum - aspose.com

Hyperlink in table cell

I have tried the suggestions on these two pages:

- http://www.aspose.com/community/forums/thread/394128/how-to-add-hyperlinks-to-table-cells.aspx
- http://www.aspose.com/docs/display/pdfnet/Working+with+Hyperlinks+%28Generator%29

However, I am still having problems generating hyperlinks. The text is displayed as expected.

Code as follows (where row is an instance of Aspose.Pdf.Generator.Row):

Aspose.Pdf.Generator.Cell cell = row.Cells.Add();
Aspose.Pdf.Generator.Text cellText = new Text();
Aspose.Pdf.Generator.Segment segment = cellText.Segments.Add("Test text");
segment.Hyperlink = new Aspose.Pdf.Generator.Hyperlink();
segment.Hyperlink.LinkType = HyperlinkType.Web;
segment.Hyperlink.Url = "http://www.aspose.com/";

cell.Paragraphs.Add(cellText);

Thanks for your advice.

Hi there,


Thanks for your inquriy. Please note you are using old generator(Aspose.Pdf.Generator), it is recommended to use new generator(Aspose.Pdf). New generator is more efficient and improved. Furthermore, we are not fixing issues and making any improvement in old generator as it will be obsolete in near future.

In reference to your requirement, please check following code snippet for adding hyperlink in a table cell using new generator.

Aspose.Pdf.Cell
cell = row.Cells.Add();<o:p></o:p>

cell.BackgroundColor = Aspose.Pdf.Color.Yellow;<o:p></o:p>

// Create Text Fragment instance<o:p></o:p>

Aspose.Pdf.Text.TextFragment
text = new Aspose.Pdf.Text.TextFragment(“Aspose
Website”
);<o:p></o:p>

// Create local hyperlink instance<o:p></o:p>

Aspose.Pdf.WebHyperlink
link = new Aspose.Pdf.WebHyperlink();<o:p></o:p>

// Set target page for link instance<o:p></o:p>

link.Url = http://www.aspose.com/;<o:p></o:p>

// Set TextFragment hyperlink<o:p></o:p>

text.Hyperlink = link;<o:p></o:p>

cell.Paragraphs.Add(text);<o:p></o:p>

....


Please feel free to contact us for any further assistance.

Best Regards,

Hi team,

I am still facing the same issue.
Below is my code sample:

Everything is derived from Aspose.Pdf.Generator
and link is Aspose.Pdf.Generator.Hyperlink

Cell newCell = row.Cells.Add();
newCell.IsNoBorder = true;
Text text = new Text();
text.Segments.Add(attachmentLabelTxt);
text.Segments.Add(link.LinkFile);

        Segment sg = new Segment();
        sg.Hyperlink = link;
        text.Segments.Add(sg);

        newCell.Paragraphs.Add(text);

Can you please help? Quick response is much appreciated!

@sandhyacp

Thanks for your inquiry.

I am afraid that you are using quite older approach i.e. Aspose.Pdf.Generator, which has been discontinued. It is now recommended to use new DOM (Aspose.Pdf) model and related code has already been shared in this thread.

Please try using already shared code snippet and in case you still face any issue, please share complete sample code snippet you have tried along with sample PDF document. We will test the scenario in our environment and address it accordingly.