使用iText生成波斯语PDF [英] generating Persian PDF with iText
问题描述
嗨
我知道很多人之前可能会问过这个问题。我几乎阅读了所有这些内容,但它无法帮我解决问题。
我正在使用iText java库生成一个波斯语PDF。我使用以下代码:
Hi
I know that many people may have asked this question before. I've read almost all of them`but it couldn't help me solve my problem.
I'm using iText java library to generate a Persian PDF. I'm using the following code:
Document document = new Document(PageSize.A4,50,50,50,50);
FileOutputStream fos = new FileOutputStream("D:\\ITextTest.pdf");
PdfWriter writer = PdfWriter.getInstance(document,fos);
document.open();
BaseFont bf = BaseFont.createFont("C:\\Windows\\Fonts\\XB YagutBd.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font a = new Font(bf,10);
Paragraph p1 = new Paragraph("سلام دوست من");
p1.setFont(a);
document.add(p1);
document.close();
但是当我执行代码时,没有任何内容写入PDF文件并且它是空白的。请注意,XB YagutBd.ttf是波斯语Unicode字体,p1包含一些波斯语字符。
But when I execute the code, nothing has been written to the PDF file and it's blank. Note that "XB YagutBd.ttf" is a Persian Unicode font and "p1" contains some Persian characters.
我该怎么办?我已经陷入了这个问题......请帮帮我。
What should I do? I've gotten stuck in this problem... help me please.
推荐答案
只有部分iText元素支持RTL,所以as PdfPCell,PdfPTable,ColumnText。
只有这些元素有 RunDirection
属性,可以设置为 PdfWriter.RUN_DIRECTION_RTL
value。 (更多波斯语信息)
Only some of the iText elements support RTL, shuch as PdfPCell, PdfPTable, ColumnText.
Only these elements have RunDirection
property which can be set to PdfWriter.RUN_DIRECTION_RTL
value. (more info in Persian)
这篇关于使用iText生成波斯语PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!