Java PDFBox-无法对由代理项对组成的字符串进行编码
在我的PDFBox实现中,我通过测试不同的字体创建了用多种语言编写字符串的方法Java PDFBox-无法对由代理项对组成的字符串进行编码,java,unicode,pdfbox,emoji,surrogate-pairs,Java,Unicode,Pdfbox,Emoji,Surrogate Pairs,在我的PDFBox实现中,我通过测试不同的字体创建了用多种语言编写字符串的方法 PDFont currentFont = PDType0Font.load(pdfDocument, new File("path/to/font/font.ttf")); for (int offset = 0; offset < sValue.length();) { int iCodePoint = sValue.codePointAt(offset); boolean isEncodab
PDFont currentFont = PDType0Font.load(pdfDocument, new File("path/to/font/font.ttf"));
for (int offset = 0; offset < sValue.length();) {
int iCodePoint = sValue.codePointAt(offset);
boolean isEncodable = isCodePointEncodable(currentFont, iCodePoint);
//-Further logic here, etc.
offset += Character.charCount(iCodePoint);
}
private boolean isCodePointEncodable (PDFont currentFont, int iCodePoint) throws IOException {
StringBuilder st = new StringBuilder();
st.appendCodePoint(iCodePoint);
try {
currentFont.encode(st.toString());
return true;
} catch (IllegalArgumentException iae) {
return false;
}
}
PDFont-currentFont=PDType0Font.load(pdfDocument,新文件(“path/to/font/font.ttf”);
对于(int offset=0;offset
虽然这适用于基本多语言平面(BMP)中的任何内容,但任何涉及BMP之外的Unicode的内容都不起作用。我已经下载并用字形图表广泛地查看了涉及的字体,并记录了每个代码。例如,当尝试编码时,我已经创建并解决了这个问题。原因是我们没有使用最好的cmap子表 虽然没有解决办法,但该漏洞将在几个月后的2.0.9版中修复。但是你不必等那么久,你可以用一个测试仪来测试