私は、mysqlデータベースを介して生成されるアラビア語でPDFレポートを表示する。ここに私のコードは次のとおりです。PDFboxアラビア語textnot表示データベースから取得する
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String relativeWebPath = "/font/A_Nefel_Adeti.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 = PDTrueTypeFont.load(document, new File(absoluteDiskPath),new WinAnsiEncoding());
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();
document.close();
response.setContentType("application/pdf;base64,BASE_64_ENCODED_PDF");
response.addHeader("Content-Disposition", "inline; filename=\"TestReport.pdf\"");
response.getOutputStream().write(output.toByteArray());
}
それは、コンソール上のアラビア語のテキストを示すが、PDFは、このエラーを与える:
type Exception report
message U+0646 is not available in this font's encoding: WinAnsiEncoding
description The server encountered an internal error that prevented it from >fulfilling this request.
例外
java.lang.IllegalArgumentException: U+0646 is not available in this font's encoding: WinAnsiEncoding
org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.encode(PDTrueTypeFont.java:368)
org.apache.pdfbox.pdmodel.font.PDFont.encode(PDFont.java:286)
org.apache.pdfbox.pdmodel.PDPageContentStream.showText(PDPageContentStream.java:411)
uae.org.TestReport.doGet(TestReport.java:93)
javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
ありがとうございます。左から右に向かって、アラビア語のwriting.iとして左から右に欲しい単語は1文字しか表示されませんが、icu4j-49_1.jarは含まれていますが、動作しません。 –
これは別の話題ですが、私はそれについて新しい質問をすることをお勧めします(悲しいことには助けません)、そしてSQLのものを削除し、 "rtl"のようなタグを追加することをお勧めします。うまくいけば、他の人が助けることができます。 –