use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class LoadEmbedded method loadEmbedded.
public static void loadEmbedded(XSSFWorkbook workbook) throws IOException, InvalidFormatException, OpenXML4JException, XmlException {
for (PackagePart pPart : workbook.getAllEmbedds()) {
String contentType = pPart.getContentType();
if (contentType.equals("application/vnd.ms-excel")) {
// Excel Workbook - either binary or OpenXML
HSSFWorkbook embeddedWorkbook = new HSSFWorkbook(pPart.getInputStream());
embeddedWorkbook.close();
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
// Excel Workbook - OpenXML file format
XSSFWorkbook embeddedWorkbook = new XSSFWorkbook(pPart.getInputStream());
embeddedWorkbook.close();
} else if (contentType.equals("application/msword")) {
// Word Document - binary (OLE2CDF) file format
HWPFDocument document = new HWPFDocument(pPart.getInputStream());
document.close();
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
// Word Document - OpenXML file format
XWPFDocument document = new XWPFDocument(pPart.getInputStream());
document.close();
} else if (contentType.equals("application/vnd.ms-powerpoint")) {
// PowerPoint Document - binary file format
HSLFSlideShow slideShow = new HSLFSlideShow(pPart.getInputStream());
slideShow.close();
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
// PowerPoint Document - OpenXML file format
XMLSlideShow slideShow = new XMLSlideShow(pPart.getInputStream());
slideShow.close();
} else {
// Any other type of embedded object.
System.out.println("Unknown Embedded Document: " + contentType);
InputStream inputStream = pPart.getInputStream();
inputStream.close();
}
}
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class EmbeddedObjects method main.
public static void main(String[] args) throws Exception {
XSSFWorkbook workbook = new XSSFWorkbook(args[0]);
for (PackagePart pPart : workbook.getAllEmbedds()) {
String contentType = pPart.getContentType();
InputStream is = pPart.getInputStream();
Closeable document;
if (contentType.equals("application/vnd.ms-excel")) {
// Excel Workbook - either binary or OpenXML
document = new HSSFWorkbook(is);
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
// Excel Workbook - OpenXML file format
document = new XSSFWorkbook(is);
} else if (contentType.equals("application/msword")) {
// Word Document - binary (OLE2CDF) file format
document = new HWPFDocument(is);
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document")) {
// Word Document - OpenXML file format
document = new XWPFDocument(is);
} else if (contentType.equals("application/vnd.ms-powerpoint")) {
// PowerPoint Document - binary file format
document = new HSLFSlideShow(is);
} else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
// PowerPoint Document - OpenXML file format
document = new XMLSlideShow(is);
} else {
// Any other type of embedded object.
document = is;
}
document.close();
is.close();
}
workbook.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestSlideMaster method testIndentation.
/**
* Varify we can read attrubutes for different identtation levels.
* (typical for the "bullted body" placeholder)
*/
@Test
public void testIndentation() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
HSLFSlide slide = ppt.getSlides().get(0);
for (List<HSLFTextParagraph> tparas : slide.getTextParagraphs()) {
HSLFTextParagraph tpara = tparas.get(0);
if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE) {
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(40, rt.getFontSize(), 0);
assertEquals(true, rt.isUnderlined());
assertEquals("Arial", rt.getFontFamily());
} else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE) {
int[] indents = { 32, 28, 24 };
for (HSLFTextRun rt : tpara.getTextRuns()) {
int indent = tpara.getIndentLevel();
assertEquals(indents[indent], rt.getFontSize(), 0);
}
}
}
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestSlideMaster method testMasterAttributes.
/**
* If a style attribute is not set ensure it is read from the master
*/
@Test
public void testMasterAttributes() throws Exception {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
List<HSLFSlide> slide = ppt.getSlides();
assertEquals(3, slide.size());
for (List<HSLFTextParagraph> tparas : slide.get(0).getTextParagraphs()) {
HSLFTextParagraph tpara = tparas.get(0);
if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE) {
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(40, rt.getFontSize(), 0);
assertEquals(true, rt.isUnderlined());
assertEquals("Arial", rt.getFontFamily());
} else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE) {
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(0, tpara.getIndentLevel());
assertEquals(32, rt.getFontSize(), 0);
assertEquals("Arial", rt.getFontFamily());
tpara = tparas.get(1);
rt = tpara.getTextRuns().get(0);
assertEquals(1, tpara.getIndentLevel());
assertEquals(28, rt.getFontSize(), 0);
assertEquals("Arial", rt.getFontFamily());
}
}
for (List<HSLFTextParagraph> tparas : slide.get(1).getTextParagraphs()) {
HSLFTextParagraph tpara = tparas.get(0);
if (tpara.getRunType() == TextHeaderAtom.TITLE_TYPE) {
HSLFTextRun rt = tpara.getTextRuns().get(0);
assertEquals(48, rt.getFontSize(), 0);
assertEquals(true, rt.isItalic());
assertEquals("Georgia", rt.getFontFamily());
} else if (tpara.getRunType() == TextHeaderAtom.BODY_TYPE) {
HSLFTextRun rt;
rt = tpara.getTextRuns().get(0);
assertEquals(0, tpara.getIndentLevel());
assertEquals(32, rt.getFontSize(), 0);
assertEquals("Courier New", rt.getFontFamily());
}
}
ppt.close();
}
use of org.apache.poi.hslf.usermodel.HSLFSlideShow in project poi by apache.
the class TestSlideMaster method testSlideMaster.
/**
* The reference ppt has two masters.
* Check we can read their attributes.
*/
@Test
public void testSlideMaster() throws IOException {
HSLFSlideShow ppt = new HSLFSlideShow(_slTests.openResourceAsStream("slide_master.ppt"));
Environment env = ppt.getDocumentRecord().getEnvironment();
List<HSLFSlideMaster> master = ppt.getSlideMasters();
assertEquals(2, master.size());
//character attributes
assertEquals(40, master.get(0).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.size", true).getValue());
assertEquals(48, master.get(1).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.size", true).getValue());
int font1 = master.get(0).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.index", true).getValue();
int font2 = master.get(1).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "font.index", true).getValue();
assertEquals("Arial", env.getFontCollection().getFontWithId(font1));
assertEquals("Georgia", env.getFontCollection().getFontWithId(font2));
CharFlagsTextProp prop1 = (CharFlagsTextProp) master.get(0).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "char_flags", true);
assertEquals(false, prop1.getSubValue(CharFlagsTextProp.BOLD_IDX));
assertEquals(false, prop1.getSubValue(CharFlagsTextProp.ITALIC_IDX));
assertEquals(true, prop1.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
CharFlagsTextProp prop2 = (CharFlagsTextProp) master.get(1).getStyleAttribute(TextHeaderAtom.TITLE_TYPE, 0, "char_flags", true);
assertEquals(false, prop2.getSubValue(CharFlagsTextProp.BOLD_IDX));
assertEquals(true, prop2.getSubValue(CharFlagsTextProp.ITALIC_IDX));
assertEquals(false, prop2.getSubValue(CharFlagsTextProp.UNDERLINE_IDX));
//now paragraph attributes
assertEquals(0x266B, master.get(0).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.char", false).getValue());
assertEquals(0x2022, master.get(1).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.char", false).getValue());
int b1 = master.get(0).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
int b2 = master.get(1).getStyleAttribute(TextHeaderAtom.BODY_TYPE, 0, "bullet.font", false).getValue();
assertEquals("Arial", env.getFontCollection().getFontWithId(b1));
assertEquals("Georgia", env.getFontCollection().getFontWithId(b2));
ppt.close();
}
Aggregations