org.apache.poi.xslf.usermodel.XMLSlideShow Java Examples
The following examples show how to use
org.apache.poi.xslf.usermodel.XMLSlideShow.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WatermarkPptTests.java From kbase-doc with Apache License 2.0 | 6 votes |
@Test public void test1() throws IOException { // create a ppt XMLSlideShow ppt = new XMLSlideShow(new FileInputStream("E:\\ConvertTester\\ppt\\看看addThread方法的源码.pptx")); XSLFPictureData pd = ppt.addPicture(new File("E:\\ConvertTester\\images\\jshrss-logo.png"), PictureType.PNG); for (int i=0;i<ppt.getSlideMasters().size();i++) { XSLFSlideMaster slideMaster = ppt.getSlideMasters().get(i); XSLFSlideLayout[] slideLayouts = slideMaster.getSlideLayouts(); for (XSLFSlideLayout slidelayout : slideLayouts) { XSLFPictureShape ps = slidelayout.createPicture(pd); ps.setAnchor(new Rectangle2D.Double(20, 20, 640, 400)); } } FileOutputStream fos = new FileOutputStream("E:\\ConvertTester\\ppt\\bla.pptx"); ppt.write(fos); fos.close(); // XSLFSlide sl = ppt.createSlide(slidelayout); // ((XSLFAutoShape)sl.getShapes().get(0)).setText("title"); // ((XSLFAutoShape)sl.getShapes().get(1)).setText("content"); }
Example #2
Source File: PPTUtil.java From SpringMVC-Project with MIT License | 6 votes |
/** * 转换2007版(.pptx)格式的PPT文件为图片 */ private static List<String> convertPPT2007ToImages(String pptFilePath, String imageFolderPath) throws IOException { List<String> imagePathList = Lists.newArrayList(); FileInputStream fis = new FileInputStream(pptFilePath); XMLSlideShow ppt = new XMLSlideShow(fis); fis.close(); Dimension dimension = ppt.getPageSize(); List<XSLFSlide> slideList = ppt.getSlides(); int index = 0; for (XSLFSlide slide : slideList) { logger.info("正在转换PPT第" + (++index) + "页"); File imageFile = new File(imageFolderPath + "/" + (index) + ".png"); convertSlideToImage(slide, dimension, imageFile); imagePathList.add(imageFile.getAbsolutePath()); } return imagePathList; }
Example #3
Source File: TextParserImpl.java From tephra with MIT License | 6 votes |
@Override public boolean parse(XMLSlideShow xmlSlideShow, XSLFSlide xslfSlide, JSONObject object) { XSLFTextBox xslfTextBox = xslfSlide.createTextBox(); xslfTextBox.clearText(); xslfTextBox.setInsets(new Insets2D(0.0D, 0.0D, 0.0D, 0.0D)); xslfTextBox.setAnchor(parserHelper.getRectangle(object)); parserHelper.rotate(xslfTextBox, object); XSLFTextParagraph xslfTextParagraph = newParagraph(xslfTextBox, object); if (object.containsKey("texts")) { JSONArray texts = object.getJSONArray("texts"); for (int i = 0, size = texts.size(); i < size; i++) xslfTextParagraph = add(xslfTextBox, xslfTextParagraph, object, texts.getJSONObject(i)); } else if (object.containsKey(getType())) add(xslfTextBox, xslfTextParagraph, object, new JSONObject()); return true; }
Example #4
Source File: SvgParserImpl.java From tephra with MIT License | 6 votes |
@Override public boolean parse(XMLSlideShow xmlSlideShow, XSLFSlide xslfSlide, JSONObject object) { try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { if (!image.svg2png(object.getString("svg"), object.getIntValue("width"), object.getIntValue("height"), outputStream)) return false; XSLFPictureData xslfPictureData = xmlSlideShow.addPicture( parserHelper.getImage(object, "image/png", outputStream), PictureData.PictureType.PNG); parse(xslfSlide, xslfPictureData, object); return true; } catch (Throwable e) { logger.warn(e, "解析SVG图片[{}]时发生异常!", object.toJSONString()); return false; } }
Example #5
Source File: PptTemplates.java From PPT-Templates with Apache License 2.0 | 6 votes |
/** * Handles shape modification * @return true is the shape should be removed */ private static boolean processShape(XSLFShape shape, List<ImageToReplace> imagesToReplace, XMLSlideShow ppt, PptMapper mapper) { if(shape instanceof XSLFTextShape) { return processTextShape((XSLFTextShape) shape, mapper); } if(shape instanceof XSLFTable) { return processTableShape((XSLFTable) shape, mapper); } if(shape instanceof XSLFPictureShape) { return processImageShape((XSLFPictureShape) shape, imagesToReplace, mapper); } if(shape instanceof XSLFGroupShape) { return processGroupShape((XSLFGroupShape) shape, ppt, mapper); } return false; }
Example #6
Source File: PptxReaderImpl.java From tephra with MIT License | 6 votes |
@Override public JSONObject read(InputStream inputStream, MediaWriter mediaWriter) { JSONObject object = new JSONObject(); try (XMLSlideShow xmlSlideShow = new XMLSlideShow(inputStream)) { parseSize(xmlSlideShow, object); ReaderContext readerContext = new ReaderContext(mediaWriter, xmlSlideShow); Map<String, Map<Integer, String>> layouts = new HashMap<>(); JSONArray slides = new JSONArray(); xmlSlideShow.getSlides().forEach(xslfSlide -> { readerContext.setXslfSlide(xslfSlide); JSONObject slide = new JSONObject(); parseSlide(readerContext, slide, parseLayout(readerContext, layouts)); slides.add(slide); }); object.put("slides", slides); inputStream.close(); } catch (Exception e) { logger.warn(e, "读取PPTX数据时发生异常!"); } return object; }
Example #7
Source File: PowerPointOOXMLDocument.java From olat with Apache License 2.0 | 6 votes |
private void extractContent(final StringBuilder buffy, final XMLSlideShow xmlSlideShow) throws IOException, XmlException { final XSLFSlide[] slides = xmlSlideShow.getSlides(); for (final XSLFSlide slide : slides) { final CTSlide rawSlide = slide._getCTSlide(); final CTSlideIdListEntry slideId = slide._getCTSlideId(); final CTNotesSlide notes = xmlSlideShow._getXSLFSlideShow().getNotes(slideId); final CTCommentList comments = xmlSlideShow._getXSLFSlideShow().getSlideComments(slideId); extractShapeContent(buffy, rawSlide.getCSld().getSpTree()); if (comments != null) { for (final CTComment comment : comments.getCmArray()) { buffy.append(comment.getText()).append(' '); } } if (notes != null) { extractShapeContent(buffy, notes.getCSld().getSpTree()); } } }
Example #8
Source File: PptTemplates.java From PPT-Templates with Apache License 2.0 | 6 votes |
private static void processShapesContainer(ShapeContainer<XSLFShape, ?> shapeContainer, XMLSlideShow ppt, PptMapper mapper) { List<ImageToReplace> imagesToReplace = new ArrayList<>(); List<XSLFShape> shapesToDelete = new ArrayList<>(); for(XSLFShape shape : shapeContainer.getShapes()) { if(processShape(shape, imagesToReplace, ppt, mapper)) { shapesToDelete.add(shape); } } for(XSLFShape shapeToDelete : shapesToDelete) { shapeContainer.removeShape(shapeToDelete); } for(ImageToReplace imageToReplace : imagesToReplace) { replaceImage(ppt, shapeContainer, imageToReplace); } }
Example #9
Source File: PowerPointExportServiceTest.java From find with MIT License | 5 votes |
@Test public void report() throws Exception { final ReportData data = mock(ReportData.class); final boolean multiPage = true; when(powerPointService.report(data, multiPage)).thenReturn(new XMLSlideShow()); powerPointExportService.report(new ByteArrayOutputStream(), data, multiPage); verify(powerPointService).report(data, multiPage); }
Example #10
Source File: PptParserTest.java From PPT-Templates with Apache License 2.0 | 5 votes |
@Test public void two_variables_in_the_same_textun_should_be_correctly_replaced() throws IOException { try(XMLSlideShow ppt = new XMLSlideShow(PptParserTest.class.getResourceAsStream("/parser/variables_same_textrun.pptx"))) { XSLFTextParagraph paragraph = firstParagraph(ppt); PptParser.replaceTextVariable(paragraph, new PptMapper().text("var1", "value1").text("var2", "value2")); assertThat(paragraph.getText()).isEqualTo("value1 value2"); } }
Example #11
Source File: PptParserTest.java From PPT-Templates with Apache License 2.0 | 5 votes |
@Test public void two_variables_mixed_in_the_same_textun_should_be_correctly_replaced() throws IOException { try(XMLSlideShow ppt = new XMLSlideShow(PptParserTest.class.getResourceAsStream("/parser/variables_mixed_textrun.pptx"))) { XSLFTextParagraph paragraph = firstParagraph(ppt); PptParser.replaceTextVariable(paragraph, new PptMapper().text("var1", "value1").text("var2", "value2")); assertThat(paragraph.getText()).isEqualTo("value1 value2"); } }
Example #12
Source File: PptParserTest.java From PPT-Templates with Apache License 2.0 | 5 votes |
@Test public void a_variable_with_an_argument_should_be_correctly_replaced() throws IOException { try(XMLSlideShow ppt = new XMLSlideShow(PptParserTest.class.getResourceAsStream("/parser/variable_with_argument.pptx"))) { XSLFTextParagraph paragraph = firstParagraph(ppt); PptParser.replaceTextVariable(paragraph, new PptMapper().text("var", arg -> "Got argument : " + arg)); assertThat(paragraph.getText()).isEqualTo("Got argument : arg"); } }
Example #13
Source File: PptParserTest.java From PPT-Templates with Apache License 2.0 | 5 votes |
@Test public void space_with_content_before_variable_should_not_be_erased() throws IOException { try(XMLSlideShow ppt = new XMLSlideShow(PptParserTest.class.getResourceAsStream("/parser/space_with_content_before_variable.pptx"))) { XSLFTextParagraph paragraph = firstParagraph(ppt); PptParser.replaceTextVariable(paragraph, new PptMapper().text("var", "value")); assertThat(paragraph.getText()).isEqualTo("Some content: (value)"); } }
Example #14
Source File: PowerPointExportServiceTest.java From find with MIT License | 5 votes |
@Test public void topicMap() throws Exception { final TopicMapData data = mock(TopicMapData.class); when(powerPointService.topicmap(data)).thenReturn(new XMLSlideShow()); powerPointExportService.topicMap(new ByteArrayOutputStream(), data); verify(powerPointService).topicmap(data); }
Example #15
Source File: PowerPointExportServiceTest.java From find with MIT License | 5 votes |
@Test public void sunburst() throws Exception { final SunburstData data = mock(SunburstData.class); when(powerPointService.sunburst(data)).thenReturn(new XMLSlideShow()); powerPointExportService.sunburst(new ByteArrayOutputStream(), data); verify(powerPointService).sunburst(data); }
Example #16
Source File: PowerPointExportServiceTest.java From find with MIT License | 5 votes |
@Test public void table() throws Exception { final TableData data = mock(TableData.class); final String title = "A title"; when(powerPointService.table(data, title)).thenReturn(new XMLSlideShow()); powerPointExportService.table(new ByteArrayOutputStream(), data, title); verify(powerPointService).table(data, title); }
Example #17
Source File: PowerPointExportServiceTest.java From find with MIT License | 5 votes |
@Test public void map() throws Exception { final MapData data = mock(MapData.class); final String title = "A title"; when(powerPointService.map(data, title)).thenReturn(new XMLSlideShow()); powerPointExportService.map(new ByteArrayOutputStream(), data, title); verify(powerPointService).map(data, title); }
Example #18
Source File: PowerPointExportServiceTest.java From find with MIT License | 5 votes |
@Test public void list() throws Exception { final ListData data = mock(ListData.class); when(powerPointService.list(data, null, null)).thenReturn(new XMLSlideShow()); powerPointExportService.list(new ByteArrayOutputStream(), data, null, null); verify(powerPointService).list(data, null, null); }
Example #19
Source File: PowerPointExportServiceTest.java From find with MIT License | 5 votes |
@Test public void dateGraph() throws Exception { final DategraphData data = mock(DategraphData.class); when(powerPointService.graph(data)).thenReturn(new XMLSlideShow()); powerPointExportService.dateGraph(new ByteArrayOutputStream(), data); verify(powerPointService).graph(data); }
Example #20
Source File: PptParserTest.java From PPT-Templates with Apache License 2.0 | 5 votes |
@Test public void no_variable_content_should_be_untouched() throws IOException { try(XMLSlideShow ppt = new XMLSlideShow(PptParserTest.class.getResourceAsStream("/parser/simple_multi_lines.pptx"))) { XSLFTextParagraph paragraph = firstParagraph(ppt); PptParser.replaceTextVariable(paragraph, new PptMapper()); assertThat(paragraph.getText()).isEqualTo("Text on multiple text runs"); } }
Example #21
Source File: ConvertPPTX2PNG.java From opencards with BSD 2-Clause "Simplified" License | 5 votes |
public static void main(String[] args) throws IOException, InvalidFormatException { FileInputStream is = new FileInputStream("/Users/brandl/Dropbox/private/oc2/testdata/experimental design.pptx"); XMLSlideShow ppt2 = new XMLSlideShow(OPCPackage.open("/Users/brandl/Dropbox/private/oc2/testdata/experimental design.pptx")); XSLFSlide slide1 = ppt2.getSlides().get(0); // slide1.get HSLFSlideShow ppt = new HSLFSlideShow(is); // HSLFSlide slide2 = ppt.getSlides().get(1); is.close(); Dimension pgsize = ppt.getPageSize(); java.util.List<HSLFSlide> slides = ppt.getSlides(); for (int i = 0; i < slides.size(); i++) { BufferedImage img = new BufferedImage(pgsize.width, pgsize.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); //clear the drawing area graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, pgsize.width, pgsize.height)); //render slides.get(i).draw(graphics); //save the output FileOutputStream out = new FileOutputStream("slide-" + (i + 1) + ".png"); javax.imageio.ImageIO.write(img, "png", out); out.close(); } }
Example #22
Source File: MSPowerpointIndexerTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test(expected = SolrException.class) public void testShouldThrowExceptionWhenFailToReadFile() throws Exception { PowerMockito.whenNew(POIFSFileSystem.class).withParameterTypes(InputStream.class) .withArguments(Mockito.any(InputStream.class)) .thenThrow(OfficeXmlFileException.class); PowerMockito.whenNew(XMLSlideShow.class).withParameterTypes(InputStream.class) .withArguments(Mockito.any()) .thenThrow(IOException.class); // SolrException is expected MSPowerpointIndexer indexer = new MSPowerpointIndexer(); indexer.getIndexedDocument(file2Index); }
Example #23
Source File: PptxToPDFConverter.java From docs-to-pdf-converter with MIT License | 5 votes |
protected Dimension processSlides() throws IOException{ InputStream iStream = inStream; XMLSlideShow ppt = new XMLSlideShow(iStream); Dimension dimension = ppt.getPageSize(); slides = ppt.getSlides(); return dimension; }
Example #24
Source File: PowerPointIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void whenReadingAPresentation_thenOK() throws Exception { XMLSlideShow xmlSlideShow = pph.readingExistingSlideShow(fileLocation); Assert.assertNotNull(xmlSlideShow); Assert.assertEquals(4, xmlSlideShow.getSlides().size()); }
Example #25
Source File: PowerPointIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void whenRetrievingThePlaceholdersForEachSlide_thenOK() throws Exception { XMLSlideShow xmlSlideShow = pph.readingExistingSlideShow(fileLocation); List<XSLFShape> onlyTitleSlidePlaceholders = pph.retrieveTemplatePlaceholders(xmlSlideShow.getSlides().get(0)); List<XSLFShape> titleAndBodySlidePlaceholders = pph.retrieveTemplatePlaceholders(xmlSlideShow.getSlides().get(1)); List<XSLFShape> emptySlidePlaceholdes = pph.retrieveTemplatePlaceholders(xmlSlideShow.getSlides().get(3)); Assert.assertEquals(1, onlyTitleSlidePlaceholders.size()); Assert.assertEquals(2, titleAndBodySlidePlaceholders.size()); Assert.assertEquals(0, emptySlidePlaceholdes.size()); }
Example #26
Source File: PowerPointIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void whenSortingSlides_thenOK() throws Exception { XMLSlideShow xmlSlideShow = pph.readingExistingSlideShow(fileLocation); XSLFSlide slide4 = xmlSlideShow.getSlides().get(3); pph.reorderSlide(xmlSlideShow, 3, 1); Assert.assertEquals(slide4, xmlSlideShow.getSlides().get(1)); }
Example #27
Source File: PowerPointIntegrationTest.java From tutorials with MIT License | 5 votes |
@Test public void givenPresentation_whenDeletingASlide_thenOK() throws Exception { XMLSlideShow xmlSlideShow = pph.readingExistingSlideShow(fileLocation); pph.deleteSlide(xmlSlideShow, 3); Assert.assertEquals(3, xmlSlideShow.getSlides().size()); }
Example #28
Source File: PptParserTest.java From PPT-Templates with Apache License 2.0 | 5 votes |
@Test public void variable_content_with_no_replacement_should_be_untouched() throws IOException { try(XMLSlideShow ppt = new XMLSlideShow(PptParserTest.class.getResourceAsStream("/parser/simple_varName_variable.pptx"))) { XSLFTextParagraph paragraph = firstParagraph(ppt); PptParser.replaceTextVariable(paragraph, new PptMapper()); assertThat(paragraph.getText()).isEqualTo("Text with a var: $/varName/"); } }
Example #29
Source File: BackgroundParserImpl.java From tephra with MIT License | 5 votes |
@Override public boolean parse(XMLSlideShow xmlSlideShow, XSLFSlide xslfSlide, JSONObject object) { if (!object.containsKey("color")) return false; xslfSlide.getXmlObject().getCSld().addNewBg(); xslfSlide.getBackground().setFillColor(parserHelper.getColor(object, "color")); return true; }
Example #30
Source File: PptxReaderImpl.java From tephra with MIT License | 5 votes |
private void parseSize(XMLSlideShow xmlSlideShow, JSONObject object) { JSONObject size = new JSONObject(); Dimension dimension = xmlSlideShow.getPageSize(); size.put("width", officeHelper.pointToPixel(dimension.width)); size.put("height", officeHelper.pointToPixel(dimension.height)); object.put("size", size); }