use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class TestHeadersFooters method testRead2007.
/**
* Test extraction of headers / footers from PPTs saved in Office 2007
*/
@Test
public void testRead2007() throws IOException {
InputStream is = _slTests.openResourceAsStream("headers_footers_2007.ppt");
HSLFSlideShow ppt = new HSLFSlideShow(is);
is.close();
HeadersFooters slideHdd = ppt.getSlideHeadersFooters();
assertTrue(slideHdd.isFooterVisible());
assertEquals("THE FOOTER TEXT", slideHdd.getFooterText());
assertTrue(slideHdd.isSlideNumberVisible());
assertFalse(slideHdd.isHeaderVisible());
assertNull(slideHdd.getHeaderText());
assertTrue(slideHdd.isUserDateVisible());
assertEquals("Wednesday, August 06, 2008", slideHdd.getDateTimeText());
HeadersFooters notesHdd = ppt.getNotesHeadersFooters();
assertTrue(notesHdd.isFooterVisible());
assertEquals("THE NOTES FOOTER TEXT", notesHdd.getFooterText());
assertTrue(notesHdd.isHeaderVisible());
assertEquals("THE NOTES HEADER TEXT", notesHdd.getHeaderText());
assertTrue(notesHdd.isUserDateVisible());
assertTrue(notesHdd.isDateTimeVisible());
//TODO: depending on the formatId getDateTimeText() should return formatted date
//assertEquals("08/12/08", notesHdd.getDateTimeText());
//per-slide headers / footers
List<HSLFSlide> slide = ppt.getSlides();
//the first slide uses presentation-scope headers / footers
HeadersFooters hd1 = slide.get(0).getHeadersFooters();
assertTrue(hd1.isFooterVisible());
assertEquals("THE FOOTER TEXT", hd1.getFooterText());
assertTrue(hd1.isSlideNumberVisible());
assertFalse(hd1.isHeaderVisible());
assertNull(hd1.getHeaderText());
assertTrue(hd1.isUserDateVisible());
assertTrue(hd1.isDateTimeVisible());
assertEquals("Wednesday, August 06, 2008", hd1.getDateTimeText());
//the second slide uses custom per-slide headers / footers
HeadersFooters hd2 = slide.get(1).getHeadersFooters();
assertTrue(hd2.isFooterVisible());
assertEquals("THE FOOTER TEXT FOR SLIDE 2", hd2.getFooterText());
assertTrue(hd2.isSlideNumberVisible());
assertFalse(hd2.isHeaderVisible());
assertNull(hd2.getHeaderText());
assertTrue(hd2.isUserDateVisible());
assertTrue(hd2.isDateTimeVisible());
assertEquals("August 06, 2008", hd2.getDateTimeText());
//the third slide uses per-slide headers / footers
HeadersFooters hd3 = slide.get(2).getHeadersFooters();
assertTrue(hd3.isFooterVisible());
assertEquals("THE FOOTER TEXT", hd3.getFooterText());
assertTrue(hd3.isSlideNumberVisible());
assertFalse(hd3.isHeaderVisible());
assertNull(hd3.getHeaderText());
assertTrue(hd3.isUserDateVisible());
assertTrue(hd3.isDateTimeVisible());
assertEquals("Wednesday, August 06, 2008", hd3.getDateTimeText());
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class TestHyperlink method testTextRunHyperlinks.
@Test
public void testTextRunHyperlinks() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("WithLinks.ppt"));
HSLFSlide slide = ppt.getSlides().get(0);
List<HSLFTextParagraph> para = slide.getTextParagraphs().get(1);
String rawText = toExternalString(getRawText(para), para.get(0).getRunType());
String expected = "This page has two links:\n" + "http://jakarta.apache.org/poi/\n" + "\n" + "http://slashdot.org/\n" + "\n" + "In addition, its notes has one link";
assertEquals(expected, rawText);
List<HSLFHyperlink> links = findHyperlinks(para);
assertEquals(2, links.size());
assertEquals("http://jakarta.apache.org/poi/", links.get(0).getLabel());
assertEquals("http://jakarta.apache.org/poi/", links.get(0).getAddress());
assertEquals("http://jakarta.apache.org/poi/", rawText.substring(links.get(0).getStartIndex(), links.get(0).getEndIndex() - 1));
assertEquals("http://slashdot.org/", links.get(1).getLabel());
assertEquals("http://slashdot.org/", links.get(1).getAddress());
assertEquals("http://slashdot.org/", rawText.substring(links.get(1).getStartIndex(), links.get(1).getEndIndex() - 1));
slide = ppt.getSlides().get(1);
para = slide.getTextParagraphs().get(1);
rawText = toExternalString(getRawText(para), para.get(0).getRunType());
expected = "I have the one link:\n" + "Jakarta HSSF";
assertEquals(expected, rawText);
links.clear();
links = findHyperlinks(para);
assertNotNull(links);
assertEquals(1, links.size());
assertEquals("Open Jakarta POI HSSF module test ", links.get(0).getLabel());
assertEquals("http://jakarta.apache.org/poi/hssf/", links.get(0).getAddress());
assertEquals("Jakarta HSSF", rawText.substring(links.get(0).getStartIndex(), links.get(0).getEndIndex() - 1));
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class TestMovieShape method testCreate.
@Test
public void testCreate() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow();
HSLFSlide slide = ppt.createSlide();
String path = "/test-movie.mpg";
int movieIdx = ppt.addMovie(path, MovieShape.MOVIE_MPEG);
HSLFPictureData thumbnailData = ppt.addPicture(_slTests.readFile("tomcat.png"), PictureType.PNG);
MovieShape shape = new MovieShape(movieIdx, thumbnailData);
shape.setAnchor(new Rectangle2D.Double(300, 225, 120, 90));
slide.addShape(shape);
assertEquals(path, shape.getPath());
assertTrue(shape.isAutoPlay());
shape.setAutoPlay(false);
assertFalse(shape.isAutoPlay());
ByteArrayOutputStream out = new ByteArrayOutputStream();
ppt.write(out);
ppt = new HSLFSlideShow(new ByteArrayInputStream(out.toByteArray()));
slide = ppt.getSlides().get(0);
shape = (MovieShape) slide.getShapes().get(0);
assertEquals(path, shape.getPath());
assertFalse(shape.isAutoPlay());
}
use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class TableDemo method main.
public static void main(String[] args) throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow();
try {
HSLFSlide slide = ppt.createSlide();
create1stTable(slide);
create2ndTable(slide);
FileOutputStream out = new FileOutputStream("hslf-table.ppt");
ppt.write(out);
out.close();
} finally {
ppt.close();
}
}
use of org.apache.poi.hslf.usermodel.HSLFSlide in project poi by apache.
the class Graphics2DDemo method main.
/**
* A simple bar chart demo
*/
public static void main(String[] args) throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow();
try {
//bar chart data. The first value is the bar color, the second is the width
Object[] def = new Object[] { Color.yellow, 40, Color.green, 60, Color.gray, 30, Color.red, 80 };
HSLFSlide slide = ppt.createSlide();
HSLFGroupShape group = new HSLFGroupShape();
//define position of the drawing in the slide
Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);
group.setAnchor(bounds);
group.setInteriorAnchor(new java.awt.Rectangle(0, 0, 100, 100));
slide.addShape(group);
Graphics2D graphics = new PPGraphics2D(group);
//draw a simple bar graph
int x = 10, y = 10;
graphics.setFont(new Font("Arial", Font.BOLD, 10));
for (int i = 0, idx = 1; i < def.length; i += 2, idx++) {
graphics.setColor(Color.black);
int width = ((Integer) def[i + 1]).intValue();
graphics.drawString("Q" + idx, x - 5, y + 10);
graphics.drawString(width + "%", x + width + 3, y + 10);
graphics.setColor((Color) def[i]);
graphics.fill(new Rectangle(x, y, width, 10));
y += 15;
}
graphics.setColor(Color.black);
graphics.setFont(new Font("Arial", Font.BOLD, 14));
graphics.draw(group.getInteriorAnchor());
graphics.drawString("Performance", x + 30, y + 10);
FileOutputStream out = new FileOutputStream("hslf-graphics.ppt");
ppt.write(out);
out.close();
} finally {
ppt.close();
}
}
Aggregations