Text from URI value is incorrect

Question:

We are trying to get the URI string from a Link annotation, but the text is not what we see in Acrobat.

string target = action.GetSDFObj().Get("URI").Value().GetAsPDFText();

How do we get the correct text.

Answer:

Link URI are one of the very few places in the PDF standard, where text is in UTF8 format. Nearly every other instance in a PDF is in one of two other encodings (PDF Doc or UTF16-BE).

To get the correct URI string from this try the following code

byte[] utf8Bytes = action.GetSDFObj().Get("URI").Value().GetBuffer(); string target = System.Text.Encoding.UTF8.GetString(utf8Bytes);