我在 Linux Mint 17.1 之上使用 itext-7.0.1
我正在尝试将非 ASCII 文本(希伯来语)添加到 PdfDocument,但文本中缺少所有希伯来语字母:
private void writePdf(Entity entity, OutputStream outputStream) throws IOException {
PdfWriter pdfWriter = new PdfWriter(outputStream);
PdfDocument pdfDocument = new PdfDocument(pdfWriter);
Document document = new Document(pdfDocument);
PdfFont font = PdfFontFactory.createRegisteredFont("open sans", "UTF-8"); //A correctly registered font
document.add(new Paragraph("Some English Letters").setFont(font)); //This will appear well inthe PDF
document.add(new Paragraph(entity.getName()).setFont(font)); //This will appear as a blank line
System.out.println(entity.getName()); //Written correctly to stdout
document.add(new Paragraph(entity.getId()).setFont(font)); //This will appear correctly in the PDF
document.close();
System.exit(-1);
}
总结上面的代码:所有 ASCII 文本(英文和数字)都正确写入 PDF,但希伯来字母 ( entity.getName()
) 写为空行。上面的字体在文字处理器中正确输入,但是为了验证这一点,我尝试了其他导致相同结果的字体。
在 itext-5 中有很多内容。我应该切换到 itext-5 而不是 7 吗?