generating Persian PDF with iText

巧了我就是萌 提交于 2019-12-12 10:43:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!