use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class ApacheconEU08 method main.
public static void main(String[] args) throws IOException {
SlideShow<?, ?> ppt = new HSLFSlideShow();
// SlideShow<?,?> ppt = new XMLSlideShow();
ppt.setPageSize(new Dimension(720, 540));
slide1(ppt);
slide2(ppt);
slide3(ppt);
slide4(ppt);
slide5(ppt);
slide6(ppt);
slide7(ppt);
slide8(ppt);
slide9(ppt);
slide10(ppt);
slide11(ppt);
slide12(ppt);
String ext = ppt.getClass().getName().contains("HSLF") ? "ppt" : "pptx";
FileOutputStream out = new FileOutputStream("apachecon_eu_08." + ext);
ppt.write(out);
out.close();
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project tika by apache.
the class HSLFExtractor method parse.
protected void parse(DirectoryNode root, XHTMLContentHandler xhtml) throws IOException, SAXException, TikaException {
HSLFSlideShow ss = new HSLFSlideShow(root);
List<HSLFSlide> _slides = ss.getSlides();
xhtml.startElement("div", "class", "slideShow");
/* Iterate over slides and extract text */
for (HSLFSlide slide : _slides) {
xhtml.startElement("div", "class", "slide");
// Slide header, if present
HeadersFooters hf = slide.getHeadersFooters();
if (hf != null && hf.isHeaderVisible() && hf.getHeaderText() != null) {
xhtml.startElement("p", "class", "slide-header");
xhtml.characters(hf.getHeaderText());
xhtml.endElement("p");
}
// Slide master, if present
extractMaster(xhtml, slide.getMasterSheet());
// Slide text
{
xhtml.startElement("div", "class", "slide-content");
textRunsToText(xhtml, slide.getTextParagraphs());
xhtml.endElement("div");
}
// Table text
for (HSLFShape shape : slide.getShapes()) {
if (shape instanceof HSLFTable) {
extractTableText(xhtml, (HSLFTable) shape);
}
}
// Slide footer, if present
if (hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
xhtml.startElement("p", "class", "slide-footer");
xhtml.characters(hf.getFooterText());
xhtml.endElement("p");
}
// Comments, if present
StringBuilder authorStringBuilder = new StringBuilder();
for (Comment comment : slide.getComments()) {
authorStringBuilder.setLength(0);
xhtml.startElement("p", "class", "slide-comment");
if (comment.getAuthor() != null) {
authorStringBuilder.append(comment.getAuthor());
}
if (comment.getAuthorInitials() != null) {
if (authorStringBuilder.length() > 0) {
authorStringBuilder.append(" ");
}
authorStringBuilder.append("(" + comment.getAuthorInitials() + ")");
}
if (authorStringBuilder.length() > 0) {
if (comment.getText() != null) {
authorStringBuilder.append(" - ");
}
xhtml.startElement("b");
xhtml.characters(authorStringBuilder.toString());
xhtml.endElement("b");
}
if (comment.getText() != null) {
xhtml.characters(comment.getText());
}
xhtml.endElement("p");
}
// Now any embedded resources
handleSlideEmbeddedResources(slide, xhtml);
// Find the Notes for this slide and extract inline
HSLFNotes notes = slide.getNotes();
if (notes != null) {
xhtml.startElement("div", "class", "slide-notes");
textRunsToText(xhtml, notes.getTextParagraphs());
xhtml.endElement("div");
}
// Slide complete
xhtml.endElement("div");
}
// All slides done
xhtml.endElement("div");
/* notes */
xhtml.startElement("div", "class", "slide-notes");
HashSet<Integer> seenNotes = new HashSet<>();
HeadersFooters hf = ss.getNotesHeadersFooters();
for (HSLFSlide slide : _slides) {
HSLFNotes notes = slide.getNotes();
if (notes == null) {
continue;
}
Integer id = notes._getSheetNumber();
if (seenNotes.contains(id)) {
continue;
}
seenNotes.add(id);
// Repeat the Notes header, if set
if (hf != null && hf.isHeaderVisible() && hf.getHeaderText() != null) {
xhtml.startElement("p", "class", "slide-note-header");
xhtml.characters(hf.getHeaderText());
xhtml.endElement("p");
}
// Notes text
textRunsToText(xhtml, notes.getTextParagraphs());
// Repeat the notes footer, if set
if (hf != null && hf.isFooterVisible() && hf.getFooterText() != null) {
xhtml.startElement("p", "class", "slide-note-footer");
xhtml.characters(hf.getFooterText());
xhtml.endElement("p");
}
}
handleSlideEmbeddedPictures(ss, xhtml);
xhtml.endElement("div");
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestShapes method lineColor.
@Test
public void lineColor() throws IOException {
HSLFSlideShow ss = new HSLFSlideShow(_slTests.openResourceAsStream("51731.ppt"));
List<HSLFShape> shape = ss.getSlides().get(0).getShapes();
assertEquals(4, shape.size());
HSLFTextShape sh1 = (HSLFTextShape) shape.get(0);
assertEquals("Hello Apache POI", sh1.getText());
assertNull(sh1.getLineColor());
HSLFTextShape sh2 = (HSLFTextShape) shape.get(1);
assertEquals("Why are you showing this border?", sh2.getText());
assertNull(sh2.getLineColor());
HSLFTextShape sh3 = (HSLFTextShape) shape.get(2);
assertEquals("Text in a black border", sh3.getText());
assertEquals(Color.black, sh3.getLineColor());
assertEquals(0.75, sh3.getLineWidth(), 0);
HSLFTextShape sh4 = (HSLFTextShape) shape.get(3);
assertEquals("Border width is 5 pt", sh4.getText());
assertEquals(Color.black, sh4.getLineColor());
assertEquals(5.0, sh4.getLineWidth(), 0);
ss.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestShapes method shapeId.
@Test
public void shapeId() throws IOException {
HSLFSlideShow ss = new HSLFSlideShow();
HSLFSlide slide = ss.createSlide();
HSLFShape shape = null;
//EscherDgg is a document-level record which keeps track of the drawing groups
EscherDggRecord dgg = ss.getDocumentRecord().getPPDrawingGroup().getEscherDggRecord();
EscherDgRecord dg = slide.getSheetContainer().getPPDrawing().getEscherDgRecord();
//total number of shapes in the ppt
int dggShapesUsed = dgg.getNumShapesSaved();
//max number of shapeId
int dggMaxId = dgg.getShapeIdMax();
//max shapeId in the slide
int dgMaxId = dg.getLastMSOSPID();
// number of shapes in the slide
int dgShapesUsed = dg.getNumShapes();
//insert 3 shapes and make sure the Ids are properly incremented
for (int i = 0; i < 3; i++) {
shape = new HSLFLine();
assertEquals(0, shape.getShapeId());
slide.addShape(shape);
assertTrue(shape.getShapeId() > 0);
//check that EscherDgRecord is updated
assertEquals(shape.getShapeId(), dg.getLastMSOSPID());
assertEquals(dgMaxId + 1, dg.getLastMSOSPID());
assertEquals(dgShapesUsed + 1, dg.getNumShapes());
//check that EscherDggRecord is updated
assertEquals(shape.getShapeId() + 1, dgg.getShapeIdMax());
assertEquals(dggMaxId + 1, dgg.getShapeIdMax());
assertEquals(dggShapesUsed + 1, dgg.getNumShapesSaved());
dggShapesUsed = dgg.getNumShapesSaved();
dggMaxId = dgg.getShapeIdMax();
dgMaxId = dg.getLastMSOSPID();
dgShapesUsed = dg.getNumShapes();
}
//For each drawing group PPT allocates clusters with size=1024
//if the number of shapes is greater that 1024 a new cluster is allocated
//make sure it is so
int numClusters = dgg.getNumIdClusters();
for (int i = 0; i < 1025; i++) {
shape = new HSLFLine();
slide.addShape(shape);
}
assertEquals(numClusters + 1, dgg.getNumIdClusters());
ss.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestShapes method shapeGroup.
/**
* Test adding shapes to <code>ShapeGroup</code>
*/
@Test
public void shapeGroup() throws IOException {
HSLFSlideShow ss = new HSLFSlideShow();
HSLFSlide slide = ss.createSlide();
Dimension pgsize = ss.getPageSize();
HSLFGroupShape group = new HSLFGroupShape();
group.setAnchor(new Rectangle2D.Double(0, 0, pgsize.getWidth(), pgsize.getHeight()));
slide.addShape(group);
HSLFPictureData data = ss.addPicture(_slTests.readFile("clock.jpg"), PictureType.JPEG);
HSLFPictureShape pict = new HSLFPictureShape(data, group);
pict.setAnchor(new Rectangle2D.Double(0, 0, 200, 200));
group.addShape(pict);
HSLFLine line = new HSLFLine(group);
line.setAnchor(new Rectangle2D.Double(300, 300, 500, 0));
group.addShape(line);
//serialize and read again.
ByteArrayOutputStream out = new ByteArrayOutputStream();
ss.write(out);
out.close();
ss.close();
ByteArrayInputStream is = new ByteArrayInputStream(out.toByteArray());
ss = new HSLFSlideShow(is);
is.close();
slide = ss.getSlides().get(0);
List<HSLFShape> shape = slide.getShapes();
assertEquals(1, shape.size());
assertTrue(shape.get(0) instanceof HSLFGroupShape);
group = (HSLFGroupShape) shape.get(0);
List<HSLFShape> grshape = group.getShapes();
assertEquals(2, grshape.size());
assertTrue(grshape.get(0) instanceof HSLFPictureShape);
assertTrue(grshape.get(1) instanceof HSLFLine);
pict = (HSLFPictureShape) grshape.get(0);
assertEquals(new Rectangle2D.Double(0, 0, 200, 200), pict.getAnchor());
line = (HSLFLine) grshape.get(1);
assertEquals(new Rectangle2D.Double(300, 300, 500, 0), line.getAnchor());
ss.close();
}
Aggregations