瀏覽代碼

增加本地生成文件代码

sakuya 2 年之前
父節點
當前提交
13f9ad30f3
共有 1 個文件被更改,包括 20 次插入0 次删除
  1. 20 0
      eladmin-system/src/main/java/me/zhengjie/base/util/HtmlConvertToPdf.java

+ 20 - 0
eladmin-system/src/main/java/me/zhengjie/base/util/HtmlConvertToPdf.java

@@ -3,6 +3,7 @@ package me.zhengjie.base.util;
 import com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder;
 import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
 import lombok.extern.slf4j.Slf4j;
+import me.zhengjie.utils.FileUtil;
 import org.apache.commons.io.FileUtils;
 import org.jsoup.Jsoup;
 import org.jsoup.helper.W3CDom;
@@ -130,4 +131,23 @@ public class HtmlConvertToPdf implements InitializingBean {
 
 		builder.run();
 	}
+
+	public static void main(String[] args) {
+		try {
+			HtmlConvertToPdf htmlConvertToPdf = new HtmlConvertToPdf();
+			htmlConvertToPdf.setSimsumPath("/font/simsun.ttf");
+			htmlConvertToPdf.setSimfangPath("/font/simfang.ttf");
+			htmlConvertToPdf.convertPdfWithOpenPDF(FileUtil.readUtf8String("/Users/sakuya/Downloads/9e88124747724a17996afeda61dbb758.html"), "/Users/sakuya/Downloads/a44a021e9a0d473092fd051c48b3d36b.pdf");
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void setSimsumPath(String simsumPath){
+		this.simsumPath=simsumPath;
+	}
+
+	public void setSimfangPath(String simfangPath){
+		this.simfangPath =simfangPath;
+	}
 }