List of usage examples for org.apache.poi.xslf.usermodel XSLFShape getAnchor
Rectangle2D getAnchor();
From source file:org.joeffice.presentation.ShapeComponent.java
License:Apache License
public ShapeComponent(XSLFShape shape, SlideComponent slideComponent) { this.shape = shape; this.slideComponent = slideComponent; setOpaque(false);/*from w w w . j a va 2s . c o m*/ // setBorder(BorderFactory.createLineBorder(Color.RED)); // for debug Rectangle shapeBounds = shape.getAnchor().getBounds(); double scale = slideComponent.getScale(); Rectangle.Double scaledBounds = new Rectangle.Double(shapeBounds.x * scale, shapeBounds.y * scale, shapeBounds.width * scale, shapeBounds.height * scale); setBounds(scaledBounds.getBounds()); setOpaque(false); setLayout(new BorderLayout()); editable = slideComponent.getSlidesComponent() != null; initComponent(); }
From source file:org.joeffice.presentation.ShapeComponent.java
License:Apache License
public static BufferedImage shapeToImage(XSLFShape shape, double scale) { BufferedImage img = new BufferedImage((int) (shape.getAnchor().getWidth() * scale), (int) (shape.getAnchor().getHeight() * scale), BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = img.createGraphics(); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); graphics.translate(-shape.getAnchor().getX() * scale, -shape.getAnchor().getY() * scale); graphics.scale(scale, scale);/*from ww w.j a v a 2s.com*/ shape.draw(graphics); graphics.dispose(); return img; }
From source file:org.joeffice.tools.PptxShapeNotDrawn.java
License:Apache License
public static void main(String[] args) throws IOException { if (args.length == 0) { System.err.println("Please profile a file path to open"); System.exit(-1);//from w w w . j ava2 s. c om } JPanel mainPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); XMLSlideShow presentation = new XMLSlideShow(new FileInputStream(args[0])); XSLFSlide[] slides = presentation.getSlides(); for (XSLFSlide slide : slides) { XSLFShape[] shapes = slide.getShapes(); for (XSLFShape shape : shapes) { BufferedImage img = new BufferedImage((int) shape.getAnchor().getWidth(), (int) shape.getAnchor().getHeight(), BufferedImage.TYPE_4BYTE_ABGR); Graphics2D graphics = img.createGraphics(); graphics.translate(-shape.getAnchor().getX(), -shape.getAnchor().getY()); shape.draw(graphics); graphics.dispose(); JLabel shapeLabel = new JLabel(new ImageIcon(img)); shapeLabel.setBorder(BorderFactory.createLineBorder(Color.RED)); mainPanel.add(shapeLabel); } } showDemo(new JScrollPane(mainPanel), "Shape not displayed"); }
From source file:poi.xslf.usermodel.DataExtraction.java
License:Apache License
public static void main(String args[]) throws Exception { if (args.length == 0) { System.out.println("Input file is required"); return;//from ww w.j a v a 2s . c o m } FileInputStream is = new FileInputStream(args[0]); XMLSlideShow ppt = new XMLSlideShow(is); is.close(); // Get the document's embedded files. List<PackagePart> embeds = ppt.getAllEmbedds(); for (PackagePart p : embeds) { String type = p.getContentType(); String name = p.getPartName().getName(); //typically file name InputStream pIs = p.getInputStream(); // make sense of the part data pIs.close(); } // Get the document's embedded files. List<XSLFPictureData> images = ppt.getAllPictures(); for (XSLFPictureData data : images) { PackagePart p = data.getPackagePart(); String type = p.getContentType(); String name = data.getFileName(); InputStream pIs = p.getInputStream(); // make sense of the image data pIs.close(); } Dimension pageSize = ppt.getPageSize(); // size of the canvas in points for (XSLFSlide slide : ppt.getSlides()) { for (XSLFShape shape : slide) { Rectangle2D anchor = shape.getAnchor(); // position on the canvas if (shape instanceof XSLFTextShape) { XSLFTextShape txShape = (XSLFTextShape) shape; System.out.println(txShape.getText()); } else if (shape instanceof XSLFPictureShape) { XSLFPictureShape pShape = (XSLFPictureShape) shape; XSLFPictureData pData = pShape.getPictureData(); System.out.println(pData.getFileName()); } else { System.out.println("Process me: " + shape.getClass()); } } } }