示例代码
public void parseExample() {
ParseContext parseContext = new ParseContext();
AutoDetectParser parser = new AutoDetectParser();
BodyContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();
OfficeParserConfig officeParserConfig = new OfficeParserConfig();
officeParserConfig.setIncludeHeadersAndFooters(false);
boolean hf= officeParserConfig.getIncludeHeadersAndFooters();
parseContext.set(OfficeParserConfig.class, officeParserConfig);
System.out.println("headfoot"+hf);
try(FileInputStream fin=new FileInputStream("D:\\docs\\Out22.docx")) {
parser.parse(fin, handler, metadata, parseContext);
String text = handler.toString();
System.out.println("output :"+text);
} catch (IOException | SAXException | TikaException ex) {
ex.printStackTrace();
}
}