Add Hyperlink (TEXT) in PDF (C#)

Hello friends,

I’m trying to use PDFTron to put a text/string with a hyperlink in a PDF file I created, but I can’t get it to work.

With WriteElement I can’t get it to work somehow. I have already tried a few things, but I can’t find a solution.

Can someone show me a short concrete example, how I can write for example the word “Google” in my PDF, which then leads to “” (web browser) when I click on the word “Google”?

I would be very very grateful.

Thanks in advance.

Hello Frank, welcome to the community.

To add a hyperlink to your text, you would create a link annotation, and overlay it over the text you want to link.

The rectange (bounding box) of the text element can be found using element.GetBBox(urlbbox).

Below is a short example:

element = eb.CreateTextBegin(Font.Create(doc, Font.StandardType1Font.e_times_roman), 12);
string data = "Hello World Google!";
element = eb.CreateTextRun(data);
element.SetTextMatrix(10, 0, 0, 10, 0, 600);
Rect urlbbox = new Rect();
Link hyperlink = Link.Create(doc, urlbbox, pdftron.PDF.Action.CreateURI(doc, ""));

Let me know if this works for you.

It worked very fine. Thanks for your efforts and your help!

I have one more quick question.

How would it be possible in the same construct to underline the text “Google”?

Hi Frank,

See this post:

Let me know if this works for you.

Hi Joe,

I solved the problem in a similar way.

Thanks again for your help. It was very helpful.