use of org.apache.poi.hslf.model.HeadersFooters in project poi by apache.
the class HeadersFootersDemo method main.
public static void main(String[] args) throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow();
try {
HeadersFooters slideHeaders = ppt.getSlideHeadersFooters();
slideHeaders.setFootersText("Created by POI-HSLF");
slideHeaders.setSlideNumberVisible(true);
slideHeaders.setDateTimeText("custom date time");
HeadersFooters notesHeaders = ppt.getNotesHeadersFooters();
notesHeaders.setFootersText("My notes footers");
notesHeaders.setHeaderText("My notes header");
ppt.createSlide();
FileOutputStream out = new FileOutputStream("headers_footers.ppt");
ppt.write(out);
out.close();
} finally {
ppt.close();
}
}
use of org.apache.poi.hslf.model.HeadersFooters in project poi by apache.
the class HSLFSlide method getDisplayPlaceholder.
@Override
public boolean getDisplayPlaceholder(Placeholder placeholder) {
HeadersFooters hf = getHeadersFooters();
SlideLayoutType slt = getSlideRecord().getSlideAtom().getSSlideLayoutAtom().getGeometryType();
boolean isTitle = (slt == SlideLayoutType.TITLE_SLIDE || slt == SlideLayoutType.TITLE_ONLY || slt == SlideLayoutType.MASTER_TITLE);
if (hf != null) {
switch(placeholder) {
case DATETIME:
return hf.isDateTimeVisible() && !isTitle;
case SLIDE_NUMBER:
return hf.isSlideNumberVisible() && !isTitle;
case HEADER:
return hf.isHeaderVisible() && !isTitle;
case FOOTER:
return hf.isFooterVisible() && !isTitle;
default:
break;
}
}
return false;
}
use of org.apache.poi.hslf.model.HeadersFooters in project poi by apache.
the class TestBugs method bug58159.
@Test
public void bug58159() throws IOException {
HSLFSlideShow ppt = open("bug58159_headers-and-footers.ppt");
HeadersFooters hf = ppt.getSlideHeadersFooters();
assertNull(hf.getHeaderText());
assertEquals("Slide footer", hf.getFooterText());
hf = ppt.getNotesHeadersFooters();
assertEquals("Notes header", hf.getHeaderText());
assertEquals("Notes footer", hf.getFooterText());
HSLFSlide sl = ppt.getSlides().get(0);
hf = sl.getHeadersFooters();
assertNull(hf.getHeaderText());
assertEquals("Slide footer", hf.getFooterText());
for (HSLFShape shape : sl.getShapes()) {
if (shape instanceof HSLFTextShape) {
HSLFTextShape ts = (HSLFTextShape) shape;
Placeholder ph = ts.getPlaceholder();
if (Placeholder.FOOTER == ph) {
assertEquals("Slide footer", ts.getText());
}
}
}
ppt.close();
}
use of org.apache.poi.hslf.model.HeadersFooters 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.model.HeadersFooters in project poi by apache.
the class TestHeadersFooters method bug58144b.
@Test
public void bug58144b() throws IOException {
assumeFalse(xslfOnly);
SlideShow<?, ?> ppt = openSampleSlideshow("bug58144-headers-footers-2007.ppt");
Slide<?, ?> sl = ppt.getSlides().get(0);
HeadersFooters hfs2 = ((HSLFSlide) sl).getHeadersFooters();
assertNull(hfs2.getHeaderText());
assertEquals("Slide footer", hfs2.getFooterText());
testSlideShow(ppt);
ppt.close();
}
Aggregations