添加空文件判断
This commit is contained in:
@@ -2,35 +2,47 @@ package com.jero.modules.document.utils;
|
||||
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.MinioUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.text.PDFTextStripper;
|
||||
import org.apache.pdfbox.text.PDFTextStripperByArea;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @description
|
||||
* @date 2022/3/21 17:04
|
||||
* @auth zhn
|
||||
*/
|
||||
@Slf4j
|
||||
public class ReadPdfUtil {
|
||||
|
||||
public static String readPdf(String path) {
|
||||
if(MinioUtil.doesObjectExist(path)){
|
||||
try (InputStream in = MinioUtil.download(path);
|
||||
PDDocument document = PDDocument.load(in)) {
|
||||
document.getClass();
|
||||
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
|
||||
stripper.setSortByPosition(true);
|
||||
PDFTextStripper tStripper = new PDFTextStripper();
|
||||
try (InputStream in = MinioUtil.download(path)) {
|
||||
if(Objects.isNull(in) || in.available() == 0){
|
||||
return null;
|
||||
}
|
||||
try (PDDocument document = PDDocument.load(in)) {
|
||||
document.getClass();
|
||||
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
|
||||
stripper.setSortByPosition(true);
|
||||
PDFTextStripper tStripper = new PDFTextStripper();
|
||||
|
||||
String pdfFileInText = tStripper.getText(document);
|
||||
return pdfFileInText;
|
||||
String pdfFileInText = tStripper.getText(document);
|
||||
return pdfFileInText;
|
||||
|
||||
}catch (IOException e) {
|
||||
throw new JeroBootException("文件内容读取失败");
|
||||
}catch (Exception e) {
|
||||
log.error("文件内容读取失败",e);
|
||||
// throw new JeroBootException("文件内容读取失败");
|
||||
}
|
||||
}catch (Exception e) {
|
||||
log.error("文件内容读取失败",e);
|
||||
// throw new JeroBootException("文件内容读取失败");
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user