我对iText库还不熟悉。我的需求是需要将输出转换为PDF格式,并且其中包含阿拉伯字符。我创建了一个测试servlet,代码如下:
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType ("application/pdf;charset=UTF-8");
Document document = new Document();
try{
PdfWriter.getInstance(document,
response.getOutputStream()); // Code 2
document.open();
Font f1;
BaseFont bf = BaseFont.createFont("C:\\WINDOWS\\Fonts\\ARIALUNI.ttf", BaseFont.CP1252, true);
f1 = new Font(bf, 10);
PdfPTable table = new PdfPTable(2);
table.addCell("hellooooo1");
table.addCell("world2");
table.addCell("1113");
table.addCell("422");
// String a = "يبسبيبيبيسسسيبيببيسبيسيببي";
String a = "سش";
PdfPCell cell = new PdfPCell (new Paragraph (a,f1));
table.addCell (cell);
cell = new PdfPCell (new Paragraph ("Road",f1));
table.addCell (cell);
document.add(table);
document.close();
}catch(DocumentException e){
e.printStackTrace();
}
}
我们使用阿拉伯字符输出的结果显示为?????。如何纠正这个问题?我在哪里犯了错误?
a
直接添加到文档中,而不是作为表格的一部分。如果这样仍然无法解决问题,我们就知道问题不是由 PdfTable 类引起的。 - Mark Storer