问题
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();
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.
回答1:
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)
来源:https://stackoverflow.com/questions/24683985/generating-persian-pdf-with-itext