public List<String> readPDF(String filepath) throws IOException
{
File file = new File(filepath);
FileInputStream fis = new FileInputStream(file);
PDFParser p = new PDFParser(fis);
List<String> sline = new ArrayList<String>();
p.parse();
PDDocument pdd = p.getPDDocument();
PDFTextStripper ts = new PDFTextStripper();
String c = ts.getText(pdd);
StringBufferInputStream inputStream = new StringBufferInputStream(c);
InputStreamReader stringreader=new InputStreamReader(inputStream);
BufferedReader buff = new BufferedReader(stringreader);
/*
while (buff.ready()) {
StringBuffer sb = new StringBuffer();
String CN= buff.readLine();
if(parselineCN(CN)){
System.out.println(CN);
}
}
*/
while (buff.ready()) {
StringBuffer sb = new StringBuffer();
String CN= buff.readLine();
//System.out.println(CN);
if(parselineCN(CN)){
sb.append(CN);
String YQ = null;
do{
YQ = buff.readLine();
if(parselineYQ(YQ)){
sb.append(" ");
sb.append(YQ);
//System.out.println(sb.toString());
sline.add(sb.toString());
}
}while(buff.ready() && !parselineYQ(YQ));
}//end if
}// end while
buff.close();
pdd.close();
fis.close();
return sline;
}// end function
public boolean parselineCN(String line){
Boolean flag = true;
//String regEx="[0-9]{4}"+"\\s" +"[0-9]{3}"+"\\s"+"[0-9]{2,3}";
String regEx="0.00"+"\\s"+"CN";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(line);
if(!matcher.find()){
flag = false;
return flag;
}
return flag;
}
public boolean parselineYQ(String line){
Boolean flag = true;
String regEx="[0-9]*"+"\\s" +"0.00"+"\\s"+"YQ";
Pattern pattern = Pattern.compile(regEx);
Matcher matcher = pattern.matcher(line);
if(!matcher.find()){
flag = false;
return flag;
}
return flag;
}
public void parseflight(List ls){
List<String> kk = new ArrayList<String>();
for(int i = 0;i < ls.size(); i++){
int index = ls.get(i).toString().indexOf("YQ");
String temp = ls.get(i).toString().substring(0, index);
System.out.println("截取不需要信息后的字符串::"+temp);
kk.add(temp);
}
for(int i=0; i<kk.size(); i++){
List ww = new ArrayList();
//System.out.println(ls.get(i));
StringBuffer sb = new StringBuffer();
for(int j=0; j < kk.get(i).toString().length();j++){
String temp = kk.get(i).toString();
char c = temp.charAt(j);
String str=String.valueOf(c);
if(str.equals(" ")||" ".equals(str))
{
ww.add(sb.toString());
sb = new StringBuffer();
}
else
{
sb.append(str);
}
}
for(int k=0;k<ww.size();k++){
System.out.print(k+":"+ww.get(k).toString()+" ");
}
System.out.println("size:"+ww.size());
if(ww.get(ww.size()- 6).toString().contains("-")){
//System.out.println("----------------------------------");
//System.out.println("ww.get(ww.size()-2).toString()"+ww.get(ww.size()-2).toString());
String a1 = null;
String a2 = null;
String a3 = null;
String b1 = null;
String b2 = null;
String result = null;
PDFflight pdf = new PDFflight();
a1 = ww.get(ww.size()-22).toString();
a2 = ww.get(ww.size()-19).toString();
a3 = ww.get(ww.size()-3).toString();
b1 = ww.get(ww.size()-6).toString();
b2 = ww.get(ww.size()-13).toString();
Float re = (Float.parseFloat(replace(b1,","))+Float.parseFloat(replace(b2,",")))-(Float.parseFloat(replace(a1,","))+Float.parseFloat(replace(a2,","))+Float.parseFloat(replace(a3,",")));
String ss = String.valueOf(re);
ss = radixPoint(ss);
}
}
}
public static String replace(String id,String where){
int index = id.indexOf(where);
if(index != -1){
id = id.replaceAll(where, "");
//id = id.substring(0,index) + where + id.substring(index);
id = id.substring(0,index) + id.substring(index);
System.out.println("去除,号后的String:"+id);
}
return id;
}
public static String radixPoint(String ss){
int index = ss.indexOf(".");
if(index != -1){
ss = ss.substring(0,index);
System.out.println("去除小数的String:"+ss);
}
return ss;
}
|
|