1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;
//import java.io.*;
import java.util.regex.*;
import java.io.IOException;
public class ParserPdf{
public static Pattern pattern;
public static Matcher matcher;
public static String cdeadh="";
public static String numcmd="";
public static String result="";
public static String newName="";
public static void main(String[] args) {
for(int i=0; i<args.length; i++) {
newName=reader(args[i]);
System.out.println(newName);
reader(args[i]);
}
}
public static String reader(String file) {
PdfReader reader;
String res="";
try {
reader = new PdfReader(file);
String textPdf = PdfTextExtractor.getTextFromPage(reader, 1);
//System.out.println(textPdf);
reader.close();
res=finderCopab(textPdf, "AD"+"[0-9]{3}"+".*");
res=finderArca(textPdf, "22"+"[0-9]{3}"+"[A-Z]"+".*");
res=finderCesaea(textPdf, "CESAEA"+".*");
res=finderCesaew(textPdf, "CESAEW"+".*");
} catch (IOException e) {
e.printStackTrace();
}
return res;
}
// Finder ADH COPAB
public static String finderCopab(String data, String regEx) throws IOException {
pattern = Pattern.compile(regEx);
matcher = pattern.matcher(data);
while(matcher.find()) {
//cdeadh=matcher.toString();
//System.out.println(cdeadh);
cdeadh=matcher.toString().substring(69, 74);
numcmd=matcher.toString().substring(98, 104);
result=cdeadh+"_"+numcmd;
//System.out.println(result);
}
return result;
}
// Finder ADH ARCA
public static String finderArca(String data, String regEx) throws IOException {
pattern = Pattern.compile(regEx);
matcher = pattern.matcher(data);
while(matcher.find()) {
//cdeadh=matcher.toString();
//System.out.println(cdeadh);
cdeadh=matcher.toString().substring(74, 80);
numcmd=matcher.toString().substring(103, 109);
result=cdeadh+"_"+numcmd;
//System.out.println(result);
}
return result;
}
// Finder cession CESAEA
public static String finderCesaea(String data, String regEx) throws IOException {
pattern = Pattern.compile(regEx);
matcher = pattern.matcher(data);
while(matcher.find()) {
cdeadh=matcher.toString().substring(65, 72);
//System.out.println(cdeadh);
if(!cdeadh.equals("CESAEA/")) {
cdeadh=matcher.toString().substring(65, 71);
numcmd=matcher.toString().substring(94, 100);
result=cdeadh+"_"+numcmd;
//System.out.println(result);
}
}
return result;
}
// Finder cession CESAEW
public static String finderCesaew(String data, String regEx) throws IOException {
pattern = Pattern.compile(regEx);
matcher = pattern.matcher(data);
while(matcher.find()) {
cdeadh=matcher.toString().substring(65, 72);
//System.out.println(cdeadh);
if(!cdeadh.equals("CESAEW/")) {
cdeadh=matcher.toString().substring(65, 71);
numcmd=matcher.toString().substring(94, 100);
result=cdeadh+"_"+numcmd;
//System.out.println(result);
}
}
return result;
}
} |
Partager