如何使用Apache Tika仅从.ppt中提取文本

时间:2018-02-09 12:34:55

标签: apache-tika

公共课测试{

    public static void main(String[] args) throws Exception{
        String data;
        TikaConfig tikaConfig = TikaConfig.getDefaultConfig();
        Metadata metadata = new Metadata();
        ContentHandler handler;
        try (InputStream stream = new BufferedInputStream(new FileInputStream(new File("E:\\AllTypes\\PPT\\Presentation1.pptx")))) {
            Detector detector = tikaConfig.getDetector();
            Parser parser = tikaConfig.getParser();
            MediaType type = detector.detect(stream, metadata);
            metadata.set(Metadata.CONTENT_TYPE, type.toString());
            handler = new BodyContentHandler(-1);
            parser.parse(stream, handler, metadata, new ParseContext());
            data = handler.toString();
            System.out.println(data);
        }
    }
}

我只有Hello世界!在输入ppt所以我只想要Hello世界! 输出:[Content_Types] .xml

_rels /的.rels

PPT /幻灯片/ _rels / slide1.xml.rels

PPT / _rels / presentation.xml.rels

PPT / presentation.xml

PPT /幻灯片/ slide1.xml                                  你好,世界!

PPT / slideLayouts / _rels / slideLayout6.xml.rels

PPT / slideLayouts / _rels / slideLayout7.xml.rels

PPT / slideLayouts / _rels / slideLayout9.xml.rels

PPT / slideLayouts / _rels / slideLayout10.xml.rels

PPT / slideLayouts / _rels / slideLayout8.xml.rels

PPT / slideLayouts / _rels / slideLayout11.xml.rels

PPT / slideLayouts / _rels / slideLayout1.xml.rels

PPT / slideLayouts / _rels / slideLayout2.xml.rels

PPT / slideLayouts / _rels / slideLayout3.xml.rels

PPT / slideLayouts / _rels / slideLayout4.xml.rels

PPT / slideMasters / _rels / slideMaster1.xml.rels

PPT / slideLayouts / slideLayout11.xml                                点击编辑主标题样式点击编辑主文本样式第二级第三级第四级第五级1/30/2018 <#>

PPT / slideLayouts / slideLayout10.xml                             点击编辑主标题样式点击编辑主文本样式第二级第三级第四级第五级1/30/2018 <#>

PPT / slideLayouts / slideLayout3.xml                                  单击以编辑主标题样式单击以编辑主文本样式1/30/2018 <#>

PPT / slideLayouts / slideLayout2.xml                             点击编辑主标题样式点击编辑主文本样式第二级第三级第四级第五级1/30/2018 <#>

PPT / slideLayouts / slideLayout1.xml                                  单击以编辑主标题样式单击以编辑主标题样式1/30/2018 <#>

PPT / slideMasters / slideMaster1.xml                                      点击编辑主标题样式点击编辑主文本样式第二级第三级第四级第五级1/30/2018 <#>

PPT / slideLayouts / slideLayout4.xml                             点击编辑主标题样式点击编辑主文本样式第二级第三级第四级第五级点击编辑主文本样式第二级第三级第四级第五级1/30/2018 <#>

PPT / slideLayouts / slideLayout5.xml                                单击以编辑主标题样式单击以编辑主文本样式单击以编辑主文本样式第二级第三级第四级第五级单击以编辑主文本样式单击以编辑主文本样式第二级第三级第四级第五级1/30 / 2018年<#>

PPT / slideLayouts / slideLayout6.xml                             点击编辑主标题样式1/30/2018 <#>

PPT / slideLayouts / slideLayout7.xml                             1/30/2018 <#>

PPT / slideLayouts / slideLayout8.xml                                  单击以编辑主标题样式单击以编辑主文本样式第二级第三级第四级第五级单击以编辑主文本样式1/30/2018 <#>

PPT / slideLayouts / slideLayout9.xml                                  单击以编辑主标题样式单击以编辑主文本样式1/30/2018 <#>

PPT / slideLayouts / _rels / slideLayout5.xml.rels

PPT /主题/ theme1.xml

docProps / thumbnail.jpeg

PPT / presProps.xml

PPT / tableStyles.xml

PPT / viewProps.xml

docProps / core.xml   PowerPoint简报srinuk srinuk 1 2018-01-30T10:19:34Z 2018-01-30T10:22:05Z

docProps / app.xml中   2 3 Microsoft Office PowerPoint宽屏1 1 0 0 0假使用的字体3主题1幻灯片标题1 Arial Calibri Calibri Light办公主题PowerPoint演示文稿false false false 15.0000

1 个答案:

答案 0 :(得分:0)

您可以尝试使用tika-app.jar。只需使用Tika提取文本功能。

Tika tika = new Tika(); File file = new File("path"); String str = tika.parseToString(file);

此代码只解析文件中的文本内容。