How to set the BaseUrl of an existing PDF document?

We're having trouble setting a BaseUrl using iTextSharp.

31st May 2016
iText PDF

We have used Adobes Implementation for this in the past, but we got some severe performance issues. So we switched to iTextSharp, which is aprox 10 times faster.

Adobe enabled us to set a base url for each document. We really need this in order to deploy our documents on different servers. But we cant seem to find the right code to do this.

This code is what we used with Adobe:


public bool SetBaseUrl(object jso, string baseUrl)
        object result = jso.GetType().InvokeMember("baseURL", BindingFlags.SetProperty, null, jso, new Object[] {baseUrl });
        return result != null;
        return false;
A lot of solutions describe how you can insert links in new or empty documents. But our documents already exist and do contain more than just text. We want to overlay specific words with a link that leads to one or more other documents. Therefore, its really important to us that we can insert a link without accessing the text itself. Maybe lay a box on top of these words and set its position (since we know where the words are located in the document)

We have tried different implementations, using the setAction method, but it doesn't seem to work properly. The result was in most cases, that we saw out box, but there was no link inside or associated with it. (the cursor didn't change and nothing happened, when I clicked inside the box)


Posted on StackOverflow on Jul 4, 2014 by Chrisi


I've made you a couple of examples in iText 7. If you want an iText for C# example, you'll discover that it is very easy to port the Java to C# as the terminology is identical.

First, let's take a look at BaseURL1. In your comment, you referred to JavaScript, so I created a document to which I added a snippet of document-level JavaScript:

pdfDoc.getCatalog().setOpenAction(PdfAction.createJavaScript("this.baseURL = \"\"";""));


Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now