我有兴趣将MS Word文档和pdf内容解析为内容及其结构。我应该能够从其内容大致重建文档。将使用什么tika方法来获取页眉,页脚,标题1,标题2,表格结构,段落等。
我在线搜索了解决方案,但找不到准确的答案。其中一些是指Apache POI项目。有人可以建议添加到以下程序的代码 -
public class MSWordParser {
public static void main(final String[] args) throws IOException, TikaException, SAXException, OpenXML4JException, XmlException {
BodyContentHandler handler = new BodyContentHandler();
Metadata metadata = new Metadata();
FileInputStream inputstream = new FileInputStream(new File("Sample_document.docx"));
ParseContext pcontext = new ParseContext();
OOXMLParser msofficeparser = new OOXMLParser ();
msofficeparser.parse(inputstream, handler, metadata, pcontext);
System.out.println("Contents of the document:" + handler.toString());
System.out.println(" " + metadata.get(Metadata.CONTENT_TYPE));
System.out.println("Sample Word Document"+ metadata.get(TikaCoreProperties.TITLE));
System.out.println("Metadata of the document:");
String[] metadataNames = metadata.names();
for(String name : metadataNames) {
System.out.println(name + ": " + metadata.get(name));
}