Jrxml Field property settings:
< TextElement > < fontname= "Song Body" pdffontname= "Stsong-light" pdfencoding = "Unigb-ucs2-h" ispdfembedded = "true" /> </ TextElement >
Introduction of the Itextasian-1.5.2.jar file in the project LIB, note that the directory structure of the file is com/lowagie/text/pdf/fonts/*, the latest Itext-asian.jar package is not the structure of the normal use,
Java Sample code:
/*** * Database connection * * **/ Public StaticConnection getconnection () {Connection conn=NULL; String Driver= "Net.sourceforge.jtds.jdbc.Driver"; String URL= "JDBC:JTDS:SQLSERVER://127.0.0.1:1433/CODE-WH"; Try{class.forname (driver); Conn= Drivermanager.getconnection (URL, "sa", "123"); returnConn; } Catch(ClassNotFoundException e) {e.printstacktrace (); } Catch(SQLException ex) {ex.printstacktrace (); } return NULL; } Public Static voidMain (string[] args)throwsException {String fileName= "D:/coffee.jrxml"; LongStartTime =System.currenttimemillis (); //compile the report's definition file *.jrxml into a *.jasper fileString Jasperfile =Jaspercompilemanager.compilereporttofile (fileName); //populate the *.jasper file with data, this step will produce the *.jrprint fileString Jrprintfile =jasperfillmanager.fillreporttofile (Jasperfile,NULL, getconnection ()); System.out.println ("jrprintfile==" +jrprintfile); //Convert. jrprint files to HTML formatJasperexportmanager.exportreporttohtmlfile (Jrprintfile); //Convert. jrprint files to PDF formatJasperexportmanager.exportreporttopdffile (Jrprintfile); //Convert. jrprint files to XML format//Jasperexportmanager.exportreporttoxmlfile (Jrprintfile, false); //converting. jrprint files to an XLS format (that is, an Excel file) requires a POI class library.File sourcefile=NewFile (Jrprintfile); Jasperprint Jasperprint=(Jasperprint) jrloader.loadobject (sourcefile); File DestFile=NewFile (Sourcefile.getparent (), Jasperprint.getname ()+ ". xls"); Jrxlsexporter exporter=NewJrxlsexporter (); Exporter.setexporterinput (Newsimpleexporterinput (jasperprint)); Exporter.setexporteroutput (Newsimpleoutputstreamexporteroutput (destfile)); Simplexlsreportconfiguration Configuration=Newsimplexlsreportconfiguration (); Configuration.setonepagepersheet (false); Exporter.setconfiguration (configuration); Exporter.exportreport (); LongEndTime =System.currenttimemillis (); LongTime = (endtime-starttime)/1000; System.out.println ("Success with" + Time + "s"); }
jasperreports-5.6 + jaspersoftstudio-5.6 Generate PDF file Chinese does not display the problem correctly