jasperreports-5.6 + jaspersoftstudio-5.6 Generate PDF file Chinese does not display the problem correctly

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.