org.apache.poi.xslf.usermodel.XSLFSlide Java Examples
The following examples show how to use
org.apache.poi.xslf.usermodel.XSLFSlide.
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: 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 #2
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 #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: 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 #6
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 #7
Source File: PptTemplates.java From PPT-Templates with Apache License 2.0 | 5 votes |
private static XSLFSlide findCurrentSlide(POIXMLDocumentPart containerDocument) { while(containerDocument != null) { if(containerDocument instanceof XSLFSlide) { return (XSLFSlide) containerDocument; } if(containerDocument instanceof XMLSlideShow) { return null; } containerDocument = containerDocument.getParent(); } return null; }
Example #8
Source File: PptTemplates.java From PPT-Templates with Apache License 2.0 | 5 votes |
private static boolean canRelationBeRemoved(POIXMLDocumentPart containerDocument, String relationId) { XSLFSlide currentSlide = findCurrentSlide(containerDocument); if(currentSlide == null) { // this case where a containerDocument in not part of a slide should not append, // but in doubt we don't allow relation to be changed here return false; } return StringUtils.countMatches(currentSlide.getXmlObject().toString(), "r:embed=\""+relationId+"\"") < 2; }
Example #9
Source File: ImageParserSupport.java From tephra with MIT License | 5 votes |
void parse(XSLFSlide xslfSlide, XSLFPictureData xslfPictureData, JSONObject object) { if (!object.containsKey("alpha")) { parseImage(xslfSlide, xslfPictureData, object); return; } double alpha = object.getDoubleValue("alpha"); if (alpha >= 1.0D) { parseImage(xslfSlide, xslfPictureData, object); return; } PackagePart packagePart = xslfPictureData.getPackagePart(); POIXMLDocumentPart.RelationPart relationPart = xslfSlide.addRelation(null, XSLFRelation.IMAGES, new XSLFPictureData(packagePart)); XSLFAutoShape xslfAutoShape = xslfSlide.createAutoShape(); CTShape ctShape = (CTShape) xslfAutoShape.getXmlObject(); CTBlipFillProperties ctBlipFillProperties = ctShape.getSpPr().addNewBlipFill(); CTBlip ctBlip = ctBlipFillProperties.addNewBlip(); ctBlip.setEmbed(relationPart.getRelationship().getId()); ctBlip.setCstate(STBlipCompression.PRINT); ctBlip.addNewAlphaModFix().setAmt(numeric.toInt(alpha * 100000)); ctBlipFillProperties.addNewSrcRect(); ctBlipFillProperties.addNewStretch().addNewFillRect(); xslfAutoShape.setAnchor(parserHelper.getRectangle(object)); parserHelper.rotate(xslfAutoShape, object); }
Example #10
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 #11
Source File: PresentationSlide.java From Quelea with GNU General Public License v3.0 | 5 votes |
/** * Create a new presentation slide. * * @param slide the underlying apache POI slide. */ public PresentationSlide(XSLFSlide slide, int numSlide) { org.apache.poi.xslf.usermodel.XMLSlideShow slideshow = slide.getSlideShow(); if (Math.abs(slideshow.getPageSize().getHeight() - HEIGHT) > 0.1) { int adjustHeight = HEIGHT; int adjustWidth = (int) ((adjustHeight / slideshow.getPageSize().getHeight()) * slideshow.getPageSize().getWidth()); scaleWidth = (double) adjustWidth / slideshow.getPageSize().getWidth(); scaleHeight = (double) adjustHeight / slideshow.getPageSize().getHeight(); slideshow.setPageSize(new Dimension(adjustWidth, adjustHeight)); } BufferedImage originalImage = new BufferedImage((int) slideshow.getPageSize().getWidth(), (int) slideshow.getPageSize().getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = originalImage.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); try { g2.setTransform(AffineTransform.getScaleInstance(scaleWidth, scaleHeight)); slide.draw(g2); } catch (NullPointerException ex) { if (QueleaProperties.get().getUsePP()) { LOGGER.log(Level.INFO, "Couldn't use library to generate thumbnail, using default"); draw(g2, originalImage.getWidth(), originalImage.getHeight(), numSlide); } else { throw ex; } } image = new WritableImage(originalImage.getWidth(), originalImage.getHeight()); SwingFXUtils.toFXImage(originalImage, image); }
Example #12
Source File: PPTXPresentation.java From Quelea with GNU General Public License v3.0 | 5 votes |
/** * Make the slides that go in this presentation, this is what takes time and * should only be done once. * * @return all the slides. */ private PresentationSlide[] makeSlides() { List<XSLFSlide> lSlides = slideshow.getSlides(); ArrayList<PresentationSlide> ret = new ArrayList<>(); for (int i = 0; i < lSlides.size(); i++) { if (lSlides.get(i) != null) { ret.add(new PresentationSlide(lSlides.get(i), i + 1)); } } return ret.toArray(new PresentationSlide[ret.size()]); }
Example #13
Source File: ImageParserSupport.java From tephra with MIT License | 4 votes |
private void parseImage(XSLFSlide xslfSlide, XSLFPictureData xslfPictureData, JSONObject object) { XSLFPictureShape xslfPictureShape = xslfSlide.createPicture(xslfPictureData); xslfPictureShape.setAnchor(parserHelper.getRectangle(object)); parserHelper.rotate(xslfPictureShape, object); }
Example #14
Source File: ReaderContext.java From tephra with MIT License | 4 votes |
public XSLFSlide getXslfSlide() { return xslfSlide; }
Example #15
Source File: ReaderContext.java From tephra with MIT License | 4 votes |
public void setXslfSlide(XSLFSlide xslfSlide) { this.xslfSlide = xslfSlide; }
Example #16
Source File: WriterContext.java From tephra with MIT License | 4 votes |
public XSLFSlide getXslfSlide() { return xslfSlide; }
Example #17
Source File: WriterContext.java From tephra with MIT License | 4 votes |
public void setXslfSlide(XSLFSlide xslfSlide) { this.xslfSlide = xslfSlide; }
Example #18
Source File: TableParserImpl.java From tephra with MIT License | 4 votes |
@Override public boolean parse(XMLSlideShow xmlSlideShow, XSLFSlide xslfSlide, JSONObject object) { XSLFTable xslfTable = xslfSlide.createTable(); xslfTable.setAnchor(parserHelper.getRectangle(object)); xslfTable.getCTTable().getTblPr().setTableStyleId("{5940675A-B579-460E-94D1-54222C63F5DA}"); JSONArray rows = object.getJSONObject("table").getJSONArray("rows"); Map<String, Integer> spans = new HashMap<>(); Color borderColor = null; for (int i = 0; i < rows.size(); i++) { XSLFTableRow xslfTableRow = xslfTable.addRow(); JSONArray cols = rows.getJSONArray(i); for (int j = 0; j < cols.size(); j++) { XSLFTableCell xslfTableCell = xslfTableRow.addCell(); JSONObject col = cols.getJSONObject(j); if (borderColor == null) borderColor = findBorderColor(col.getJSONObject("style")); if (borderColor != null) { for (String key : edges.keySet()) { xslfTableCell.setBorderWidth(edges.get(key), 1.0D); xslfTableCell.setBorderColor(edges.get(key), borderColor); } } CTTableCell ctTableCell = (CTTableCell) xslfTableCell.getXmlObject(); JSONObject data = col.getJSONObject("data"); setSpan(spans, ctTableCell, data, i, j); if (col.containsKey("width")) xslfTable.setColumnWidth(j, col.getDoubleValue("width")); if (col.containsKey("height")) xslfTable.setRowHeight(i, col.getDoubleValue("height")); if (col.containsKey("fillColor")) xslfTableCell.setFillColor(parserHelper.getColor(col, "fillColor")); if (col.containsKey("elements")) { JSONArray elements = col.getJSONArray("elements"); XSLFTextParagraph xslfTextParagraph = xslfTableCell.addNewTextParagraph(); for (int k = 0, size = elements.size(); k < size; k++) { JSONObject element = elements.getJSONObject(k); String value = element.getJSONObject("data").getString("value"); if (validator.isEmpty(value)) { textParser.newTextRun(xslfTextParagraph, col, element).setText(""); xslfTextParagraph = xslfTableCell.addNewTextParagraph(); } else textParser.newTextRun(xslfTextParagraph, col, element).setText(value); } } else if (data.containsKey("value")) textParser.newTextRun(xslfTableCell.addNewTextParagraph(), col, new JSONObject()).setText(data.getString("value")); } } return true; }
Example #19
Source File: Parser.java From tephra with MIT License | 2 votes |
/** * 解析数据并添加到PPTx元素。 * * @param xmlSlideShow PPTx实例。 * @param xslfSlide Slide实例。 * @param object 数据。 * @return 如果解析成功则返回true;否则返回false。 */ boolean parse(XMLSlideShow xmlSlideShow, XSLFSlide xslfSlide, JSONObject object);