分离tl-server和server中接口的非公共方法,将公共方法wordToPdf放到BaseDocumentService中
BaseDocumentService.java中增加doc转docx、xls转xlsx的方法 BaseDocumentService.java中增加convert方法
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
package com.optima.document.api;
|
||||
|
||||
/**
|
||||
* @author yanghuanglin
|
||||
* @since 2022/12/28
|
||||
*/
|
||||
public interface BaseDocumentService {
|
||||
/**
|
||||
* 格式转换,server和tl-server下均实现
|
||||
*
|
||||
* @param sourceData 源文件流,tl-server下仅支持docx格式
|
||||
* @param sourceExtension 源文件后缀名,不包含"."
|
||||
* @param targetExtension 目标文件后缀名,不包含"."
|
||||
* @param targetFormat 目标文件格式
|
||||
* @return 转换后的文件流
|
||||
*/
|
||||
default byte[] convert(byte[] sourceData, String sourceExtension, String targetExtension, String targetFormat) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通word转pdf,server和tl-server下均实现
|
||||
*
|
||||
* @param source 源文件流,tl-server下仅支持docx格式
|
||||
* @param sourceFormat 源文件后缀名,不包含".",tl-server下可忽略
|
||||
* @param clear 是否清除占位符
|
||||
* @return pdf文档流
|
||||
*/
|
||||
default byte[] wordToPdf(byte[] source, String sourceFormat, boolean clear) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* doc转为docx,server和tl-server下均实现
|
||||
*
|
||||
* @param docData doc文档流
|
||||
* @return docx文档流
|
||||
*/
|
||||
default byte[] docToDocx(byte[] docData) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* xls转为xlsx,server和tl-server下均实现
|
||||
*
|
||||
* @param xlsData xls文档流
|
||||
* @return xlsx文档流
|
||||
*/
|
||||
default byte[] xlsToXlsx(byte[] xlsData) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -1,71 +1,44 @@
|
||||
package com.optima.document.api;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文档接口
|
||||
* @author Elias
|
||||
* @date 2021-09-28 16:00
|
||||
* 文档接口,此类中用的poi2生成word文档,使用docto进行格式转换
|
||||
*
|
||||
* @author yanghuanglin
|
||||
* @since 2022/12/28
|
||||
*/
|
||||
public interface DocumentService {
|
||||
public interface DocumentService extends BaseDocumentService {
|
||||
/**
|
||||
* generate word
|
||||
* @param templateData word模版流
|
||||
* @param dataModel 数据模型
|
||||
* @return 修改后的文档流
|
||||
* 通过调用poi生成word,仅tl-server模块下实现,仅支持docx格式
|
||||
*
|
||||
* @param templateData word模版流,仅支持docx格式
|
||||
* @param dataModel 数据模型
|
||||
* @return word文档流
|
||||
*/
|
||||
default byte[] generateWord(byte[] templateData, Map<String, Object> dataModel) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* word to pdf
|
||||
* @param templateData word模版流
|
||||
* @param clear 是否清除占位符
|
||||
* @return
|
||||
* 通过调用poi将word转pdf,仅tl-server模块下实现,仅支持docx格式
|
||||
*
|
||||
* @param templateData word模版流,仅支持docx格式
|
||||
* @param clear 是否清除占位符
|
||||
* @return pdf文档流
|
||||
*/
|
||||
default byte[] wordToPdf(byte[] templateData, boolean clear) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* word to image
|
||||
* @param templateData word模版流
|
||||
* @param targetFormat 目标格式 支持jpeg, jpg, gif, tiff or png
|
||||
* @return
|
||||
*/
|
||||
default byte[] wordToImage(byte[] templateData, String targetFormat) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* word转图片,仅支持docx格式
|
||||
*
|
||||
* @param source 文档
|
||||
* @param toFindText 需要替换的文本
|
||||
* @param imgSource 图片
|
||||
* @param width 宽度
|
||||
* @param height 高度
|
||||
* @return 修改后的文档
|
||||
* @param source word文件流,仅支持docx格式
|
||||
* @param targetExtension 目标格式 支持jpeg, jpg, gif, tiff or png
|
||||
* @return 图片流
|
||||
*/
|
||||
default byte[] insertJpeg(byte[] source, String toFindText, byte[] imgSource, int width, int height){
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param source
|
||||
* @param toFindText
|
||||
* @param imgSource
|
||||
* @param width
|
||||
* @param height
|
||||
* @return
|
||||
*/
|
||||
default byte[] insertJpeg(byte[] source, String toFindText, List<byte[]> imgSource, int width, int height) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
default byte[] fieldToWord(byte[] source, Map<String, Object> infoMap) {
|
||||
default byte[] wordToImage(byte[] source, String targetExtension) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.optima.document.api;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 文档接口,此类中用的jacob生成word文档,插入图片等,使用openoffice进行格式转换
|
||||
*
|
||||
* @author Elias
|
||||
* @since 2021-09-28 16:00
|
||||
*/
|
||||
public interface LegacyDocumentService extends BaseDocumentService {
|
||||
/**
|
||||
* 通过pdfbox将word转图片,仅server模块下实现
|
||||
*
|
||||
* @param templateData word模版流
|
||||
* @param sourceExtension 源文件后缀名,不包含"."
|
||||
* @param targetExtension 目标格式 支持jpeg, jpg, gif, tiff or png
|
||||
* @return 图片流
|
||||
*/
|
||||
default byte[] wordToImage(byte[] templateData, String sourceExtension, String targetExtension) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过jacob向文档中插入图片,仅server模块下实现
|
||||
*
|
||||
* @param source 文档流
|
||||
* @param toFindText 需要替换的文本
|
||||
* @param imgSource 图片流
|
||||
* @param width 宽度
|
||||
* @param height 高度
|
||||
* @return word文档流
|
||||
*/
|
||||
default byte[] insertJpeg(byte[] source, String toFindText, byte[] imgSource, int width, int height) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过jacob向文档中插入多张图片,仅server模块下实现
|
||||
*
|
||||
* @param source 文档流
|
||||
* @param toFindText 需要替换的文本
|
||||
* @param imgSource 图片流列表
|
||||
* @param width 宽度
|
||||
* @param height 高度
|
||||
* @return word文档流
|
||||
*/
|
||||
default byte[] insertJpeg(byte[] source, String toFindText, List<byte[]> imgSource, int width, int height) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过jacob向word填充属性字段,仅server模块下实现
|
||||
*
|
||||
* @param source 文档流
|
||||
* @param infoMap 字段集合,${key}为占位字符,value为对应替换内容
|
||||
* @return word文档流
|
||||
*/
|
||||
default byte[] fieldToWord(byte[] source, Map<String, Object> infoMap) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,17 @@ import com.artofsolving.jodconverter.DocumentConverter;
|
||||
import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;
|
||||
import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;
|
||||
import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;
|
||||
import com.optima.document.api.DocumentService;
|
||||
import com.optima.document.api.LegacyDocumentService;
|
||||
import com.optima.document.server.config.DocumentConfig;
|
||||
import com.optima.document.server.utils.DocToPdfUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.rendering.ImageType;
|
||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||
import org.apache.pdfbox.tools.imageio.ImageIOUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -21,11 +24,44 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 服务接口实现
|
||||
*
|
||||
* @author Elias
|
||||
* @date 2021-09-28 16:18
|
||||
* @since 2021-09-28 16:18
|
||||
*/
|
||||
@Slf4j
|
||||
public class DocumentServiceImpl implements DocumentService {
|
||||
@Service
|
||||
public class LegacyDocumentServiceImpl implements LegacyDocumentService {
|
||||
@Resource
|
||||
private DocumentConfig documentConfig;
|
||||
|
||||
/**
|
||||
* 文件格式转换
|
||||
*
|
||||
* @param source 源文件流
|
||||
* @param sourceExtension 源文件后缀名,不包含"."
|
||||
* @param targetExtension 目标文件后缀名
|
||||
* @return 转换后的文件流
|
||||
*/
|
||||
private byte[] convert(byte[] source, String sourceExtension, String targetExtension) {
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
String command = "%s -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard";
|
||||
Process p = Runtime.getRuntime().exec(String.format(command, documentConfig.getOpenOfficeHome()));
|
||||
OpenOfficeConnection connection = new SocketOpenOfficeConnection();
|
||||
connection.connect();
|
||||
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DefaultDocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry();
|
||||
converter.convert(new ByteArrayInputStream(source), formatRegistry.getFormatByFileExtension(sourceExtension), bos, formatRegistry.getFormatByFileExtension(targetExtension));
|
||||
connection.disconnect();
|
||||
p.destroy();
|
||||
log.info("{} to {} take {} milliseconds", sourceExtension, targetExtension, System.currentTimeMillis() - start);
|
||||
return bos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] fieldToWord(byte[] source, Map<String, Object> infoMap) {
|
||||
return DocToPdfUtil.fieldToWord(source, infoMap);
|
||||
@@ -39,39 +75,31 @@ public class DocumentServiceImpl implements DocumentService {
|
||||
return DocToPdfUtil.insertJpeg(source, toFindText, imgSource, width, height);
|
||||
}
|
||||
|
||||
public byte[] wordToPdf(byte[] source, String sourceFormat, boolean clear) {
|
||||
public byte[] wordToPdf(byte[] source, String sourceExtension, boolean clear) {
|
||||
try {
|
||||
if (clear) {
|
||||
source = DocToPdfUtil.clearPlaceholder(source);
|
||||
}
|
||||
long t1 = System.currentTimeMillis();
|
||||
String command = "D:\\OpenOffice4\\program\\soffice.exe -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard";
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
OpenOfficeConnection connection = new SocketOpenOfficeConnection();
|
||||
connection.connect();
|
||||
DocumentConverter converter = new OpenOfficeDocumentConverter(connection);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DefaultDocumentFormatRegistry formatRegistry = new DefaultDocumentFormatRegistry();
|
||||
converter.convert(new ByteArrayInputStream(source), formatRegistry.getFormatByFileExtension(sourceFormat), bos, formatRegistry.getFormatByFileExtension("pdf"));
|
||||
connection.disconnect();
|
||||
p.destroy();
|
||||
log.info("word to pdf=======consuming:{} milliseconds", System.currentTimeMillis() - t1);
|
||||
return bos.toByteArray();
|
||||
return convert(source, sourceExtension, "pdf");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] wordToImage(byte[] source, String sourceFormat, String targetFormat) {
|
||||
public byte[] convert(byte[] sourceData, String sourceExtension, String targetExtension, String targetFormat) {
|
||||
return convert(sourceData, sourceExtension, targetExtension);
|
||||
}
|
||||
|
||||
public byte[] wordToImage(byte[] source, String sourceExtension, String targetExtension) {
|
||||
try {
|
||||
byte[] pdfBytes = wordToPdf(source, sourceFormat, true);
|
||||
byte[] pdfBytes = wordToPdf(source, sourceExtension, true);
|
||||
PDDocument document = PDDocument.load(new ByteArrayInputStream(pdfBytes));
|
||||
PDFRenderer pdfRenderer = new PDFRenderer(document);
|
||||
BufferedImage bim = pdfRenderer.renderImageWithDPI(
|
||||
0, 300, ImageType.RGB);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ImageIOUtil.writeImage(bim, targetFormat, bos, 300);
|
||||
ImageIOUtil.writeImage(bim, targetExtension, bos, 300);
|
||||
document.close();
|
||||
return bos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
@@ -79,4 +107,12 @@ public class DocumentServiceImpl implements DocumentService {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] docToDocx(byte[] docData) {
|
||||
return convert(docData, "doc", "docx");
|
||||
}
|
||||
|
||||
public byte[] xlsToXlsx(byte[] xlsData) {
|
||||
return convert(xlsData, "xls", "xlsx");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.optima.document.server.config;
|
||||
|
||||
import com.optima.document.api.DocumentService;
|
||||
import com.optima.document.server.api.DocumentServiceImpl;
|
||||
import com.optima.document.api.LegacyDocumentService;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -10,9 +9,11 @@ import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
|
||||
|
||||
/**
|
||||
* 服务端配置
|
||||
*
|
||||
* @author Elias
|
||||
* @date 2021-09-28 16:12
|
||||
* @since 2021-09-28 16:12
|
||||
*/
|
||||
@SuppressWarnings("VulnerableCodeUsages")
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "document")
|
||||
@Data
|
||||
@@ -24,13 +25,14 @@ public class DocumentConfig {
|
||||
|
||||
/**
|
||||
* 文档接口
|
||||
*
|
||||
* @return httpinvoker
|
||||
*/
|
||||
@Bean(name = "/document-service")
|
||||
HttpInvokerServiceExporter wordService() {
|
||||
HttpInvokerServiceExporter wordService(LegacyDocumentService legacyDocumentService) {
|
||||
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
|
||||
exporter.setService( new DocumentServiceImpl() );
|
||||
exporter.setServiceInterface(DocumentService.class);
|
||||
exporter.setService(legacyDocumentService);
|
||||
exporter.setServiceInterface(LegacyDocumentService.class);
|
||||
return exporter;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
server:
|
||||
port: 8090
|
||||
document:
|
||||
doc-to-program: D:\\optima\\docto.exe
|
||||
open-office-home: D:\\OpenOffice4\\program\\soffice.exe
|
||||
|
||||
|
||||
@@ -13,30 +13,33 @@ import com.deepoove.poi.xwpf.BodyContainerFactory;
|
||||
import com.optima.document.api.DocumentService;
|
||||
import com.optima.document.tl.server.config.DocumentConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.rendering.ImageType;
|
||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||
import org.apache.pdfbox.tools.imageio.ImageIOUtil;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 服务接口实现
|
||||
*
|
||||
* @author Elias
|
||||
* @date 2021-09-28 16:18
|
||||
* @since 2021-09-28 16:18
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@Service
|
||||
public class DocumentServiceImpl implements DocumentService {
|
||||
|
||||
/**
|
||||
@@ -83,11 +86,48 @@ public class DocumentServiceImpl implements DocumentService {
|
||||
@Resource
|
||||
private DocumentConfig documentConfig;
|
||||
|
||||
@Override
|
||||
public byte[] convert(byte[] sourceData, String sourceExtension, String targetExtension, String targetFormat) {
|
||||
try {
|
||||
if (!sourceExtension.contains("."))
|
||||
sourceExtension = "." + sourceExtension;
|
||||
if (!targetExtension.contains("."))
|
||||
targetExtension = "." + targetExtension;
|
||||
Path sourcePath = Files.createTempFile(UUID.randomUUID().toString(), sourceExtension);
|
||||
Path targetPath = Files.createTempFile(UUID.randomUUID().toString(), targetExtension);
|
||||
Files.write(sourcePath, sourceData);
|
||||
try {
|
||||
long begin = System.currentTimeMillis();
|
||||
String command;
|
||||
if (sourceExtension.contains("xls")) {
|
||||
command = "%s -XL -f %s -O %s -T %s";
|
||||
} else if (sourceExtension.contains("ppt")) {
|
||||
command = "%s -PP -f %s -O %s -T %s";
|
||||
} else {
|
||||
command = "%s -WD -f %s -O %s -T %s";
|
||||
}
|
||||
command = String.format(command, documentConfig.getDocToProgram(), sourcePath, targetPath, targetFormat);
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
p.waitFor();
|
||||
long end = System.currentTimeMillis();
|
||||
log.info("docto {} to {} take time in millis:{}", sourceExtension, targetExtension, (end - begin));
|
||||
return Files.readAllBytes(targetPath);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
Files.delete(sourcePath);
|
||||
Files.delete(targetPath);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("docto convert error", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] generateWord(byte[] templateData, Map<String, Object> dataModel) {
|
||||
long start = System.currentTimeMillis();
|
||||
XWPFTemplate template = XWPFTemplate.compile(new ByteArrayInputStream(templateData), wtlConfig).render(dataModel);
|
||||
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()){
|
||||
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
|
||||
template.write(bos);
|
||||
log.info("word generate========consuming:{} milliseconds", System.currentTimeMillis() - start);
|
||||
return bos.toByteArray();
|
||||
@@ -97,7 +137,10 @@ public class DocumentServiceImpl implements DocumentService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] wordToPdf(byte[] source, String sourceFormat, boolean clear) {
|
||||
return wordToPdf(source, clear);
|
||||
}
|
||||
|
||||
public byte[] wordToPdf(byte[] source, boolean clear) {
|
||||
try {
|
||||
long start = System.currentTimeMillis();
|
||||
@@ -119,52 +162,36 @@ public class DocumentServiceImpl implements DocumentService {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Path tempFilePath = Files.createTempFile(UUID.randomUUID().toString(), ".docx");
|
||||
Files.write(tempFilePath, source);
|
||||
|
||||
Path pdfPath = Files.createTempFile(UUID.randomUUID().toString(), ".pdf");
|
||||
|
||||
try {
|
||||
long begin = System.currentTimeMillis();
|
||||
String command = "%s -f %s -O %s -T wdFormatPDF";
|
||||
command = String.format(command, documentConfig.getDocToProgram(), tempFilePath, pdfPath);
|
||||
Process p = Runtime.getRuntime().exec(command);
|
||||
p.waitFor();
|
||||
long end = System.currentTimeMillis();
|
||||
log.info("docto take time in millis:" + (end - begin));
|
||||
return Files.readAllBytes(pdfPath);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
Files.delete(tempFilePath);
|
||||
Files.delete(pdfPath);
|
||||
}
|
||||
return convert(source, "docx", "pdf", "wdFormatPDF");
|
||||
} catch (Exception e) {
|
||||
log.error("word to pdf error", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] wordToImage(byte[] source, String targetFormat) {
|
||||
public byte[] wordToImage(byte[] source, String targetExtension) {
|
||||
try {
|
||||
byte[] pdfBytes = wordToPdf(source, true);
|
||||
long start = System.currentTimeMillis();
|
||||
PDDocument document = PDDocument.load(new ByteArrayInputStream(pdfBytes));
|
||||
PDFRenderer pdfRenderer = new PDFRenderer(document);
|
||||
BufferedImage bim = pdfRenderer.renderImageWithDPI(
|
||||
0, 300, ImageType.RGB);
|
||||
BufferedImage bim = pdfRenderer.renderImageWithDPI(0, 300, ImageType.RGB);
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
ImageIOUtil.writeImage(bim, targetFormat, bos, 300);
|
||||
ImageIOUtil.writeImage(bim, targetExtension, bos, 300);
|
||||
document.close();
|
||||
log.info("word to image=======consuming:{} milliseconds", System.currentTimeMillis() - start);
|
||||
|
||||
return bos.toByteArray();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("word to image error", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte[] docToDocx(byte[] docData) {
|
||||
return convert(docData, "doc", "docx", "wdFormatDocumentDefault");
|
||||
}
|
||||
|
||||
public byte[] xlsToXlsx(byte[] xlsData) {
|
||||
return convert(xlsData, "xls", "xlsx", "xlWorkbookDefault");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,19 @@
|
||||
package com.optima.document.tl.server.config;
|
||||
|
||||
import com.optima.document.api.DocumentService;
|
||||
import com.optima.document.tl.server.api.DocumentServiceImpl;
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.Socket;
|
||||
|
||||
/**
|
||||
* 服务端配置
|
||||
*
|
||||
* @author Elias
|
||||
* @date 2021-09-28 16:12
|
||||
* @since 2021-09-28 16:12
|
||||
*/
|
||||
@SuppressWarnings("VulnerableCodeUsages")
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "document")
|
||||
@Data
|
||||
@@ -28,12 +23,13 @@ public class DocumentConfig {
|
||||
|
||||
/**
|
||||
* 文档接口
|
||||
*
|
||||
* @return httpinvoker
|
||||
*/
|
||||
@Bean(name = "/document-service")
|
||||
HttpInvokerServiceExporter wordService(DocumentService documentService) {
|
||||
HttpInvokerServiceExporter exporter = new HttpInvokerServiceExporter();
|
||||
exporter.setService( documentService );
|
||||
exporter.setService(documentService);
|
||||
exporter.setServiceInterface(DocumentService.class);
|
||||
return exporter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user