java - PDFbox arabic textnot show retrieve from database mysql -


i want display pdf report in arabic generated through mysql database. here code:

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 * 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());   } 

it shows arabic text on console pdf gives error:

type exception report

message u+0646 not available in font's encoding: winansiencoding

description server encountered internal error prevented >fulfilling request.

exception

java.lang.illegalargumentexception: u+0646 not available in 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) 

if not done, please update 2.0. javadoc has note:

note: simple fonts support 256 characters. unicode support, use pdtype0font.load(pddocument, file) instead.

so this:

pdfont font = pdtype0font.load(document, new file(absolutediskpath); 

this doesn't work 1.8 or earlier.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -