| | |
| | | @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(); |
| | |
| | | |
| | | public static void main(String[] args) { |
| | | //convertPDF("D:\\测评系统\\home\\林_PAQ_GS_TH.docx"); |
| | | convertPDF("D:\\home\\PAQ简易版【泰文】.docx"); |
| | | convertPDF("C:\\Users\\大头\\Desktop\\MAQ组别报告\\测试_MAQTR_IA_EN.docx"); |
| | | } |
| | | |
| | | } |