package com.test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import org.apache.pdfbox.pdfparser.PDFParser;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;
public class TestPdf {
public String GetTextFromPdf(String filename) throws Exception {
String content = null;
PDDocument pdfdocument = null;
FileInputStream is = new FileInputStream(filename);
PDFParser parser = new PDFParser(is);
parser.parse();
pdfdocument = parser.getPDDocument();
PDFTextStripper stripper = new PDFTextStripper();
content = stripper.getText(pdfdocument);
return content;
}
public static void main(String args[]) {
try {
TestPdf pf = new TestPdf();
String ts = pf.GetTextFromPdf("D:\157038_PackingList_20170330_100427.PDF");
OutputStreamWriter osw = new OutputStreamWriter(
new FileOutputStream("D:/aa.txt"));
System.out.println(ts);
osw.write(ts);
osw.flush();
osw.close();
} catch (Exception e) {
e.printStackTrace();
}
}

}