/** * Creates a HSLFSlideShow from the given DirectoryNode<p> * Note that in order to properly release resources the * SlideShow should be closed after use. */ public static HSLFSlideShow createSlideShow(final DirectoryNode root) throws IOException { return new HSLFSlideShow(root); } }
/** * Creates a PowerPointExtractor, from a specific place * inside an open NPOIFSFileSystem * * @param dir the POIFS Directory containing the PowerPoint document */ public PowerPointExtractor(DirectoryNode dir) throws IOException { this(new HSLFSlideShow(dir)); }
/** * Creates a HSLFSlideShow from the given NPOIFSFileSystem<p> * Note that in order to properly release resources the * SlideShow should be closed after use. */ public static HSLFSlideShow createSlideShow(final POIFSFileSystem fs) throws IOException { return new HSLFSlideShow(fs); }
/** * Creates a PowerPointExtractor, from a HSLFSlideShow * * @param ss the HSLFSlideShow to extract text from */ public PowerPointExtractor(HSLFSlideShowImpl ss) { this(new HSLFSlideShow(ss)); }
HSLFSlideShow slideShow = new HSLFSlideShow(new HSLFSlideShowImpl(dir)); for (int i = 0; i < 5; i++) { slideShow.removeSlide(0); } FileOutputStream out = new FileOutputStream("changed.ppt"); slideShow.write(out); out.close();
SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt")); //extract all pictures contained in the presentation PictureData[] pdata = ppt.getPictureData(); for (int i = 0; i < pdata.length; i++){ PictureData pict = pdata[i]; // picture data byte[] data = pict.getData(); int type = pict.getType(); String ext; switch (type){ case Picture.JPEG: ext=".jpg"; break; case Picture.PNG: ext=".png"; break; case Picture.WMF: ext=".wmf"; break; case Picture.EMF: ext=".emf"; break; case Picture.PICT: ext=".pict"; break; default: continue; } FileOutputStream out = new FileOutputStream("pict_"+i + ext); out.write(data); out.close(); }
SlideShow ppt = new SlideShow(new HSLFSlideShow("slideshow.ppt")); //extract all pictures contained in the presentation PictureData[] pdata = ppt.getPictureData(); for (int i = 0; i < pdata.length; i++){ PictureData pict = pdata[i]; // picture data byte[] data = pict.getData(); int type = pict.getType(); String ext; switch (type){ case Picture.JPEG: ext=".jpg"; break; case Picture.PNG: ext=".png"; break; case Picture.WMF: ext=".wmf"; break; case Picture.EMF: ext=".emf"; break; case Picture.PICT: ext=".pict"; break; default: continue; } FileOutputStream out = new FileOutputStream("pict_"+i + ext); out.write(data); out.close(); }
public static void main(String[] args) throws Exception { try (HSLFSlideShow ppt = new HSLFSlideShow()) { HSLFSlide slide = ppt.createSlide(); create1stTable(slide); create2ndTable(slide); try (FileOutputStream out = new FileOutputStream("hslf-table.ppt")) { ppt.write(out); } } }
String lowerFilePath = filePath.toLowerCase(); if (lowerFilePath.endsWith(".xls")) { HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(lowerFilePath)); Integer sheetNums = workbook.getNumberOfSheets(); if (sheetNums > 0) { return workbook.getSheetAt(0).getRowBreaks().length + 1; } } else if (lowerFilePath.endsWith(".xlsx")) { XSSFWorkbook xwb = new XSSFWorkbook(lowerFilePath); Integer sheetNums = xwb.getNumberOfSheets(); if (sheetNums > 0) { return xwb.getSheetAt(0).getRowBreaks().length + 1; } } else if (lowerFilePath.endsWith(".docx")) { XWPFDocument docx = new XWPFDocument(POIXMLDocument.openPackage(lowerFilePath)); return docx.getProperties().getExtendedProperties().getUnderlyingProperties().getPages(); } else if (lowerFilePath.endsWith(".doc")) { HWPFDocument wordDoc = new HWPFDocument(new FileInputStream(lowerFilePath)); return wordDoc.getSummaryInformation().getPageCount(); } else if (lowerFilePath.endsWith(".ppt")) { HSLFSlideShow document = new HSLFSlideShow(new FileInputStream(lowerFilePath)); SlideShow slideShow = new SlideShow(document); return slideShow.getSlides().length; } else if (lowerFilePath.endsWith(".pptx")) { XSLFSlideShow xdocument = new XSLFSlideShow(lowerFilePath); XMLSlideShow xslideShow = new XMLSlideShow(xdocument); return xslideShow.getSlides().length; }
} else if (contentType.equals("application/vnd.ms-powerpoint")) { document = new HSLFSlideShow(is); } else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
public static PowerpointMetadata instance( InputStream stream ) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(stream); HSLFSlideShow rawSlideShow = new HSLFSlideShow(fs); List<SlideMetadata> slidesMetadata = rawSlideShow.getSlides() .stream() .map(slide -> processSlide(rawSlideShow, slide)) .collect(Collectors.toList()); PowerpointMetadata deck = new PowerpointMetadata(); deck.setSlides(slidesMetadata); deck.setMetadata(new HSLFSlideShowImpl(fs).getSummaryInformation()); return deck; }
public static void main(String args[]) throws IOException { if (args.length < 1) { System.err.println("Usage:"); System.err.println("\tImageExtractor <file>"); return; } HSLFSlideShow ppt = new HSLFSlideShow(new HSLFSlideShowImpl(args[0])); //extract all pictures contained in the presentation int i = 0; for (HSLFPictureData pict : ppt.getPictureData()) { // picture data byte[] data = pict.getData(); PictureType type = pict.getType(); FileOutputStream out = new FileOutputStream("pict_" + i++ + type.extension); out.write(data); out.close(); } ppt.close(); } }
public static PowerpointMetadata instance( InputStream stream ) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(stream); HSLFSlideShow rawSlideShow = new HSLFSlideShow(fs); List<SlideMetadata> slidesMetadata = rawSlideShow.getSlides() .stream() .map(slide -> processSlide(rawSlideShow, slide)) .collect(Collectors.toList()); PowerpointMetadata deck = new PowerpointMetadata(); deck.setSlides(slidesMetadata); deck.setMetadata(new HSLFSlideShowImpl(fs).getSummaryInformation()); return deck; }
public static void main(String[] args) throws IOException { try (FileInputStream fis = new FileInputStream(args[0])) { try (HSLFSlideShow ppt = new HSLFSlideShow(fis)) { HSLFSoundData[] sounds = ppt.getSoundData(); for (HSLFSlide slide : ppt.getSlides()) { for (HSLFShape shape : slide.getShapes()) { int soundRef = getSoundReference(shape); if (soundRef == -1) continue; System.out.println("Slide[" + slide.getSlideNumber() + "], shape[" + shape.getShapeId() + "], soundRef: " + soundRef); System.out.println(" " + sounds[soundRef].getSoundName()); System.out.println(" " + sounds[soundRef].getSoundType()); } } } } }
} else if (contentType.equals("application/vnd.ms-powerpoint")) { HSLFSlideShow slideShow = new HSLFSlideShow(pPart.getInputStream()); slideShow.close(); } else if (contentType.equals("application/vnd.openxmlformats-officedocument.presentationml.presentation")) {
ss = new HSLFSlideShow(root); } catch (EncryptedPowerPointFileException e) { throw new EncryptedDocumentException(e);
public static void main(String[] args) throws IOException { try (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"; try (FileOutputStream out = new FileOutputStream("apachecon_eu_08." + ext)) { ppt.write(out); } } }
public static void main(String[] args) throws IOException { try (HSLFSlideShow ppt = new HSLFSlideShow()) { 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(); try (FileOutputStream out = new FileOutputStream("headers_footers.ppt")) { ppt.write(out); } } }
public static void main(String[] args) throws IOException { try (HSLFSlideShow ppt = new HSLFSlideShow()) { HSLFSlide slideA = ppt.createSlide(); ppt.createSlide(); HSLFSlide slideC = ppt.createSlide(); // link to a URL HSLFTextBox textBox1 = slideA.createTextBox(); textBox1.setText("Apache POI"); textBox1.setAnchor(new Rectangle(100, 100, 200, 50)); HSLFHyperlink link1 = textBox1.getTextParagraphs().get(0).getTextRuns().get(0).createHyperlink(); link1.linkToUrl("http://www.apache.org"); link1.setLabel(textBox1.getText()); // link to another slide HSLFTextBox textBox2 = slideA.createTextBox(); textBox2.setText("Go to slide #3"); textBox2.setAnchor(new Rectangle(100, 300, 200, 50)); HSLFHyperlink link2 = textBox2.getTextParagraphs().get(0).getTextRuns().get(0).createHyperlink(); link2.linkToSlide(slideC); try (FileOutputStream out = new FileOutputStream("hyperlink.ppt")) { ppt.write(out); } } } }
public static void main(String[] args) throws IOException { try (HSLFSlideShow ppt = new HSLFSlideShow()) { HSLFSlide slide = ppt.createSlide(); HSLFTextBox shape = new HSLFTextBox(); HSLFTextParagraph rt = shape.getTextParagraphs().get(0); rt.getTextRuns().get(0).setFontSize(42d); rt.setBullet(true); rt.setIndent(0d); //bullet offset rt.setLeftMargin(50d); //text offset (should be greater than bullet offset) rt.setBulletChar('\u263A'); //bullet character shape.setText( "January\r" + "February\r" + "March\r" + "April"); slide.addShape(shape); shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300)); //position of the text box in the slide slide.addShape(shape); try (FileOutputStream out = new FileOutputStream("bullets.ppt")) { ppt.write(out); } } } }