2

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?

Gandhi
  • 11,875
  • 4
  • 39
  • 63
zulu
  • 21
  • 2

1 Answers1

1

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"));
Community
  • 1
  • 1
Jose Llausas
  • 3,366
  • 1
  • 20
  • 24
  • I had the same problem with jasper reports, where deep down a PdfAction is generated. I used the encoding but sadly IE doesn't like %-encoded file-Urls, so i had to run over the generated pdf, find the urls and decode it again. – Turo Mar 21 '18 at 13:30