2016-05-26 46 views
1

我尝试将PdfAction与PdfOutline结合使用来创建指向存储在中央网络位置的文档的链接。这工作正常,但是当在URL中使用西里尔文字符时,系统找不到文档。调查了解到,在由Pdf打开的链接中,所有西里尔字符都没有了?!使用西里尔字符的IText PdfAction

我的代码:

//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"); 

我做了什么错?

回答

1

它看起来像你有一些字符串编码问题。该函数可能期望一个UTF-8字符串,因为它检测到'回归'字符,它们会被剥离。您可以尝试编码您的字符串,以便它可以顺利通过功能没有被剥离的不良特征:

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!?"); 
    } 
} 

也可以尝试在看这个question有关字符串编码

更多信息最终你的代码可能看起来像这样:

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