Example usage for org.apache.poi.xslf.usermodel XMLSlideShow getSlides

List of usage examples for org.apache.poi.xslf.usermodel XMLSlideShow getSlides

Introduction

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

Prototype

@Override
public List<XSLFSlide> getSlides() 

Source Link

Document

Return all the slides in the slideshow

Usage

From source file:com.github.codeurjc.slidesconverter.PowerPointToHTML.java

License:Apache License

private void generateSlidesContent(XMLSlideShow pptx, HSLFSlideShow ppt) throws IOException {

    out.println("<h1>Slides</h1>");

    for (int numSlide = 0; numSlide < pptx.getSlides().size(); numSlide++) {

        System.out.println("Processing slide " + numSlide);

        XSLFSlide slideX = pptx.getSlides().get(numSlide);
        HSLFSlide slide = ppt.getSlides().get(numSlide);

        Section section = getSection(numSlide);

        if (section != null && section.startSlide == numSlide) {

            if (section.level == 0) {

                out.println("<h2>" + escape(section.sectionNum + ". " + section.name) + "</h2>");

            } else {

                out.println(//from   ww  w.  j  a  v  a 2  s  .  c  o  m
                        "<h3>" + escape(section.sectionNum + "." + section.subsectionNum + ". " + section.name)
                                + "</h3>");
            }
        }

        generateSlideImage(slide);

        out.println("<h4>Slide (" + (numSlide + 1) + ")</h4>");

        out.println("<img src=" + getImageFileName(slideX.getSlideNumber()) + "><br>");

        for (XSLFShape shape : slideX.getShapes()) {

            if (shape instanceof XSLFTextShape) {

                XSLFTextShape tsh = (XSLFTextShape) shape;

                boolean first = true;
                boolean code = false;

                boolean subtitle = false;

                for (XSLFTextParagraph p : tsh) {

                    String indent = "";

                    int indentLevel = p.getIndentLevel();
                    if (subtitle) {
                        indentLevel++;
                    }

                    if (indentLevel > 0) {
                        for (int j = 0; j < indentLevel; j++) {
                            indent += "> ";
                        }
                    }

                    StringBuilder sb = new StringBuilder();
                    for (XSLFTextRun r : p) {
                        sb.append(r.getRawText());
                    }

                    String text = sb.toString();

                    // Avoid section or subsection name to appear in slide
                    // contents
                    if ((section != null && (text.equals(section.name)
                            || (section.parentSection != null && section.parentSection.name.equals(text))))
                            || text.trim().isEmpty()) {
                        continue;
                    }

                    if (first) {

                        code = p.getDefaultFontFamily().startsWith("Courier");

                        if (code) {
                            out.println("<pre style='border:1px;border-style: solid;'>");
                        }
                    }

                    if (!code) {
                        out.println("<p>");
                    }

                    out(indent + text);

                    if (!code) {
                        out.println("</p>");
                    }

                    first = false;
                    if (p.getTextAlign() == TextAlign.CENTER) {
                        subtitle = true;
                    }
                }

                if (code) {
                    out.println("</pre>");
                }

            } else if (shape instanceof XSLFPictureShape) {

                XSLFPictureShape pShape = (XSLFPictureShape) shape;

                out.println("<p>Imagen: " + pShape.getShapeName() + "</p>");
            }
        }

        out.println("<hr>");
    }

    out.println("</body></html>");
}

From source file:com.github.codeurjc.slidesconverter.PowerPointToHTML.java

License:Apache License

