Pet*_*erg 3 java pdf fonts itext
这是关于如何将古吉拉特语 - 印度语的字体导出为pdf的后续问题?,@ amedee-van-gasse,iText的质量保证工程师让我用相关的mcve发布一个特定于itext的问题.
为什么这个unicode序列\u0ab9\u0abf\u0aaa\u0acd\u0ab8
没有正确呈现?
它应该像这样呈现:
હિપ્સ,也用unicode转换器测试过
但是这段代码(示例改编自iText:第11章:选择正确的字体)
public class FontTest {
/** The resulting PDF file. */
public static final String RESULT = "fontTest.pdf";
/** the text to render. */
public static final String TEST = "\u0ab9\u0abf\u0aaa\u0acd\u0ab8";
public void createPdf(String filename) throws IOException, DocumentException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
BaseFont bf = BaseFont.createFont(
"ARIALUNI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bf, 20);
ColumnText column = new ColumnText(writer.getDirectContent());
column.setSimpleColumn(36, 730, 569, 36);
column.addElement(new Paragraph(TEST, font));
column.go();
document.close();
System.out.println("DONE");
}
public static void main(String[] args) throws IOException, DocumentException {
new FontTest().createPdf(RESULT);
}
}
Run Code Online (Sandbox Code Playgroud)
生成此结果:
那看起来与众不同
હિપ્સ
我有测试itextpdf-5.5.4.jar
,itextpdf-5.5.9.jar
并且itext-2.1.7.js3.jar
(与jasper报告分发)
使用它的字体与MS Office一起分发,ARIALUNI.TTF
可以从这里下载Arial Unicode MS *也许有一些法律问题下载见Mike'Pomax'Kamermans评论
无论您选择哪种字体,iText5和iText2(顺便说一下,它都是非常过时的版本)都不支持人工智能脚本的渲染.
渲染印度语脚本与任何拉丁文脚本都不相似,因为应该采取一系列额外的操作来获得正确的结果,例如,某些字符需要首先根据语言规则重新排序.
这是iText公司的一个已知问题.
在iText5中有一个名为GujaratiLigaturizer的Gujaranti的存根实现,但实现真的很差,你不能期望得到正确的结果.
您可以尝试使用此ligaturizer处理字符串,然后按以下方式输出结果字符串:
IndicLigaturizer g = new GujaratiLigaturizer();
String processed = g.process(inputString);
// proceed with the processed string
Run Code Online (Sandbox Code Playgroud)