| 123456789101112131415161718192021222324252627 |
- package com.onemap.file.utils;
- import com.spire.doc.*;
- import java.io.*;
- public class PdfUtils {
- /**
- * @param toFilePath 文件夹路径
- * @param fileName 文件名
- * @param type 文件类型
- * @return
- * @throws Exception
- */
- public static String file2pdf(String toFilePath, String fileName, String type) throws Exception {
- String infilepath = toFilePath;
- String outfilepath = infilepath.replace(type,".pdf");
- //实例化Document类的对象
- Document doc = new Document();
- //加载Word
- doc.loadFromFile(infilepath);
- //保存为PDF格式
- doc.saveToFile(outfilepath,FileFormat.PDF);
- return fileName.replace(type,".pdf");
- }
- }
|