use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.
the class XSLFFileHandler method handleFile.
@Override
public void handleFile(InputStream stream, String path) throws Exception {
XMLSlideShow slide = new XMLSlideShow(stream);
XSLFSlideShow slideInner = new XSLFSlideShow(slide.getPackage());
assertNotNull(slideInner.getPresentation());
assertNotNull(slideInner.getSlideMasterReferences());
assertNotNull(slideInner.getSlideReferences());
new POIXMLDocumentHandler().handlePOIXMLDocument(slide);
handleSlideShow(slide);
slideInner.close();
slide.close();
}
use of org.apache.poi.xslf.usermodel.XMLSlideShow 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.xslf.usermodel.XMLSlideShow in project poi by apache.
the class Step1 method main.
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("Input file is required");
return;
}
FileInputStream fis = new FileInputStream(args[0]);
XMLSlideShow ppt = new XMLSlideShow(fis);
fis.close();
for (XSLFSlide slide : ppt.getSlides()) {
System.out.println("Title: " + slide.getTitle());
for (XSLFShape shape : slide.getShapes()) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape tsh = (XSLFTextShape) shape;
for (XSLFTextParagraph p : tsh) {
System.out.println("Paragraph level: " + p.getIndentLevel());
for (XSLFTextRun r : p) {
System.out.println(r.getRawText());
System.out.println(" bold: " + r.isBold());
System.out.println(" italic: " + r.isItalic());
System.out.println(" underline: " + r.isUnderlined());
System.out.println(" font.family: " + r.getFontFamily());
System.out.println(" font.size: " + r.getFontSize());
System.out.println(" font.color: " + r.getFontColor());
}
}
}
}
}
ppt.close();
}
use of org.apache.poi.xslf.usermodel.XMLSlideShow in project poi by apache.
the class Step2 method main.
public static void main(String[] args) throws Exception {
XMLSlideShow ppt = new XMLSlideShow();
// first see what slide layouts are available by default
System.out.println("Available slide layouts:");
for (XSLFSlideMaster master : ppt.getSlideMasters()) {
for (XSLFSlideLayout layout : master.getSlideLayouts()) {
System.out.println(layout.getType());
}
}
// blank slide
/*XSLFSlide blankSlide =*/
ppt.createSlide();
XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0);
// title slide
XSLFSlideLayout titleLayout = defaultMaster.getLayout(SlideLayout.TITLE);
XSLFSlide slide1 = ppt.createSlide(titleLayout);
XSLFTextShape title1 = slide1.getPlaceholder(0);
title1.setText("First Title");
// title and content
XSLFSlideLayout titleBodyLayout = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT);
XSLFSlide slide2 = ppt.createSlide(titleBodyLayout);
XSLFTextShape title2 = slide2.getPlaceholder(0);
title2.setText("Second Title");
XSLFTextShape body2 = slide2.getPlaceholder(1);
// unset any existing text
body2.clearText();
body2.addNewTextParagraph().addNewTextRun().setText("First paragraph");
body2.addNewTextParagraph().addNewTextRun().setText("Second paragraph");
body2.addNewTextParagraph().addNewTextRun().setText("Third paragraph");
FileOutputStream out = new FileOutputStream("step2.pptx");
ppt.write(out);
out.close();
ppt.close();
}
use of org.apache.poi.xslf.usermodel.XMLSlideShow 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();
}
Aggregations