2024年11月win7系统下JFreeChart1.0.1和iText集成时,中文字符出现乱码的解决方法
⑴环境:JFreeChart ..iText.
⑵JFreeChart..中的Plot接口没有提供SetValueLabelFont的方法,无法直接设置label的字体!
⑶不过还好试了一下午总算弄出来了,具体代码如下:
⑷记住别忘了添加iTextAisan.jar不然会报如下错误:下载地址:iTextAsian.jar下载(&位
⑸.lowagie.text.DocumentException: Font 'STSong-Light' with 'UniGB-UCS-H' is not recognized.
⑹at .lowagie.text.pdf.BaseFont.createFont(Unknown Source)
⑺at .lowagie.text.pdf.BaseFont.createFont(Unknown Source)
⑻at .lowagie.text.pdf.AsianFontMapper.awtToPdf(Unknown Source)
⑼at .lowagie.text.pdf.PdfGraphicsD.getCachedBaseFont(Unknown Source)
⑽at .lowagie.text.pdf.PdfGraphicsD.setFont(Unknown Source)
⑾at .lowagie.text.pdf.PdfGraphicsD.(Unknown Source)
⑿at .lowagie.text.pdf.PdfContentByte.createGraphics(Unknown Source)
⒀at JFreeChartExample.convertToPdf(JFreeChartExample.Java:)
⒁at JFreeChartExample.main(JFreeChartExample.java:)
⒂.lowagie.text.DocumentException: Font 'STSong-Light' with 'UniGB-UCS-H' is not recognized.
⒃at .lowagie.text.pdf.BaseFont.createFont(Unknown Source)
⒄at .lowagie.text.pdf.BaseFont.createFont(Unknown Source)
⒅at .lowagie.text.pdf.AsianFontMapper.awtToPdf(Unknown Source)
⒆at .lowagie.text.pdf.PdfGraphicsD.getCachedBaseFont(Unknown Source)
⒇at .lowagie.text.pdf.PdfGraphicsD.setFont(Unknown Source)
⒈at .jfree.chart.title.TextTitle.arrangeRR(TextTitle.java:)
⒉at .jfree.chart.title.TextTitle.arrange(TextTitle.java:)
⒊at .jfree.chart.JFreeChart.drawTitle(JFreeChart.java:)
⒋at .jfree.chart.JFreeChart.draw(JFreeChart.java:)
⒌at .jfree.chart.JFreeChart.draw(JFreeChart.java:)
⒍at JFreeChartExample.convertToPdf(JFreeChartExample.java:)
⒎at JFreeChartExample.main(JFreeChartExample.java:)
⒏Exception in thread "main" java.lang.NullPointerException
⒐at .lowagie.text.pdf.PdfWriter.addSimple(Unknown Source)
⒑at .lowagie.text.pdf.PdfContentByte.setFontAndSize(Unknown Source)
⒒at .lowagie.text.pdf.PdfGraphicsD.drawString(Unknown Source)
⒓at .jfree.text.TextUtilities.drawRotatedString(TextUtilities.java:)
⒔at .jfree.text.TextUtilities.drawRotatedString(TextUtilities.java:)
⒕at .jfree.text.TextFragment.draw(TextFragment.java:)
⒖at .jfree.text.TextLine.draw(TextLine.java:)
⒗at .jfree.text.TextBlock.draw(TextBlock.java:)
⒘at .jfree.text.TextBlock.draw(TextBlock.java:)
⒙at .jfree.chart.title.TextTitle.drawHorizontal(TextTitle.java:)
⒚at .jfree.chart.title.TextTitle.draw(TextTitle.java:)
⒛at .jfree.chart.JFreeChart.drawTitle(JFreeChart.java:)
①at .jfree.chart.JFreeChart.draw(JFreeChart.java:)
②at .jfree.chart.JFreeChart.draw(JFreeChart.java:)
③at JFreeChartExample.convertToPdf(JFreeChartExample.java:)
④at JFreeChartExample.main(JFreeChartExample.java:)