|
|
|
@ -345,8 +345,8 @@ public class SysOssServiceImpl extends ServiceImpl<SysOssDao, SysOssEntity> impl |
|
|
|
if ("xlsx".equalsIgnoreCase(fileExtension) || "xls".equalsIgnoreCase(fileExtension)) { |
|
|
|
// 如果是 Excel 文件,将其转换为 PDF |
|
|
|
convertExcelToPdf(file); |
|
|
|
} else if ("docx".equalsIgnoreCase(fileExtension)) { |
|
|
|
// 如果是 Word 文件,将其转换为 PDF |
|
|
|
} else if ("docx".equalsIgnoreCase(fileExtension) || "doc".equalsIgnoreCase(fileExtension)) { |
|
|
|
// 如果是 Word 文件(doc/docx),将其转换为 PDF |
|
|
|
convertWordToPdf(file); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -440,12 +440,13 @@ public class SysOssServiceImpl extends ServiceImpl<SysOssDao, SysOssEntity> impl |
|
|
|
System.out.println("Excel 文件转换为 PDF 成功,保存路径:" + pdfPath); |
|
|
|
} |
|
|
|
|
|
|
|
// 将 Word 文件转换为 PDF |
|
|
|
// 将 Word 文件转换为 PDF(支持 doc 和 docx) |
|
|
|
public static void convertWordToPdf(File file) throws Exception { |
|
|
|
Document document = new Document(file.getAbsolutePath()); |
|
|
|
|
|
|
|
// 转换为 PDF |
|
|
|
String pdfPath = file.getAbsolutePath().replace(".docx", ".pdf"); |
|
|
|
// 兼容 .doc 和 .docx,统一替换扩展名为 .pdf |
|
|
|
String absPath = file.getAbsolutePath(); |
|
|
|
String pdfPath = absPath.substring(0, absPath.lastIndexOf('.')) + ".pdf"; |
|
|
|
document.save(pdfPath); |
|
|
|
System.out.println("Word 文件转换为 PDF 成功,保存路径:" + pdfPath); |
|
|
|
} |
|
|
|
|