PDFファイルを読み取るためにiTextプログラムがPDFBoxプログラムに置き換えられました。
public static void main(String[] args) {
// TODO Auto-generated method stub
PDDocument pd;
BufferedWriter wr;
try {
File input = new File("C:\\test\\ExtractTextFromThis.pdf"); // The PDF file from where you would like to extract
File output = new File("C:\\test\\OutPut.txt"); // The text file where you are going to store the extracted data
//ドキュメントを読み込みます。
pd = PDDocument.load(input); // load document
pd.setAllSecurityToBeRemoved(true);
//言語をチェックしようとしています
System.out.println(pd.getDocumentCatalog().getLanguage());
PDFTextStripper stripper = new PDFTextStripper("UTF-8"); // Initializing PDFTextStripper Object with UTF-8 encoding.
// PDFTextStripperByArea stripper = new PDFTextStripperByArea("UTF-16");
// Please provide example for this. In attached document,I want to extract text from rectangle. There are 30 boxes.
wr = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(output)));
stripper.writeText(pd, wr);
System.out.println(stripper.getText(pd));
String text = stripper.getText(pd);
char[] cArr = text.toCharArray();
// Here is the problem. It's not printing characters of Kannada language within its UTF Range.
//printing chracters -- their integer value -- their Hexadecimal value
for (int i = 1; i < 130; i++) {
System.out.println(cArr[i] + "\t" + (int) cArr[i] + "\t" + Integer.toHexString(cArr[i]));
}
if (pd != null) {
pd.close();
}
wr.close();
} catch (Exception e) {
e.printStackTrace();
}
}