package cokr.xit.fims.cmmn.pdf;

import java.io.IOException;
import java.util.regex.Pattern;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;

public class ExtractText {

	public static final String REGEXP_PATTERN_NUMBER = "^[\\d]*$";

	public static String getExtractEpayNo(PDDocument pdDocument, int pageNum) {
		String epayNo = "";

		PDFTextStripper Tstripper = new PDFTextStripper();

		Tstripper.setStartPage(pageNum);
        Tstripper.setEndPage(pageNum);
        String summaryText = null;

        try {
			summaryText = Tstripper.getText(pdDocument);
		} catch (IOException e) {
			e.printStackTrace();
		}

        String[] textArr = summaryText.split("\r\n");

        for(int i=0; i < textArr.length; i++) {
        	boolean isNumber = Pattern.matches(REGEXP_PATTERN_NUMBER, textArr[i]);
        	if(isNumber) {
        		if(textArr[i].length() == 19) {
        			epayNo = textArr[i];
        		}
        	}
        }
		return epayNo;
	}

}
