嗨我用PDF格式显示pdf的阿拉伯语文本,它会从左到右打印字符,但我想要一个从右到左的单词,因为单个单词来自数据库而不是单个字符。我上传icu4j-49_1。但它不起作用。 我也使用过PDFTextStriper它会绑定字符,但只能在控制台打印方向从左到右。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String relativeWebPath = "/font/arial.ttf";
String absoluteDiskPath = getServletContext().getRealPath(relativeWebPath);
File file = new File(absoluteDiskPath);
System.out.print(file);
ByteArrayOutputStream output=new ByteArrayOutputStream();
PDDocument document=new PDDocument();
PDFont font = PDType0Font.load(document, new File(absoluteDiskPath));
PDPage test=new PDPage();
document.addPage(test);
PDPageContentStream content=new PDPageContentStream(document, test);
final String EXAMPLE = "نديم";
System.out.print(EXAMPLE);
try{
con=DBUtility.getConnection();
stmt=con.prepareStatement("select * from login");
rs=stmt.executeQuery();
while(rs.next()){
userName=rs.getString("UserName");
password=rs.getString("Password");
content.beginText();
content.newLineAtOffset(50, 680);
content.setFont(font, 12);
content.showText(rs.getString("UserName"));
System.out.print(rs.getString("Password"));
content.endText();
}
}catch(SQLException ex){
ex.printStackTrace();
}
content.close();
PDFTextStripper textStripper = new PDFTextStripper();
String Text = textStripper.getText(document);
System.out.print(Text);
document.save(output);
document.close();
response.setContentType("application/pdf;base64,BASE_64_ENCODED_PDF");
response.addHeader("Content-Disposition", "inline; filename=\"TestReport.pdf\"");
response.getCharacterEncoding();
response.getOutputStream().write(output.toByteArray());
}