我需要从pdf中提取一段文字。本文具有与特征相同的字体族。有什么想法吗?干杯
编辑:,让我用另一种方式问这个问题:我如何才能从pdf页面中提取出“粗体”文本?
发布于 2014-01-14 21:57:56
public String pdftoText(String fileName){
try {
File f = new File(fileName);
if (!f.isFile()) {
System.out.println("File not exist.");
return null;
}
parser = new PDFParser(new FileInputStream(f));
parser.parse();
cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();
pdDoc = new PDDocument(cosDoc);
parsedText = pdfStripper.getText(pdDoc);
cosDoc.close();
pdDoc.close();
return parsedText;
} catch (IOException ex) {
Logger.getLogger(PDFTextParser.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
}运行前的:将pdfbox.jar添加到项目中
https://stackoverflow.com/questions/18877749
复制相似问题