|
@@ -0,0 +1,90 @@
|
|
|
+package com.yaoyicloud.render;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 抽象渲染器
|
|
|
+ *
|
|
|
+ */
|
|
|
+public abstract class AbstractRender {
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 导出文件位置
|
|
|
+ */
|
|
|
+ protected final String cwd;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Docx结果文件路径
|
|
|
+ */
|
|
|
+ protected String docxResultPath;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * html结果文件路径
|
|
|
+ */
|
|
|
+ protected String htmlResultPath;
|
|
|
+
|
|
|
+ /*
|
|
|
+ * pdf结果文件路径
|
|
|
+ */
|
|
|
+ protected String pdfResultPath;
|
|
|
+
|
|
|
+ public AbstractRender(String cwd) {
|
|
|
+ this.cwd = cwd;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Docx 渲染
|
|
|
+ * @param info 数据
|
|
|
+ * @param templateFileContent 模板内容
|
|
|
+ * @return 本地文件目录
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public final String renderDocx(String json /* 可能会改成对象 */, Byte[] templateFileContent, String outputPath) throws IOException {
|
|
|
+ // 用POI 渲染模板
|
|
|
+ // 保存到 cwd 目录,文件名使用 ServiceProviderInfo + uuid
|
|
|
+ // 注: 目前的实现假设:一个session对应一个cwd目录
|
|
|
+
|
|
|
+ this.docxResultPath = cwd + "/1.docx";
|
|
|
+ return this.docxResultPath;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * docx转换为pdf
|
|
|
+ * @return 本地文件目录
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public final String fromDocxToPdf() throws IOException {
|
|
|
+ // 转换 docxResultPath 为 html
|
|
|
+ // 加工html
|
|
|
+ // 把 html 文件转成 pdf
|
|
|
+ fromDocxToHtml();
|
|
|
+ this.pdfResultPath = fromHtmlToPdf();
|
|
|
+ return this.pdfResultPath;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * docx转换为Html
|
|
|
+ * @return 本地文件目录
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public final String fromDocxToHtml() throws IOException {
|
|
|
+ // 转换 docxResultPath 为 html
|
|
|
+ // 加工html
|
|
|
+ this.htmlResultPath = cwd + "/1.html";
|
|
|
+ return this.htmlResultPath;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * html转换为pdf
|
|
|
+ * @return 本地文件目录
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public final String fromHtmlToPdf() throws IOException {
|
|
|
+ // 转换 htmlResultPath 为 pdf
|
|
|
+ this.pdfResultPath = cwd + "/1.pdf";
|
|
|
+ return this.pdfResultPath;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|