派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
src/main/java/com/qxueyou/scc/base/util/docConverterUtil.java
@@ -8,16 +8,16 @@
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
/**
 * 文件转换为pdf的工具类
 * 文件转换为pdf的工具类
 * 
 * @author lyl
 *
 */
public class docConverterUtil {
   @SuppressWarnings("unused")
   private String fileString; // (待转换文件的根路径)
   private String fileString; // (待转换文件的根路径)
   @SuppressWarnings("unused")
   private String outputPath = ""; // pdf输出路径 ,如果不设置就输出在默认的位置
   private String outputPath = ""; // pdf输出路径 ,如果不设置就输出在默认的位置
   @SuppressWarnings("unused")
   private String fileName;
   private File pdfFile;
@@ -28,7 +28,7 @@
   }
   /**
    * 可自定义设置转换文件全路径名
    * 可自定义设置转换文件全路径名
    * 
    * @param fileString
    */
@@ -37,7 +37,7 @@
   }
   /**
    * 初始化
    * 初始化
    * 
    * @param fileString
    */
@@ -47,7 +47,7 @@
   }
   /**
    * 设置输出路径
    * 设置输出路径
    */
   public void setOutputPath(String outputPath) {
      this.outputPath = outputPath;
@@ -64,7 +64,7 @@
   }
   /**
    * תΪPDF
    * 转为PDF
    * 
    * @param file
    */
@@ -73,11 +73,11 @@
      if (docFile.exists()) {
         if (!pdfFile.exists()) {
            String OpenOffice_HOME = "C:\\Program Files (x86)\\OpenOffice 4";
            // 如果从文件中读取的URL地址最后一个字符不是 '\',则添加'\'
            // 如果从文件中读取的URL地址最后一个字符不是 '\',则添加'\'
            if (OpenOffice_HOME.charAt(OpenOffice_HOME.length() - 1) != '\\') {
               OpenOffice_HOME += "\\";
            }
            // 启动OpenOffice的服务
            // 启动OpenOffice的服务
            String command = OpenOffice_HOME
                  + "program\\soffice.exe -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\"";
            Process pro = Runtime.getRuntime().exec(command);
@@ -88,29 +88,29 @@
               DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
               converter.convert(docFile, pdfFile);
               connection.disconnect();
               System.out.println("df转换成功,保存路径:" + pdfFile.getPath());
               System.out.println("df转换成功,保存路径:" + pdfFile.getPath());
            } catch (java.net.ConnectException e) {
               e.printStackTrace();
               System.out.println("转换失败,openoffice服务未启动!");
               System.out.println("转换失败,openoffice服务未启动!");
               throw e;
            } catch (com.artofsolving.jodconverter.openoffice.connection.OpenOfficeException e) {
               e.printStackTrace();
               System.out.println("读取转换文件失败");
               System.out.println("读取转换文件失败");
               throw e;
            } catch (Exception e) {
               e.printStackTrace();
               throw e;
            }
         } else {
            System.out.println("文件已存在,不需要转换");
            System.out.println("文件已存在,不需要转换");
         }
      } else {
         System.out.println("需要转换的文档不存在,无法转换");
         System.out.println("需要转换的文档不存在,无法转换");
      }
   }
   /**
    * 返回pdf文件路径
    * 返回pdf文件路径
    * 
    * @return
    */