From f927e53eb5c98de2e19bc1b47512ff655c54d2ba Mon Sep 17 00:00:00 2001
From: zhijie <1003392067@qq.com>
Date: 星期一, 06 九月 2021 22:38:47 +0800
Subject: [PATCH] PAQ转换字体库支持
---
src/main/java/com/ots/project/tool/PdfUtil.java | 17 ++++++++++-------
1 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/src/main/java/com/ots/project/tool/PdfUtil.java b/src/main/java/com/ots/project/tool/PdfUtil.java
index 7745ebd..e960caa 100644
--- a/src/main/java/com/ots/project/tool/PdfUtil.java
+++ b/src/main/java/com/ots/project/tool/PdfUtil.java
@@ -13,21 +13,24 @@
@Slf4j
public class PdfUtil {
+ /**
+ * 璁剧疆鐢ㄦ埛瀛椾綋浣嶇疆
+ */
public static void setFont(){
- String userfontsfoloder = "C:\\Users\\澶уご\\AppData\\Local\\Microsoft\\Windows\\Fonts\\";
- log.info("font璺緞:{}",userfontsfoloder);
+ String[] fonts = {"C:\\Users\\澶уご\\AppData\\Local\\Microsoft\\Windows\\Fonts\\","C:\\Users\\datou\\AppData\\Local\\Microsoft\\Windows\\Fonts\\","/usr/share/fonts"};
List<FontSourceBase> fontSources = new ArrayList(Arrays.asList(FontSettings.getDefaultInstance().getFontsSources()));
- FolderFontSource folderFontSource = new FolderFontSource(userfontsfoloder,true);
- fontSources.add(folderFontSource);
+ for (int i = 0; i < fonts.length; i++) {
+ FolderFontSource folderFontSource = new FolderFontSource(fonts[i],true);
+ fontSources.add(folderFontSource);
+ }
FontSourceBase[] fontSourceBases = fontSources.toArray(new FontSourceBase[fontSources.size()]);
FontSettings.getDefaultInstance().setFontsSources(fontSourceBases);
}
public static void convertPDF(String input){
try {
- //setFont();
+ setFont();
Document pres = null;
- FontSettings.getDefaultInstance().setFontsFolder("C:\\Users\\澶уご\\AppData\\Local\\Microsoft\\Windows\\Fonts", true);
//鎵嬪姩鏇挎崲杈撳嚭pdf鍚嶇О
String output = input.replaceAll(".docx", ".pdf");
long old = System.currentTimeMillis();
@@ -45,7 +48,7 @@
public static void main(String[] args) {
//convertPDF("D:\\娴嬭瘎绯荤粺\\home\\鏋梍PAQ_GS_TH.docx");
- convertPDF("D:\\home\\PAQ绠�鏄撶増銆愭嘲鏂囥��.docx");
+ convertPDF("D:\\娴嬭瘎绯荤粺\\home\\uploadPath\\娴嬭瘯2_PAQ_GS_CN.docx");
}
}
--
Gitblit v1.9.1