重写代码
This commit is contained in:
parent
7450f41a9d
commit
53e61b11d4
|
|
@ -10,7 +10,7 @@ import java.io.InputStream;
|
|||
public class ExcelParse extends FileParse {
|
||||
|
||||
@Override
|
||||
public String parseContent(InputStream stream, String fileType) {
|
||||
public String parseAllText(InputStream stream, String fileType) {
|
||||
String fileTmpPath = createFileTmpPath(fileType);
|
||||
String res = "";
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public abstract class FileParse {
|
|||
|
||||
private static String tmpPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
|
||||
|
||||
public abstract String parseContent(InputStream stream, String fileType);
|
||||
public abstract String parseAllText(InputStream stream, String fileType);
|
||||
|
||||
protected String createFileTmpPath(String fileType) {
|
||||
String uuid = IdUtil.fastSimpleUUID();
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import java.io.InputStream;
|
|||
@Slf4j
|
||||
public class PdfParse extends FileParse {
|
||||
@Override
|
||||
public String parseContent(InputStream stream, String fileType) {
|
||||
public String parseAllText(InputStream stream, String fileType) {
|
||||
String res = "";
|
||||
String fileTmpPath = createFileTmpPath(fileType);
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -10,15 +10,15 @@ import java.io.InputStream;
|
|||
public class PptParse extends FileParse {
|
||||
|
||||
@Override
|
||||
public String parseContent(InputStream stream, String fileType) {
|
||||
public String parseAllText(InputStream stream, String fileType) {
|
||||
String fileTmpPath = createFileTmpPath(fileType);
|
||||
String res = "";
|
||||
try {
|
||||
FileUtil.writeFromStream(stream, fileTmpPath);
|
||||
if (fileType.endsWith("pptx")) {
|
||||
return OfficeFileUtil.parsePptxAllText(fileTmpPath);
|
||||
res = OfficeFileUtil.parsePptxAllText(fileTmpPath);
|
||||
}
|
||||
return OfficeFileUtil.parsePptAllText(fileTmpPath);
|
||||
res = OfficeFileUtil.parsePptAllText(fileTmpPath);
|
||||
} catch (Exception e) {
|
||||
log.error("解析{}格式的ppt错误,具体为{}",fileType, e.getMessage(), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import java.nio.charset.Charset;
|
|||
public class TextParse extends FileParse {
|
||||
|
||||
@Override
|
||||
public String parseContent(InputStream stream, String fileType) {
|
||||
public String parseAllText(InputStream stream, String fileType) {
|
||||
String fileTmpPath = createFileTmpPath(fileType);
|
||||
String res = "";
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import java.io.InputStream;
|
|||
public class WordParse extends FileParse {
|
||||
|
||||
@Override
|
||||
public String parseContent(InputStream stream, String fileType) {
|
||||
public String parseAllText(InputStream stream, String fileType) {
|
||||
String fileTmpPath = createFileTmpPath(fileType);
|
||||
String res = "";
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public final class EleCommonUtil {
|
|||
public static String parse(InputStream inputStream, String fileType) {
|
||||
|
||||
FileParse fileParse = PARSE_MAP.getOrDefault(fileType, new TextParse());
|
||||
return fileParse.parseContent(inputStream, fileType);
|
||||
return fileParse.parseAllText(inputStream, fileType);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,21 +33,20 @@ import java.util.Objects;
|
|||
@Slf4j
|
||||
public class OfficeFileUtil {
|
||||
|
||||
private static final IConverter CONVERT = LocalConverter.builder().build();
|
||||
|
||||
public static void doc2pdf(String wordPath, String pdfPath) {
|
||||
if (EleCommonUtil.isWinOs()) {
|
||||
File inputWord = new File(wordPath);
|
||||
File outputFile = new File(pdfPath);
|
||||
try(InputStream docxInputStream = Files.newInputStream(inputWord.toPath());
|
||||
OutputStream outputStream = Files.newOutputStream(outputFile.toPath())) {
|
||||
boolean execute = CONVERT.convert(docxInputStream)
|
||||
IConverter build = LocalConverter.builder().build();
|
||||
boolean execute = build.convert(docxInputStream)
|
||||
.as(DocumentType.DOCX)
|
||||
.to(outputStream)
|
||||
.as(DocumentType.PDF).schedule().get();
|
||||
Assert.isTrue(execute, "转换失败");
|
||||
log.info("转换完毕 targetPath = {}", outputFile.getAbsolutePath());
|
||||
CONVERT.shutDown();
|
||||
build.shutDown();
|
||||
} catch (Exception e) {
|
||||
log.error("[documents4J] word转pdf失败:{}", e.toString());
|
||||
String info = StrFormatter.format("word文档{}转换成pdf文档{}失败", wordPath, pdfPath);
|
||||
|
|
|
|||
Loading…
Reference in New Issue