我正在使用iText 5.5.10
创建PDF。当我使用英语单词时,它可以很好地工作,但是当我使用阿拉伯语单词时,它可以显示空行。
问题出在哪里,我该如何解决?预先感谢。
public void createPDF1(View view) throws IOException, DocumentException {
// BaseFont urName = BaseFont.createFont("assets/subFolder/fontName.TTF", "UTF-8",BaseFont.EMBEDDED);
// Font urFontName = new Font(urName, 12);
Font font = FontFactory.getFont("Simplified Arabic", BaseFont.IDENTITY_H, true, 22, Font.BOLD);
EditText et=(EditText)findViewById(R.id.txt_input);
BaseFont ArialBase = BaseFont.createFont("assets/tahoma.ttf", BaseFont.IDENTITY_H, true);
Font ArialFont = new Font(ArialBase, 20);
// Font f = FontFactory.getFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font chapterFont = FontFactory.getFont("assets/arialuni.ttf", BaseFont.IDENTITY_H, 16, Font.BOLDITALIC);
Font f=new Font(Font.FontFamily.TIMES_ROMAN,50.0f,Font.UNDERLINE,BaseColor.RED);
Document document = new Document();
String outpath= Environment.getExternalStorageDirectory()+"/mypdf1.pdf";
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outpath));
document.open();
Phrase p = new Phrase("This is incorrect:احمد",ArialFont);
p.add(new Chunk("احمد",ArialFont));
p.add(new Chunk(": 50.00 USD"));
document.add(p);
p = new Phrase("This is correct: ");
p.add(new Chunk("#"+et.getText().toString(),chapterFont));
p.add(new Phrase(": 50.00"));
ColumnText canvas = new ColumnText(writer.getDirectContent());
canvas.setSimpleColumn(36, 750, 559, 780);
canvas.setRunDirection(PdfWriter.RUN_DIRECTION_LTR);
canvas.addElement(p);
canvas.go();
document.close();
}
我已经尝试过this post中的建议,但这是行不通的。