我正在使用Apache pdfbox来提取文本。我可以从PDF中提取文本,但我不知道如何知道这个词是否是粗体? (代码建议会很好!!!) 这里是从PDF中提取纯文本的代码,工作正常。如何使用pdfbox从pdf中提取粗体文本?
PDDocument document = PDDocument
.load("/home/lipu/workspace/MRCPTester/test.pdf");
document.getClass();
if (document.isEncrypted()) {
try {
document.decrypt("");
} catch (InvalidPasswordException e) {
System.err.println("Error: Document is encrypted with a password.");
System.exit(1);
}
}
// PDFTextStripperByArea stripper = new PDFTextStripperByArea();
// stripper.setSortByPosition(true);
PDFTextStripper stripper = new PDFTextStripper();
stripper.setStartPage(1);
stripper.setEndPage(2);
stripper.setSortByPosition(true);
String st = stripper.getText(document);
你有一个带粗体文本的PDF示例吗?问题在于并不是所有的粗体字都被标记为粗体,而且还有更多不同的粗体字。因此,识别粗体字体或字符的模式可以是文档特定的。 – mkl