|
@@ -8,12 +8,17 @@ import com.spire.pdf.PdfDocument;
|
|
|
import com.spire.pdf.PdfPageBase;
|
|
|
import com.spire.pdf.general.find.PdfTextFind;
|
|
|
import com.spire.pdf.general.find.PdfTextFindCollection;
|
|
|
+import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
+import org.apache.pdfbox.text.PDFTextStripper;
|
|
|
import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
public class PDFUtil {
|
|
@@ -89,34 +94,50 @@ public class PDFUtil {
|
|
|
table.addCell(cell);
|
|
|
}
|
|
|
|
|
|
- public static List<String> getPdfSignIds(String pdfUrl) {
|
|
|
- PdfDocument pdf = new PdfDocument();
|
|
|
+ public static List<String> getPdfSignIds(String pdfUr) {
|
|
|
List<String> eVisaConfigList = new ArrayList<>();
|
|
|
- try {
|
|
|
- InputStream ossInputStream = CommonUtil.getOSSInputStream(pdfUrl);
|
|
|
- //加载PDF文档
|
|
|
- pdf.loadFromStream(ossInputStream);
|
|
|
-
|
|
|
- for(int i= 0;i<pdf.getPages().getCount();i++){
|
|
|
- PdfPageBase page = pdf.getPages().get(i);
|
|
|
- PdfTextFindCollection allText = page.findAllText();
|
|
|
- PdfTextFind[] finds = allText.getFinds();
|
|
|
- for(int k=0;k<finds.length;k++){
|
|
|
- String textStr = finds[k].getMatchText();
|
|
|
- System.out.println(textStr);
|
|
|
- String[] textS = Func.toStrArray("\\|\\|",textStr);
|
|
|
- for(String txt : textS){
|
|
|
- if (txt.length() >= 15 && Func.isNumeric(txt)||(Func.isNumeric(txt)&&txt.length()==8&&txt.startsWith("123"))) {
|
|
|
- eVisaConfigList.add(txt);
|
|
|
+ try {
|
|
|
+ InputStream inputStream = CommonUtil.getOSSInputStream(pdfUr);
|
|
|
+ PDDocument document = PDDocument.load(inputStream);
|
|
|
+ PDFTextStripper stripper = new PDFTextStripper();
|
|
|
+ String text = stripper.getText(document);
|
|
|
+ String[] lines = text.split("[ \\n]+");
|
|
|
+ for(int k=0;k<lines.length;k++){
|
|
|
+ String textStr = lines[k];
|
|
|
+ if(textStr.indexOf("*")>=0){
|
|
|
+ textStr = textStr.substring(textStr.lastIndexOf("*")+1,textStr.length());
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] textS = Func.toStrArray("\\|\\|",textStr);
|
|
|
+ for(String txt : textS){
|
|
|
+ for (int i = 0; i < txt.length(); i++) {
|
|
|
+ if (!Character.isDigit(txt.charAt(i))) {
|
|
|
+ txt=txt.substring(0,i);
|
|
|
}
|
|
|
}
|
|
|
+ if (txt.length() >= 15 && Func.isNumeric(txt)) {
|
|
|
+ eVisaConfigList.add(txt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 特殊处理
|
|
|
+ if(textStr.indexOf("1")>=0){
|
|
|
+ String txt = textStr.substring(textStr.indexOf("1"));
|
|
|
+ if (txt.length() >= 15 && Func.isNumeric(txt)) {
|
|
|
+ System.out.println(txt);
|
|
|
+ eVisaConfigList.add(txt);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- ossInputStream.close();
|
|
|
+
|
|
|
+ List<String> unique = eVisaConfigList.stream().distinct().collect(Collectors.toList());
|
|
|
+ document.close();
|
|
|
+ return unique;
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
+ System.out.println("pdf大小为0");
|
|
|
+ return eVisaConfigList;
|
|
|
}
|
|
|
- return eVisaConfigList;
|
|
|
}
|
|
|
|
|
|
/* public static void main(String[] args) {
|