Search in sources :

Example 46 with HSLFSlideShow

use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.

the class TestHeadersFooters method testCreateSlideFooters.

@Test
public void testCreateSlideFooters() throws IOException {
    HSLFSlideShow ppt1 = new HSLFSlideShow();
    HeadersFooters hdd = ppt1.getSlideHeadersFooters();
    hdd.setFootersText("My slide footer");
    hdd.setSlideNumberVisible(true);
    HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
    HeadersFooters hdd2 = ppt2.getSlideHeadersFooters();
    assertTrue(hdd2.isSlideNumberVisible());
    assertTrue(hdd2.isFooterVisible());
    assertEquals("My slide footer", hdd2.getFooterText());
    ppt2.close();
    ppt1.close();
}
Also used : HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) Test(org.junit.Test)

Example 47 with HSLFSlideShow

use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.

the class TestHeadersFooters method testReadNoHeadersFooters.

/**
     * If Headers / Footers are not set, all the getters should return <code>false</code> or <code>null</code>
     */
@Test
public void testReadNoHeadersFooters() throws Exception {
    InputStream is = _slTests.openResourceAsStream("basic_test_ppt_file.ppt");
    HSLFSlideShow ppt = new HSLFSlideShow(is);
    is.close();
    HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
    assertFalse(slideHdd.isFooterVisible());
    assertNull(slideHdd.getFooterText());
    assertFalse(slideHdd.isSlideNumberVisible());
    assertFalse(slideHdd.isHeaderVisible());
    assertNull(slideHdd.getHeaderText());
    assertFalse(slideHdd.isUserDateVisible());
    assertNull(slideHdd.getDateTimeText());
    HeadersFooters notesHdd = ppt.getNotesHeadersFooters();
    assertFalse(notesHdd.isFooterVisible());
    assertNull(notesHdd.getFooterText());
    assertFalse(notesHdd.isHeaderVisible());
    assertNull(notesHdd.getHeaderText());
    assertFalse(notesHdd.isUserDateVisible());
    assertNull(notesHdd.getDateTimeText());
    for (HSLFSlide s : ppt.getSlides()) {
        HeadersFooters hd1 = s.getHeadersFooters();
        assertFalse(hd1.isFooterVisible());
        assertNull(hd1.getFooterText());
        assertFalse(hd1.isHeaderVisible());
        assertNull(hd1.getHeaderText());
        assertFalse(hd1.isUserDateVisible());
        assertNull(hd1.getDateTimeText());
    }
    ppt.close();
}
Also used : InputStream(java.io.InputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 48 with HSLFSlideShow

use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.

the class TestHeadersFooters method testRead.

@Test
public void testRead() throws IOException {
    InputStream is = _slTests.openResourceAsStream("headers_footers.ppt");
    HSLFSlideShow ppt = new HSLFSlideShow(is);
    is.close();
    HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
    assertTrue(slideHdd.isFooterVisible());
    assertEquals("Global Slide Footer", slideHdd.getFooterText());
    assertTrue(slideHdd.isSlideNumberVisible());
    assertFalse(slideHdd.isHeaderVisible());
    assertNull(slideHdd.getHeaderText());
    assertFalse(slideHdd.isUserDateVisible());
    assertNull(slideHdd.getDateTimeText());
    HeadersFooters notesHdd = ppt.getNotesHeadersFooters();
    assertTrue(notesHdd.isFooterVisible());
    assertEquals("Notes Footer", notesHdd.getFooterText());
    assertTrue(notesHdd.isHeaderVisible());
    assertEquals("Notes Header", notesHdd.getHeaderText());
    assertTrue(notesHdd.isUserDateVisible());
    assertNull(notesHdd.getDateTimeText());
    List<HSLFSlide> slide = ppt.getSlides();
    //the first slide uses presentation-scope headers / footers
    HeadersFooters hd1 = slide.get(0).getHeadersFooters();
    assertEquals(slideHdd.isFooterVisible(), hd1.isFooterVisible());
    assertEquals(slideHdd.getFooterText(), hd1.getFooterText());
    assertEquals(slideHdd.isSlideNumberVisible(), hd1.isSlideNumberVisible());
    assertEquals(slideHdd.isHeaderVisible(), hd1.isHeaderVisible());
    assertEquals(slideHdd.getHeaderText(), hd1.getHeaderText());
    assertEquals(slideHdd.isUserDateVisible(), hd1.isUserDateVisible());
    assertEquals(slideHdd.getDateTimeText(), hd1.getDateTimeText());
    //the first slide uses per-slide headers / footers
    HeadersFooters hd2 = slide.get(1).getHeadersFooters();
    assertEquals(true, hd2.isFooterVisible());
    assertEquals("per-slide footer", hd2.getFooterText());
    assertEquals(true, hd2.isUserDateVisible());
    assertEquals("custom date format", hd2.getDateTimeText());
    ppt.close();
}
Also used : InputStream(java.io.InputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 49 with HSLFSlideShow

use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.

the class TestHyperlink method bug47291.

@Test
public void bug47291() throws IOException {
    HSLFSlideShow ppt1 = new HSLFSlideShow();
    HSLFSlide slide1 = ppt1.createSlide();
    HSLFTextRun r1 = slide1.createTextBox().setText("page1");
    HSLFHyperlink hl1 = r1.createHyperlink();
    hl1.linkToEmail("dev@poi.apache.org");
    HSLFTextRun r2 = ppt1.createSlide().createTextBox().setText("page2");
    HSLFHyperlink hl2 = r2.createHyperlink();
    hl2.linkToLastSlide();
    HSLFSlide sl1 = ppt1.createSlide();
    HSLFTextBox tb1 = sl1.createTextBox();
    tb1.setAnchor(new Rectangle2D.Double(100, 100, 100, 100));
    tb1.appendText("text1 ", false);
    HSLFTextRun r3 = tb1.appendText("link", false);
    tb1.appendText(" text2", false);
    HSLFHyperlink hl3 = r3.createHyperlink();
    hl3.linkToSlide(slide1);
    HSLFTextRun r4 = ppt1.createSlide().createTextBox().setText("page4");
    HSLFHyperlink hl4 = r4.createHyperlink();
    hl4.linkToUrl("http://poi.apache.org");
    HSLFTextBox tb5 = ppt1.createSlide().createTextBox();
    tb5.setText("page5");
    HSLFHyperlink hl5 = tb5.createHyperlink();
    hl5.linkToFirstSlide();
    HSLFSlideShow ppt2 = HSLFTestDataSamples.writeOutAndReadBack(ppt1);
    ppt1.close();
    List<HSLFSlide> slides = ppt2.getSlides();
    tb1 = (HSLFTextBox) slides.get(0).getShapes().get(0);
    hl1 = tb1.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
    assertNotNull(hl1);
    assertEquals("dev@poi.apache.org", hl1.getLabel());
    assertEquals(HyperlinkType.EMAIL, hl1.getTypeEnum());
    HSLFTextBox tb2 = (HSLFTextBox) slides.get(1).getShapes().get(0);
    hl2 = tb2.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
    assertNotNull(hl2);
    assertEquals(InteractiveInfoAtom.LINK_LastSlide, hl2.getInfo().getInteractiveInfoAtom().getHyperlinkType());
    assertEquals(HyperlinkType.DOCUMENT, hl2.getTypeEnum());
    HSLFTextBox tb3 = (HSLFTextBox) slides.get(2).getShapes().get(0);
    hl3 = tb3.getTextParagraphs().get(0).getTextRuns().get(1).getHyperlink();
    assertNotNull(hl3);
    assertEquals(ppt2.getSlides().get(0)._getSheetNumber(), Integer.parseInt(hl3.getAddress().split(",")[0]));
    assertEquals(HyperlinkType.DOCUMENT, hl3.getTypeEnum());
    HSLFTextBox tb4 = (HSLFTextBox) slides.get(3).getShapes().get(0);
    hl4 = tb4.getTextParagraphs().get(0).getTextRuns().get(0).getHyperlink();
    assertNotNull(hl4);
    assertEquals("http://poi.apache.org", hl4.getLabel());
    assertEquals(HyperlinkType.URL, hl4.getTypeEnum());
    tb5 = (HSLFTextBox) slides.get(4).getShapes().get(0);
    hl5 = tb5.getHyperlink();
    assertNotNull(hl5);
    assertEquals(InteractiveInfoAtom.LINK_FirstSlide, hl5.getInfo().getInteractiveInfoAtom().getHyperlinkType());
    assertEquals(HyperlinkType.DOCUMENT, hl5.getTypeEnum());
    ppt2.close();
}
Also used : HSLFTextRun(org.apache.poi.hslf.usermodel.HSLFTextRun) HSLFTextBox(org.apache.poi.hslf.usermodel.HSLFTextBox) HSLFHyperlink(org.apache.poi.hslf.usermodel.HSLFHyperlink) Rectangle2D(java.awt.geom.Rectangle2D) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) HSLFSlide(org.apache.poi.hslf.usermodel.HSLFSlide) Test(org.junit.Test)

Example 50 with HSLFSlideShow

use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.

the class TestExtractor method testHeaderFooter.

/**
     * From bug #45537
     */
@Test
public void testHeaderFooter() throws IOException {
    String text;
    // With a header on the notes
    InputStream is1 = slTests.openResourceAsStream("45537_Header.ppt");
    HSLFSlideShow ppt1 = new HSLFSlideShow(is1);
    is1.close();
    assertNotNull(ppt1.getNotesHeadersFooters());
    assertEquals("testdoc test phrase", ppt1.getNotesHeadersFooters().getHeaderText());
    PowerPointExtractor ppe1 = new PowerPointExtractor(ppt1.getSlideShowImpl());
    text = ppe1.getText();
    assertFalse("Header shouldn't be there by default\n" + text, text.contains("testdoc"));
    assertFalse("Header shouldn't be there by default\n" + text, text.contains("test phrase"));
    ppe1.setNotesByDefault(true);
    text = ppe1.getText();
    assertContains(text, "testdoc");
    assertContains(text, "test phrase");
    ppe1.close();
    ppt1.close();
    // And with a footer, also on notes
    InputStream is2 = slTests.openResourceAsStream("45537_Footer.ppt");
    HSLFSlideShow ppt2 = new HSLFSlideShow(is2);
    is2.close();
    assertNotNull(ppt2.getNotesHeadersFooters());
    assertEquals("testdoc test phrase", ppt2.getNotesHeadersFooters().getFooterText());
    ppt2.close();
    PowerPointExtractor ppe2 = openExtractor("45537_Footer.ppt");
    text = ppe2.getText();
    assertFalse("Header shouldn't be there by default\n" + text, text.contains("testdoc"));
    assertFalse("Header shouldn't be there by default\n" + text, text.contains("test phrase"));
    ppe2.setNotesByDefault(true);
    text = ppe2.getText();
    assertContains(text, "testdoc");
    assertContains(text, "test phrase");
    ppe2.close();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) HSLFSlideShow(org.apache.poi.hslf.usermodel.HSLFSlideShow) Test(org.junit.Test)

Aggregations

HSLFSlideShow (org.apache.poi.hslf.usermodel.HSLFSlideShow)69 Test (org.junit.Test)42 HSLFSlide (org.apache.poi.hslf.usermodel.HSLFSlide)39 HSLFShape (org.apache.poi.hslf.usermodel.HSLFShape)17 ByteArrayInputStream (java.io.ByteArrayInputStream)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 InputStream (java.io.InputStream)10 FileOutputStream (java.io.FileOutputStream)9 HSLFTextRun (org.apache.poi.hslf.usermodel.HSLFTextRun)9 HSLFTextParagraph (org.apache.poi.hslf.usermodel.HSLFTextParagraph)8 Rectangle2D (java.awt.geom.Rectangle2D)7 FileInputStream (java.io.FileInputStream)7 HSLFPictureData (org.apache.poi.hslf.usermodel.HSLFPictureData)7 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)7 HWPFDocument (org.apache.poi.hwpf.HWPFDocument)7 HSLFSlideShowImpl (org.apache.poi.hslf.usermodel.HSLFSlideShowImpl)6 HSLFTextBox (org.apache.poi.hslf.usermodel.HSLFTextBox)5 POIDataSamples (org.apache.poi.POIDataSamples)4 Record (org.apache.poi.hslf.record.Record)4 HSLFHyperlink (org.apache.poi.hslf.usermodel.HSLFHyperlink)4