private List<Section> calculateSections(XMLSlideShow pptx, HSLFSlideShow ppt) {

    sectionsPerPage = new Section[pptx.getSlides().size()];

    List<Section> sectionsList = new ArrayList<>();

    String lastSection = null;//from  www  .  j a  v a  2  s  .c  o  m
    String lastSubsection = null;

    Section lastSectionObj = null;
    Section lastSubsectionObj = null;

    int numSections = 0;
    int numSubsectionsInSection = 0;

    for (int slideNum = 0; slideNum < pptx.getSlides().size(); slideNum++) {

        XSLFSlide slideX = pptx.getSlides().get(slideNum);
        HSLFSlide slide = ppt.getSlides().get(slideNum);

        String title = calculateTitle(slideX, slide);
        String subtitle = calculateSubtitle(slideX, slide);

        if (title != null && !title.trim().isEmpty()) {

            if (lastSection == null || !lastSection.equals(title)) {
                lastSection = title;
                numSections++;
                Section section = new Section(0, numSections, title);
                section.startSlide = slideNum;
                sectionsList.add(section);

                lastSubsection = null;
                lastSubsectionObj = null;

                numSubsectionsInSection = 0;

                this.sectionsPerPage[slideNum] = section;

                lastSectionObj = section;

                System.out.println("Section " + section.sectionNum + ". " + section.name);
            }

        }

        if (subtitle != null && !subtitle.trim().isEmpty()) {

            if (lastSubsection == null || !lastSubsection.equals(subtitle)) {
                lastSubsection = subtitle;
                numSubsectionsInSection++;

                Section section = new Section(1, numSections, subtitle);
                section.startSlide = slideNum;
                section.subsectionNum = numSubsectionsInSection;
                section.parentSection = lastSectionObj;
                sectionsList.add(section);

                this.sectionsPerPage[slideNum] = section;

                lastSubsectionObj = section;

                System.out.println("  Subsection " + section.sectionNum + ". " + section.name);
            }

        }

        if (sectionsPerPage[slideNum] == null) {

            if (lastSubsectionObj != null) {
                this.sectionsPerPage[slideNum] = lastSubsectionObj;
            } else {
                this.sectionsPerPage[slideNum] = lastSectionObj;
            }
        }
    }

    return sectionsList;
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImpl.java

License:MIT License

private static void transferSizedTextboxes(final XMLSlideShow ppt, final XSLFSlide slide,
        final XSLFSlide sizingSlide) {
    // Clone all text boxes to the original slide afterward, and remove the sizing slide
    for (XSLFShape shape : sizingSlide.getShapes()) {
        if (shape instanceof XSLFTextBox) {
            final XSLFTextBox src = (XSLFTextBox) shape;
            final XSLFTextBox textBox = slide.createTextBox();
            textBox.setAnchor(src.getAnchor());
            textBox.clearText();/* w w  w .j  a  v a 2 s.  c o m*/
            src.forEach(
                    srcPara -> textBox.addNewTextParagraph().getXmlObject().set(srcPara.getXmlObject().copy()));
        }
    }

    ppt.removeSlide(ppt.getSlides().indexOf(sizingSlide));
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImplTest.java

License:MIT License

@Test
public void testDateGraphTwoAxes() throws TemplateLoadException, IOException {
    final DategraphData data = createTwoAxisDategraphData();

    final XMLSlideShow pptx = pptxService.graph(data);
    testWrite(pptx);/*from   w  w  w .  ja va 2 s  . co m*/

    Assert.assertEquals(pptx.getSlides().size(), 1);
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImplTest.java

License:MIT License

@Test
public void testDateGraphSingleAxis() throws TemplateLoadException, IOException {
    final DategraphData data = createSingleAxisDategraphData();

    final XMLSlideShow pptx = pptxService.graph(data);
    testWrite(pptx);/*  w ww.j  av a  2  s.  c o m*/

    Assert.assertEquals(pptx.getSlides().size(), 1);
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImplTest.java

License:MIT License

@Test
public void testDateGraphMultipleSeries() throws TemplateLoadException, IOException {
    final DategraphData data = createTwoAxisMultipleSeriesDategraphData();

    final XMLSlideShow pptx = pptxService.graph(data);
    testWrite(pptx);//from  w  w w.j  a  va  2 s .c o m

    Assert.assertEquals(pptx.getSlides().size(), 1);
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImplTest.java

License:MIT License

@Test
public void testSunburst() throws TemplateLoadException, IOException {
    final SunburstData sunburst = createSunburstData();

    final XMLSlideShow pptx = pptxService.sunburst(sunburst);
    testWrite(pptx);/*w  ww .j  a va 2s  .c  om*/

    Assert.assertEquals(pptx.getSlides().size(), 1);
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImplTest.java

License:MIT License

@Test
public void testColoredFillSunburst() throws TemplateLoadException, IOException {
    final SunburstData sunburst = createSunburstData();
    sunburst.setColors(new String[] { "#FF0000", "#00FF00", "#0000FF" });

    final XMLSlideShow pptx = pptxService.sunburst(sunburst);
    testWrite(pptx);/*from w w  w.j a  v a2 s  . com*/

    Assert.assertEquals(pptx.getSlides().size(), 1);
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImplTest.java

License:MIT License

@Test
public void testColoredStrokeSunburst() throws TemplateLoadException, IOException {
    final SunburstData sunburst = createSunburstData();
    sunburst.setStrokeColors(new String[] { "#FFFF00", "#FF00FF", "#00FFFF" });

    final XMLSlideShow pptx = pptxService.sunburst(sunburst);
    testWrite(pptx);//from w  w w .ja  va2s .  co m

    Assert.assertEquals(pptx.getSlides().size(), 1);
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.PowerPointServiceImplTest.java

License:MIT License

@Test
public void testColoredFillAndStrokeSunburst() throws TemplateLoadException, IOException {
    final SunburstData sunburst = createSunburstData();
    sunburst.setColors(new String[] { "#FF0000", "#00FF00", "#0000FF" });
    sunburst.setStrokeColors(new String[] { "#FFFF00", "#FF00FF", "#00FFFF" });

    final XMLSlideShow pptx = pptxService.sunburst(sunburst);
    testWrite(pptx);/*from  w w w.  j a v a2 s  . c  om*/

    Assert.assertEquals(pptx.getSlides().size(), 1);
}