Partial text as hyperlink

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v10)  /  Partial text as hyperlink

DynamicPDF CoreSuite for .NET (v10) Forum

 Nov 24 2020 10:05 AM
Hi Team,

While evaluating DynamicPDF I came across a requirement which I am facing difficulty to achieve. Basically the scenario is to form a part of a text as hyperlink to a different section in the same document. For example, consider a string "Click here to go to xyz section" and here my need is to make the word "Click" clickable and upon clicking "Click" word it should navigate to a destination in the same document.
Can you please help me in finding the fix for this?

Thanks,
Chinmaya
 Nov 24 2020 3:00 PM
Posted by a ceTe Software moderator
Hello  Chinmaya,

You can accomplish this by using a Link page element with an XYDestination. Please refer to this link from our documentation on the Link page element here. Please be sure to use an XYDestination as the action for the Link.

Thanks,
ceTe Software Support Team
 Nov 24 2020 8:03 PM
Thank you for your quick reply.

Here the challenging part is to making the text "Click" as clickable link. How to make the part of a text as hyperlink?

Can you please help me (may be a code snippet) for the same?

Regards,
Chinmaya
 Dec 07 2020 11:00 AM
Posted by a ceTe Software moderator
Hello Chinmaya,

The combination of Link and Label elements can give the feel of a hyperlink. The Link element can take different Actions. Please go through the help documentation about Actions and XYDestination.

Currently, it is not possible to make a random word as a link directly from a text area or a line. However, you could handle it by calculating the text width till the actual Link and add the Link at that location. You can get the text width by using the Font.GetTextWidth method.

Pseudo-code could be.

float firstTextWidth = font.GetTextWidth("This is some text having a link, ", fontSize);
Label firstPartOfText = new Label("This is some text having a link, ", x, y, firstTextWidth, height, font, fontSize);
x += firstTextWidth;

float linkTextWidth = font.GetTextWidth("Click here ", fontSize);
Label linkText = new Label("Click here", x, y, linkTextWidth, height, font, fontSize, RgbColor.Blue);
linkText.Underline = true;
Link link = new Link(x, y, linkTextWidth, height, goToAction);
x += linkTextWidth;

Label secondPartOfText = new Label(" to navigate to second page", x, y, font.GetTextWidth(" to navigate to second page", fontSize), height, font, fontSize);

Thanks,
ceTe Software Support Team.

All times are US Eastern Standard time. The time now is 6:50 PM.