| | |
| | | package com.ots.project.tool; |
| | | import com.ots.common.utils.spring.SpringUtils; |
| | | import com.ots.common.utils.text.CharsetKit; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jodconverter.core.DocumentConverter; |
| | | import org.jodconverter.core.office.OfficeException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.io.*; |
| | | import java.util.concurrent.ScheduledExecutorService; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class ShellTool { |
| | | |
| | | |
| | | @Autowired |
| | | private DocumentConverter documentConverter; |
| | | private static ShellTool shellTool; |
| | | |
| | | @PostConstruct |
| | | public void init(){ |
| | | shellTool = this; |
| | | shellTool.documentConverter = documentConverter; |
| | | } |
| | | |
| | | public static ShellTool builder(){ |
| | | return shellTool; |
| | | } |
| | | |
| | | |
| | | public static String execLibreofficeCommand(String type, String sourcePath, String targetPath) { |
| | | String os = System.getProperty("os.name"); |
| | | StringBuilder builder = new StringBuilder(); |
| | |
| | | file.delete(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | log.info("执行命令:{}",builder.toString()); |
| | | return exec(builder.toString()); |
| | | } |
| | | |
| | | public static void execNewLibreofficeCommand(String type, String sourcePath, String targetPath) throws OfficeException { |
| | | //使用文件方式转换成PDF |
| | | shellTool.documentConverter.convert(new File(sourcePath)).to(new File(targetPath)).execute(); |
| | | } |
| | | |
| | | private static String exec(String command) { |
| | | String returnString = ""; |
| | | Runtime runTime = Runtime.getRuntime(); |