|
@@ -1,6 +1,9 @@
|
|
|
package org.springblade.evisa.utils;
|
|
|
|
|
|
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 com.spire.pdf.utilities.PdfTable;
|
|
|
import com.spire.pdf.utilities.PdfTableExtractor;
|
|
|
|
|
@@ -13,6 +16,7 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
public class PDFUtils {
|
|
|
+/*
|
|
|
public static List<String> getPdfSignIds(String pdfUrl) {
|
|
|
PdfDocument pdf = new PdfDocument();
|
|
|
List<String> eVisaConfigList = new ArrayList<>();
|
|
@@ -35,6 +39,7 @@ public class PDFUtils {
|
|
|
for (int j = 0; j < column; j++) {
|
|
|
//获取表格中的文本内容
|
|
|
String text = table.getText(i, j);
|
|
|
+ System.out.println(text);
|
|
|
String textVal[] = text.split(" ");
|
|
|
for (String textStr : textVal) {
|
|
|
if (textStr.length() >= 15 && Func.isNumeric(textStr)) {
|
|
@@ -52,14 +57,61 @@ public class PDFUtils {
|
|
|
}
|
|
|
return eVisaConfigList;
|
|
|
}
|
|
|
+*/
|
|
|
|
|
|
- public static void main1231(String[] args) {
|
|
|
- //getPdfSignIds("https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload/20230911/c8cab7dd0eebf9b11579223e860d0320.pdf");
|
|
|
+
|
|
|
+ public static List<String> getPdfSignIds(String pdfUrl) {
|
|
|
+ PdfDocument pdf = new PdfDocument();
|
|
|
+ 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();
|
|
|
+ if (textStr.length() >= 15 && Func.isNumeric(textStr)) {
|
|
|
+ System.out.println(textStr);
|
|
|
+ eVisaConfigList.add(textStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ossInputStream.close();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return eVisaConfigList;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main123(String[] args) {
|
|
|
+ String pdfUrl= "https://bladex-chongqing-info.oss-cn-hangzhou.aliyuncs.com//upload/20230913/0193a0611867a1828164bb0abc65584c.pdf";
|
|
|
List<String> eVisaConfigList = new ArrayList<>();
|
|
|
- eVisaConfigList.add("1235677");
|
|
|
- eVisaConfigList.add("123567722");
|
|
|
- System.out.println(eVisaConfigList.toArray());
|
|
|
- System.out.println(Func.toStr(eVisaConfigList));
|
|
|
- System.out.println(String.join(",", eVisaConfigList));
|
|
|
+ try {
|
|
|
+ PdfDocument pdf = new PdfDocument();
|
|
|
+ InputStream ossInputStream = CommonUtil.getOSSInputStream(pdfUrl);
|
|
|
+ //加载PDF文档
|
|
|
+ pdf.loadFromStream(ossInputStream);
|
|
|
+
|
|
|
+ for(int i= 0;i<pdf.getPages().getCount();i++){
|
|
|
+ PdfPageBase page = pdf.getPages().get(i);
|
|
|
+ // System.out.println( page.extractText(true));
|
|
|
+ String text= page.extractText(false);
|
|
|
+ PdfTextFindCollection allText = page.findAllText();
|
|
|
+ PdfTextFind[] finds = allText.getFinds();
|
|
|
+ for(int k=0;k<finds.length;k++){
|
|
|
+ String textStr = finds[k].getMatchText();
|
|
|
+ if (textStr.length() >= 15 && Func.isNumeric(textStr)) {
|
|
|
+ System.out.println(textStr);
|
|
|
+ eVisaConfigList.add(textStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|