Example usage for org.apache.poi.xslf.usermodel XSLFSlideShow XSLFSlideShow

List of usage examples for org.apache.poi.xslf.usermodel XSLFSlideShow XSLFSlideShow

Introduction

In this page you can find the example usage for org.apache.poi.xslf.usermodel XSLFSlideShow XSLFSlideShow.

Prototype

public XSLFSlideShow(String file) throws OpenXML4JException, IOException, XmlException 

Source Link

Usage

From source file:com.jaeksoft.searchlib.parser.PptxParser.java

License:Open Source License

@Override
protected void parseContent(StreamLimiter streamLimiter, LanguageEnum lang) throws IOException {

    // TODO Optimise if it is already a file
    File tempFile = File.createTempFile("oss", ".pptx");
    FileOutputStream fos = null;/*ww  w.  j  a  v  a2s .  c o  m*/
    try {
        fos = new FileOutputStream(tempFile);
        IOUtils.copy(streamLimiter.getNewInputStream(), fos);
        fos.close();
    } catch (IOException e) {
        IOUtils.close(fos);
        throw e;
    }

    XSLFPowerPointExtractor poiExtractor = null;
    try {
        XSLFSlideShow pptSlideShow = new XSLFSlideShow(tempFile.getAbsolutePath());
        poiExtractor = new XSLFPowerPointExtractor(pptSlideShow);

        ParserResultItem result = getNewParserResultItem();
        CoreProperties info = poiExtractor.getCoreProperties();
        if (info != null) {
            result.addField(ParserFieldEnum.title, info.getTitle());
            result.addField(ParserFieldEnum.creator, info.getCreator());
            result.addField(ParserFieldEnum.subject, info.getSubject());
            result.addField(ParserFieldEnum.description, info.getDescription());
            result.addField(ParserFieldEnum.keywords, info.getKeywords());
        }

        String content = poiExtractor.getText(true, true);
        result.addField(ParserFieldEnum.content, StringUtils.replaceConsecutiveSpaces(content, " "));

        result.langDetection(10000, ParserFieldEnum.content);

    } catch (OpenXML4JException e) {
        throw new IOException(e);
    } catch (XmlException e) {
        throw new IOException(e);
    } finally {
        IOUtils.close(poiExtractor);
    }

}

From source file:com.qwazr.extractor.parser.Pptx.java

License:Apache License

@Override
protected void parseContent(File file, String extension, String mimeType) throws Exception {

    XSLFSlideShow pptSlideShow = new XSLFSlideShow(file.getAbsolutePath());
    XMLSlideShow slideshow = new XMLSlideShow(pptSlideShow.getPackage());

    // Extract metadata
    XSLFPowerPointExtractor poiExtractor = null;
    try {/*from  ww  w .ja  va 2 s .  c o m*/
        poiExtractor = new XSLFPowerPointExtractor(slideshow);
        CoreProperties info = poiExtractor.getCoreProperties();
        if (info != null) {
            metas.add(TITLE, info.getTitle());
            metas.add(CREATOR, info.getCreator());
            metas.add(SUBJECT, info.getSubject());
            metas.add(DESCRIPTION, info.getDescription());
            metas.add(KEYWORDS, info.getKeywords());
            metas.add(CREATION_DATE, info.getCreated());
            metas.add(MODIFICATION_DATE, info.getModified());
        }
    } finally {
        poiExtractor.close();
    }
    extractSides(slideshow);
}

From source file:com.qwazr.library.poi.PptxParser.java

License:Apache License

@Override
public void parseContent(final MultivaluedMap<String, String> parameters, final Path filePath,
        final String extension, final String mimeType, final ParserResultBuilder resultBuilder)
        throws Exception {

    final XSLFSlideShow pptSlideShow = new XSLFSlideShow(filePath.toAbsolutePath().toString());
    final XMLSlideShow slideshow = new XMLSlideShow(pptSlideShow.getPackage());

    final ParserFieldsBuilder metas = resultBuilder.metas();
    metas.set(MIME_TYPE, findMimeType(extension, mimeType, this::findMimeTypeUsingDefault));

    // Extract metadata
    try (XSLFPowerPointExtractor poiExtractor = new XSLFPowerPointExtractor(slideshow)) {
        final CoreProperties info = poiExtractor.getCoreProperties();
        if (info != null) {
            metas.add(TITLE, info.getTitle());
            metas.add(CREATOR, info.getCreator());
            metas.add(SUBJECT, info.getSubject());
            metas.add(DESCRIPTION, info.getDescription());
            metas.add(KEYWORDS, info.getKeywords());
            metas.add(CREATION_DATE, info.getCreated());
            metas.add(MODIFICATION_DATE, info.getModified());
        }//from   w  ww .j av  a2  s.  c  om
    }
    extractSides(slideshow, resultBuilder);
}

From source file:org.apache.tika.parser.microsoft.ooxml.XSLFPowerPointExtractorDecorator.java

License:Apache License

/**
 * In PowerPoint files, slides have things embedded in them,
 * and slide drawings which have the images
 *///from   w  w  w  . j  a  v a 2 s  .  c om
@Override
protected List<PackagePart> getMainDocumentParts() throws TikaException {
    List<PackagePart> parts = new ArrayList<>();
    XSLFSlideShow document = null;
    try {
        document = new XSLFSlideShow(extractor.getPackage());
    } catch (Exception e) {
        throw new TikaException(e.getMessage()); // Shouldn't happen
    }

    CTSlideIdList ctSlideIdList = document.getSlideReferences();
    if (ctSlideIdList != null) {
        for (int i = 0; i < ctSlideIdList.sizeOfSldIdArray(); i++) {
            CTSlideIdListEntry ctSlide = ctSlideIdList.getSldIdArray(i);
            // Add the slide
            PackagePart slidePart;
            try {
                slidePart = document.getSlidePart(ctSlide);
            } catch (IOException e) {
                throw new TikaException("Broken OOXML file", e);
            } catch (XmlException xe) {
                throw new TikaException("Broken OOXML file", xe);
            }
            parts.add(slidePart);

            // If it has drawings, return those too
            try {
                for (PackageRelationship rel : slidePart
                        .getRelationshipsByType(XSLFRelation.VML_DRAWING.getRelation())) {
                    if (rel.getTargetMode() == TargetMode.INTERNAL) {
                        PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI());
                        parts.add(rel.getPackage().getPart(relName));
                    }
                }
            } catch (InvalidFormatException e) {
                throw new TikaException("Broken OOXML file", e);
            }
        }
    }
    return parts;
}