| | |
| | | |
| | | import com.alibaba.druid.util.StringUtils; |
| | | import com.product.core.config.Global; |
| | | import com.product.core.exception.BaseException; |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.file.config.FileCode; |
| | | import org.artofsolving.jodconverter.OfficeDocumentConverter; |
| | |
| | | * 初始化转换服务 |
| | | */ |
| | | public static boolean init() { |
| | | if(!Global.getPropertyToBoolean("open.office.isEnable", "true")) {//不启用oepn office转换 |
| | | return true; |
| | | } |
| | | SpringMVCContextHolder.getSystemLogger().info("初始化转换服务->"); |
| | | openOfficeHome = Global.getSystemConfig("open.office.home",""); |
| | | portInfo = Global.getSystemConfig("open.office.port.info",""); |
| | |
| | | * @param output |
| | | * @return |
| | | */ |
| | | public static File convertToPdf(String input, String output) { |
| | | public static File convertToPdf(String input, String output) throws Exception { |
| | | File inputFile = null; |
| | | File outFile = null; |
| | | OfficeManager officeManager = null; |
| | | try { |
| | | SpringMVCContextHolder.getSystemLogger().info("从队列中提取转换端口..."); |
| | | officeManager = officeManagerQueue.take(); |
| | | inputFile = new File(input); |
| | | outFile = new File(output); |
| | | SpringMVCContextHolder.getSystemLogger().info("开始转换文档:" + input + "=>" + output); |
| | | OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager); |
| | | converter.convert(inputFile, outFile); // 转换文档 |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | SpringMVCContextHolder.getSystemLogger().error("转换文档出错" + e); |
| | | }catch (Exception e) { |
| | | outFile = null; |
| | | throw e; |
| | | } finally { |
| | | SpringMVCContextHolder.getSystemLogger().info("结束转换文档"); |
| | | if (officeManager != null) { |