| | |
| | | package com.ots.project.tool; |
| | | import com.ots.common.utils.spring.SpringUtils; |
| | | import com.ots.common.utils.text.CharsetKit; |
| | | import com.ots.project.tool.libreoffice.Office2PDFUtils; |
| | | 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; |
| | | |
| | | @Autowired |
| | | private Office2PDFUtils office2PDFUtils; |
| | | |
| | | private static ShellTool shellTool; |
| | | |
| | | @PostConstruct |
| | | public void init(){ |
| | | shellTool = this; |
| | | //shellTool.documentConverter = documentConverter; |
| | | shellTool.office2PDFUtils = office2PDFUtils; |
| | | } |
| | | |
| | | 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(); |
| | | shellTool.office2PDFUtils.office2Pdf(sourcePath,targetPath); |
| | | } |
| | | |
| | | private static String exec(String command) { |
| | | String returnString = ""; |
| | | Runtime runTime = Runtime.getRuntime(); |
| | |
| | | return returnString; |
| | | } |
| | | public static void main(String[] args) { |
| | | System.out.println(exec("soffice.exe --headless --invisible --convert-to D:/ots/uploadPath/upload/2021/02/28/01e01cf7e372ba8b1c5d24b8d69a46f8.docx 01e01cf7e372ba8b1c5d24b8d69a46f8.pdf ")); |
| | | //System.out.println(exec("soffice.exe --headless --invisible --convert-to D:/ots/uploadPath/upload/2021/02/28/01e01cf7e372ba8b1c5d24b8d69a46f8.docx 01e01cf7e372ba8b1c5d24b8d69a46f8.pdf ")); |
| | | } |
| | | } |