feat: There is no way the,
This commit is contained in:
+68
-62
@@ -2971,42 +2971,45 @@ public class SarStandardsInfoServiceImpl extends ServiceImpl<SarStandardsInfoDao
|
|||||||
String readFilePath = filePath + "/" + attFileEO.getFilePath() + attFileEO.getFileName();
|
String readFilePath = filePath + "/" + attFileEO.getFilePath() + attFileEO.getFileName();
|
||||||
// String readFilePath = "E:\\上汽企标流程总览.pdf";
|
// String readFilePath = "E:\\上汽企标流程总览.pdf";
|
||||||
try {
|
try {
|
||||||
// 判断文件是docx还是PDF
|
File existsFile = new File(readFilePath);
|
||||||
if (null != attFileEO.getFileSuffix() && (attFileEO.getFileSuffix().equals("docx") || attFileEO.getFileSuffix().equals("doc") || attFileEO.getFileSuffix().equals("DOC") || attFileEO.getFileSuffix().equals("DOCX") || attFileEO.getFileSuffix().equals("ppt") || attFileEO.getFileSuffix().equals("pptx"))) {
|
if(existsFile.exists()){
|
||||||
if (attFileEO.getFileSuffix().equals("doc") || attFileEO.getFileSuffix().equals("docx") || attFileEO.getFileSuffix().equals("DOC") || attFileEO.getFileSuffix().equals("DOCX")) {
|
// 判断文件是docx还是PDF
|
||||||
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(readFilePath)));
|
if (null != attFileEO.getFileSuffix() && (attFileEO.getFileSuffix().equals("docx") || attFileEO.getFileSuffix().equals("doc") || attFileEO.getFileSuffix().equals("DOC") || attFileEO.getFileSuffix().equals("DOCX") || attFileEO.getFileSuffix().equals("ppt") || attFileEO.getFileSuffix().equals("pptx"))) {
|
||||||
if (FileMagic.valueOf(bis) == FileMagic.OOXML) {
|
if (attFileEO.getFileSuffix().equals("doc") || attFileEO.getFileSuffix().equals("docx") || attFileEO.getFileSuffix().equals("DOC") || attFileEO.getFileSuffix().equals("DOCX")) {
|
||||||
XWPFDocument doc = new XWPFDocument(bis);
|
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(readFilePath)));
|
||||||
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
|
if (FileMagic.valueOf(bis) == FileMagic.OOXML) {
|
||||||
|
XWPFDocument doc = new XWPFDocument(bis);
|
||||||
|
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
|
||||||
|
String txt = extractor.getText();
|
||||||
|
content.append(txt);
|
||||||
|
extractor.close();
|
||||||
|
}else {
|
||||||
|
WordExtractor wordExtractor = new WordExtractor(bis);
|
||||||
|
String txt = wordExtractor.getText();
|
||||||
|
content.append(txt);
|
||||||
|
wordExtractor.close();
|
||||||
|
}
|
||||||
|
bis.close();
|
||||||
|
} else {
|
||||||
|
OPCPackage opcPackage = XWPFDocument.openPackage(readFilePath);
|
||||||
|
XWPFWordExtractor extractor = new XWPFWordExtractor(opcPackage);
|
||||||
String txt = extractor.getText();
|
String txt = extractor.getText();
|
||||||
content.append(txt);
|
content.append(txt);
|
||||||
extractor.close();
|
opcPackage.close();
|
||||||
}else {
|
|
||||||
WordExtractor wordExtractor = new WordExtractor(bis);
|
|
||||||
String txt = wordExtractor.getText();
|
|
||||||
content.append(txt);
|
|
||||||
wordExtractor.close();
|
|
||||||
}
|
}
|
||||||
bis.close();
|
|
||||||
} else {
|
} else {
|
||||||
OPCPackage opcPackage = XWPFDocument.openPackage(readFilePath);
|
PDDocument document = PDDocument.load(new File(readFilePath));
|
||||||
XWPFWordExtractor extractor = new XWPFWordExtractor(opcPackage);
|
document.getClass();
|
||||||
String txt = extractor.getText();
|
if (!document.isEncrypted()) {
|
||||||
content.append(txt);
|
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
|
||||||
opcPackage.close();
|
stripper.setSortByPosition(true);
|
||||||
|
PDFTextStripper tStripper = new PDFTextStripper();
|
||||||
|
String pdfFileInText = tStripper.getText(document);
|
||||||
|
// String[] lines = pdfFileInText.split("\\r?\\n");
|
||||||
|
content.append(pdfFileInText);
|
||||||
|
}
|
||||||
|
document.close();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
PDDocument document = PDDocument.load(new File(readFilePath));
|
|
||||||
document.getClass();
|
|
||||||
if (!document.isEncrypted()) {
|
|
||||||
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
|
|
||||||
stripper.setSortByPosition(true);
|
|
||||||
PDFTextStripper tStripper = new PDFTextStripper();
|
|
||||||
String pdfFileInText = tStripper.getText(document);
|
|
||||||
// String[] lines = pdfFileInText.split("\\r?\\n");
|
|
||||||
content.append(pdfFileInText);
|
|
||||||
}
|
|
||||||
document.close();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("搜索中心新增数据读取文档内容时失败");
|
logger.error("搜索中心新增数据读取文档内容时失败");
|
||||||
@@ -3044,42 +3047,45 @@ public class SarStandardsInfoServiceImpl extends ServiceImpl<SarStandardsInfoDao
|
|||||||
}
|
}
|
||||||
String readFilePath = filePath + "/" + attFileEO.getFilePath() + attFileEO.getFileName();
|
String readFilePath = filePath + "/" + attFileEO.getFilePath() + attFileEO.getFileName();
|
||||||
try {
|
try {
|
||||||
// 判断文件是docx还是PDF
|
File existsFile = new File(readFilePath);
|
||||||
if (null != attFileEO.getFileSuffix() && (attFileEO.getFileSuffix().equals("docx") || attFileEO.getFileSuffix().equals("doc") || attFileEO.getFileSuffix().equals("DOC") || attFileEO.getFileSuffix().equals("DOCX") || attFileEO.getFileSuffix().equals("ppt") || attFileEO.getFileSuffix().equals("pptx"))) {
|
if(existsFile.exists()){
|
||||||
if (attFileEO.getFileSuffix().equals("doc") || attFileEO.getFileSuffix().equals("docx") || attFileEO.getFileSuffix().equals("DOC") || attFileEO.getFileSuffix().equals("DOCX")) {
|
// 判断文件是docx还是PDF
|
||||||
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(readFilePath)));
|
if (null != attFileEO.getFileSuffix() && (attFileEO.getFileSuffix().equals("docx") || attFileEO.getFileSuffix().equals("doc") || attFileEO.getFileSuffix().equals("DOC") || attFileEO.getFileSuffix().equals("DOCX") || attFileEO.getFileSuffix().equals("ppt") || attFileEO.getFileSuffix().equals("pptx"))) {
|
||||||
if (FileMagic.valueOf(bis) == FileMagic.OOXML) {
|
if (attFileEO.getFileSuffix().equals("doc") || attFileEO.getFileSuffix().equals("docx") || attFileEO.getFileSuffix().equals("DOC") || attFileEO.getFileSuffix().equals("DOCX")) {
|
||||||
XWPFDocument doc = new XWPFDocument(bis);
|
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File(readFilePath)));
|
||||||
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
|
if (FileMagic.valueOf(bis) == FileMagic.OOXML) {
|
||||||
|
XWPFDocument doc = new XWPFDocument(bis);
|
||||||
|
XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
|
||||||
|
String txt = extractor.getText();
|
||||||
|
content.append(txt);
|
||||||
|
extractor.close();
|
||||||
|
}else {
|
||||||
|
WordExtractor wordExtractor = new WordExtractor(bis);
|
||||||
|
String txt = wordExtractor.getText();
|
||||||
|
content.append(txt);
|
||||||
|
wordExtractor.close();
|
||||||
|
}
|
||||||
|
bis.close();
|
||||||
|
} else {
|
||||||
|
OPCPackage opcPackage = XWPFDocument.openPackage(readFilePath);
|
||||||
|
XWPFWordExtractor extractor = new XWPFWordExtractor(opcPackage);
|
||||||
String txt = extractor.getText();
|
String txt = extractor.getText();
|
||||||
content.append(txt);
|
content.append(txt);
|
||||||
extractor.close();
|
opcPackage.close();
|
||||||
}else {
|
|
||||||
WordExtractor wordExtractor = new WordExtractor(bis);
|
|
||||||
String txt = wordExtractor.getText();
|
|
||||||
content.append(txt);
|
|
||||||
wordExtractor.close();
|
|
||||||
}
|
}
|
||||||
bis.close();
|
|
||||||
} else {
|
} else {
|
||||||
OPCPackage opcPackage = XWPFDocument.openPackage(readFilePath);
|
PDDocument document = PDDocument.load(new File(readFilePath));
|
||||||
XWPFWordExtractor extractor = new XWPFWordExtractor(opcPackage);
|
document.getClass();
|
||||||
String txt = extractor.getText();
|
if (!document.isEncrypted()) {
|
||||||
content.append(txt);
|
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
|
||||||
opcPackage.close();
|
stripper.setSortByPosition(true);
|
||||||
|
PDFTextStripper tStripper = new PDFTextStripper();
|
||||||
|
String pdfFileInText = tStripper.getText(document);
|
||||||
|
// String[] lines = pdfFileInText.split("\\r?\\n");
|
||||||
|
content.append(pdfFileInText);
|
||||||
|
}
|
||||||
|
document.close();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
PDDocument document = PDDocument.load(new File(readFilePath));
|
|
||||||
document.getClass();
|
|
||||||
if (!document.isEncrypted()) {
|
|
||||||
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
|
|
||||||
stripper.setSortByPosition(true);
|
|
||||||
PDFTextStripper tStripper = new PDFTextStripper();
|
|
||||||
String pdfFileInText = tStripper.getText(document);
|
|
||||||
// String[] lines = pdfFileInText.split("\\r?\\n");
|
|
||||||
content.append(pdfFileInText);
|
|
||||||
}
|
|
||||||
document.close();
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("搜索中心修改数据读取文档内容时失败");
|
logger.error("搜索中心修改数据读取文档内容时失败");
|
||||||
|
|||||||
Reference in New Issue
Block a user