zulu
zulu

Reputation: 21

IText PdfAction using Cyrillic characters

I try to use the PdfAction in combination with the PdfOutline to create a link to a document stored on a central network location. This works fine, but when cyrillic characters are used in the url, the system can not find the document. Investigation learned that in the link opened by the Pdf all cyrillic characters are gone ?!.

My Code:

//Create the index tree

PdfOutline index = new PdfOutline(writer.getDirectContent().getRootOutline(), new PdfDestination(PdfDestination.FITH), "Detailed Info");

//Add entry to index

PdfAction act = new PdfAction("file://CENTRALSERVER/Конвертинг/MyFile.xls");
new PdfOutline(index, act, "My File");

What did I do wrong?

Upvotes: 2

Views: 333

Answers (1)

Jose Llausas
Jose Llausas

Reputation: 3406

It looks like you are having some string encoding problems. The function probably expects an UTF-8 string , Since it detects 'ilegal' characters they become stripped. You can try encoding your string so it can go through the function without being stripped of bad characters:

public static String encodeFilename(String s)
{
    try
    {
        return java.net.URLEncoder.encode(s, "UTF-8");
    }
    catch (java.io.UnsupportedEncodingException e)
    {
        throw new RuntimeException("UTF-8 is an unknown encoding!?");
    }
}

Also try looking at this question for more information about string encoding

In the end your code could look like this:

PdfAction act = new PdfAction(encodeFilename("file://CENTRALSERVER/Конвертинг/MyFile.xls"));

Upvotes: 1

Related Questions