From 50b3c6a9000d9bf8832644782767f479c8cecd76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Wed, 9 Oct 2024 07:39:15 +0800 Subject: [PATCH] 'commit' --- dsPay.iml | 8 +++ dsPay/pom.xml | 6 ++- dsPay/src/main/java/Echarts.java | 26 ++++++++++ dsPay/src/main/java/HtmltoPDF.java | 82 ------------------------------ index.html | 70 +++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 83 deletions(-) create mode 100644 dsPay.iml create mode 100644 dsPay/src/main/java/Echarts.java delete mode 100644 dsPay/src/main/java/HtmltoPDF.java create mode 100644 index.html diff --git a/dsPay.iml b/dsPay.iml new file mode 100644 index 00000000..d49acea1 --- /dev/null +++ b/dsPay.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/dsPay/pom.xml b/dsPay/pom.xml index 4811b97e..fef37cba 100644 --- a/dsPay/pom.xml +++ b/dsPay/pom.xml @@ -42,7 +42,11 @@ xhtmlrenderer 1.0.0 - + + org.icepear.echarts + echarts-java + 1.0.7 + com.lowagie diff --git a/dsPay/src/main/java/Echarts.java b/dsPay/src/main/java/Echarts.java new file mode 100644 index 00000000..3c61d8fa --- /dev/null +++ b/dsPay/src/main/java/Echarts.java @@ -0,0 +1,26 @@ +import org.icepear.echarts.Bar; +import org.icepear.echarts.render.Engine; + +public class Echarts { + + //https://github.com/ECharts-Java/ECharts-Java + public static void main(String[] args) { +// All methods in EChart Java supports method chaining + Bar bar = new Bar() + .setLegend() + .setTooltip("item") + .addXAxis(new String[] { "Matcha Latte", "Milk Tea", "Cheese Cocoa", "Walnut Brownie" }) + .addYAxis() + .addSeries("2015", new Number[] { 43.3, 83.1, 86.4, 72.4 }) + .addSeries("2016", new Number[] { 85.8, 73.4, 65.2, 53.9 }) + .addSeries("2017", new Number[] { 93.7, 55.1, 82.5, 39.1 }); + Engine engine = new Engine(); + // The render method will generate our EChart into a HTML file saved locally in the current directory. + // The name of the HTML can also be set by the first parameter of the function. + engine.render("index.html", bar); + + // It is recommended that you can get the serialized version of Option in the representation of JSON, which can be used directly in the template or in the RESTful APIs. + String jsonStr = engine.renderJsonOption(bar); + System.out.println(jsonStr); + } +} diff --git a/dsPay/src/main/java/HtmltoPDF.java b/dsPay/src/main/java/HtmltoPDF.java deleted file mode 100644 index d1b01618..00000000 --- a/dsPay/src/main/java/HtmltoPDF.java +++ /dev/null @@ -1,82 +0,0 @@ -import java.io.File; -import java.io.FileOutputStream; -import java.io.OutputStream; - - -import org.xhtmlrenderer.pdf.ITextFontResolver; -import org.xhtmlrenderer.pdf.ITextRenderer; - -import com.lowagie.text.pdf.BaseFont; - - -public class HtmltoPDF { - - public static void main( String[] args ) throws Exception{ - - -// htmlToPdf(); -// htmlToPdf2(); - htmlToPdf3(); - } - - // 不支持中文 - public static void htmlToPdf() throws Exception - { - String inputFile = "D:/Test/flying.html"; - String url = new File( inputFile ).toURI().toURL().toString(); - String outputFile = "D:/Test/flying.pdf"; - OutputStream os = new FileOutputStream( outputFile ); - ITextRenderer renderer = new ITextRenderer(); - renderer.setDocument( url ); - renderer.layout(); - renderer.createPDF( os ); - os.close(); - } - - // 支持中文 - public static void htmlToPdf2() throws Exception { - String outputFile = "F:/TestDemo/demo_3.pdf"; - OutputStream os = new FileOutputStream(outputFile); - ITextRenderer renderer = new ITextRenderer(); - ITextFontResolver fontResolver = renderer.getFontResolver(); - fontResolver.addFont("C:/Windows/fonts/simsun.ttc", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); - StringBuffer html = new StringBuffer(); - // DOCTYPE 必需写否则类似于 这样的字符解析会出现错误 - html.append(""); - html.append(""). - append("") - .append("") - .append("") - .append("") - .append(""); - html.append("支持中文!"); - html.append(""); - renderer.setDocumentFromString(html.toString()); - // 解决图片的相对路径问题 - // renderer.getSharedContext().setBaseURL("file:/F:/teste/html/"); - renderer.layout(); - renderer.createPDF(os); - System.out.println("======转换成功!"); - os.close(); - } - - public static void htmlToPdf3() throws Exception{ - String inputFile = "F:/TestDemo/test.html"; //本地目录必须html语言否则报错 - String outFile = "F:/TestDemo/test.pdf"; - OutputStream os = null; - os = new FileOutputStream(outFile); - ITextRenderer renderer = new ITextRenderer(); - ITextFontResolver fontResolver = renderer.getFontResolver(); - fontResolver.addFont("C:/Windows/fonts/simsun.ttc", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); - - String url = new File( inputFile ).toURI().toURL().toString(); - System.out.println("=============url: "+url); - renderer.setDocument(url); - renderer.layout(); - renderer.createPDF(os); - System.out.println("======转换成功!"); - os.close(); - } - - -} \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 00000000..cc908df5 --- /dev/null +++ b/index.html @@ -0,0 +1,70 @@ + + + + + + ECharts Demo + + + + + + + + ECharts Java + Download Image + + + + + + + + + \ No newline at end of file