我需要从 pdf 文件中检索一些与关键字相关的数据。这些是关键字:标题,pdf的范围,谁提出了pdf,版本,摘要,状态,监管者。
有什么工具可以从pdf中检索数据吗?提前致谢
我需要从 pdf 文件中检索一些与关键字相关的数据。这些是关键字:标题,pdf的范围,谁提出了pdf,版本,摘要,状态,监管者。
有什么工具可以从pdf中检索数据吗?提前致谢
使用PDFBOX
public class PDFTextReader
{
static String pdftoText(String fileName) {
PDFParser parser;
String parsedText = null;
PDFTextStripper pdfStripper = null;
PDDocument pdDoc = null;
COSDocument cosDoc = null;
File file = new File(fileName);
if (!file.isFile()) {
System.err.println("File " + fileName + " does not exist.");
return null;
}
try {
parser = new PDFParser(new FileInputStream(file));
} catch (IOException e) {
System.err.println("Unable to open PDF Parser. " + e.getMessage());
return null;
}
try {
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);
// pdfStripper.setParagraphStart(FIND_START_VALUE);
// pdfStripper.setParagraphEnd("FIND_END_VALUE);
parsedText = pdfStripper.getText(pdDoc);
} catch (Exception e) {
System.err
.println("An exception occured in parsing the PDF Document."
+ e.getMessage());
} finally {
try {
if (cosDoc != null)
cosDoc.close();
if (pdDoc != null)
pdDoc.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return parsedText;
}
public static void main(String args[]){
System.out.println(pdftoText(FILEPATH));
}
}
在这里,我尝试了提取该部分。这可能会对您有所帮助。