瀏覽代碼

html转pdf切换成OpenPDF

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

+ 2 - 3
eladmin-system/src/main/java/me/zhengjie/base/util/HtmlConvertToPdf.java

@@ -3,7 +3,6 @@ package me.zhengjie.base.util;
 import com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder;
 import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
 import lombok.extern.slf4j.Slf4j;
-import me.zhengjie.sign.connector.HttpClient;
 import org.apache.commons.io.FileUtils;
 import org.jsoup.Jsoup;
 import org.jsoup.helper.W3CDom;
@@ -118,8 +117,8 @@ public class HtmlConvertToPdf implements InitializingBean {
 		//引入指定字体,注意字体名需要和css样式中指定的字体名相同
 		String fontPath = HtmlConvertToPdf.class.getClassLoader().getResource("").getPath();
 		System.out.println(fontPath);
-		builder.useFont(new File(fontPath + simsumPath), "SimSun", 0, BaseRendererBuilder.FontStyle.NORMAL, true);
-		builder.useFont(new File(fontPath + simfangPath), "simfang", 0, BaseRendererBuilder.FontStyle.NORMAL, true);
+		builder.useFont(new File(fontPath + simsumPath.substring(simsumPath.indexOf("/") + 1)), "SimSun", 0, BaseRendererBuilder.FontStyle.NORMAL, true);
+		builder.useFont(new File(fontPath + simfangPath.substring(simfangPath.indexOf("/") + 1)), "simfang", 0, BaseRendererBuilder.FontStyle.NORMAL, true);
 
 		builder.run();
 	}