我正在使用iText在html字符串中创建pdf在java下面是我的代码
try {
Document document = new Document(PageSize.LETTER);
PdfWriter pdfWriter = PdfWriter.getInstance
(document, new FileOutputStream("d://itextpdf.pdf"));
document.open();
XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
String str = "<html><head></head><body>"+
"<table border='1' cellpadding='1' cellspacing='1' id='' class=''>" +
"<tr><th> Sr.No.</th><th>Currency Id</th><th>Code</th><th>Name</th>" +
"<tr><td align='center'>1</td><td align='center'>1</td>"+
"<td align='center'>100</td>"+
"<td align='center'>الرياض (رويترز)</td></tr>" +
"</table></body></html>"
worker.parseXHtml(pdfWriter, document,
new InputStreamReader(new ByteArrayInputStream(str.getBytes("UTF-8")))) ;
document.close();
}catch(Exception e){ }
但它无法在生成的pdf中显示阿拉伯数据。我该怎么办?请帮忙。
答案 0 :(得分:0)
你可以在写字之前设置字体。 实施例
BaseFont bf = BaseFont.createFont("c:/windows/fonts/arial.ttf", BaseFont.IDENTITY_H, true);
Font font = new Font(bf, 14);