我有一個很多pdf文件夾,我需要將它們全部轉換爲txt並將這些文本文件保存在另一個文件夾中。我想爲此使用java。如何從一個文件夾中解析多個pdf文件到Java
我有這個代碼來解析PDF,但它只能在一個時間工作,我需要處理一個文件夾與數以千計的PDF文件。
PDFTextStripper pdfStripper = null;
PDDocument pdDoc = null;
COSDocument cosDoc = null;
File file = new File("C:/my.pdf");
try {
PDFParser parser = new PDFParser(new FileInputStream(file));
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);
pdfStripper.setStartPage(1);
pdfStripper.setEndPage(20);
String parsedText = pdfStripper.getText(pdDoc);
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
任何想法?
把上面的代碼在一個循環中,遍歷該文件。 –
嘗試使用文件夾名稱,而不是使用一個文件名「listFiles()'方法 –