linwe
2024-08-09 8b7258c9427882bb1798f1502eaa35184c6e374e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package org.springblade.common.utils;
 
public class WordToPdfUtils {
    // https://srgdjczzxtpt.com:2080/gminio/jczz/upload/20240710/ade086b8d725a08631b62d812a63f6da.docx
 
    public static String wordToPdf(String fileName, String pdfPath) throws Exception {
        // 判断入参是否有空
        if (fileName == null || pdfPath == null) {
            throw new Exception("入参不能为空");
        }
        // 判断文件后缀名是否doc,ppt,xls
        if (fileName.endsWith(".doc") || fileName.endsWith(".docx")) {
            // 获取文件流
            // URL url = new URL(pdfPath);
            // HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            // connection.setRequestProperty("User-Agent", "Mozilla/5.0");
            // // 获取文件名
            // String orFileName = fileName.substring(0, fileName.lastIndexOf("."));
            // InputStream inputStream = connection.getInputStream();
            // long timeMillis = System.currentTimeMillis();
            // // String filePathPdf = "/data/app/jczz/pdf/" + orFileName + "_" + timeMillis + ".pdf";
            // String filePathPdf = "D:\\公司\\" + orFileName + "_" + timeMillis + ".pdf";
            // com.aspose.words.Document doc = new com.aspose.words.Document(inputStream);
            // doc.save(filePathPdf, com.aspose.words.SaveFormat.PDF);
            return "";
        } else {
            throw new Exception("文件格式不正确");
        }
    }
 
    public static void main(String[] args) throws Exception {
        wordToPdf(" 测试.docx", "https://srgdjczzxtpt.com:2080/gminio/jczz/upload/20240710/ade086b8d725a08631b62d812a63f6da.docx");
    }
}