org.apache.poi.sl.usermodel.PictureData Java Examples
The following examples show how to use
org.apache.poi.sl.usermodel.PictureData.
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: DrawPictureShape.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public void drawContent(Graphics2D graphics) { PictureData data = getShape().getPictureData(); if(data == null) return; Rectangle2D anchor = getAnchor(graphics, getShape()); Insets insets = getShape().getClipping(); try { ImageRenderer renderer = getImageRenderer(graphics, data.getContentType()); renderer.loadImage(data.getData(), data.getContentType()); renderer.drawImage(graphics, anchor, insets); } catch (IOException e) { LOG.log(POILogger.ERROR, "image can't be loaded/rendered.", e); } }
Example #2
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 #3
Source File: ImageParserImpl.java From tephra with MIT License | 5 votes |
private PictureData.PictureType getPictureType(String url, String contentType) { switch (contentType) { case "image/jpeg": return PictureData.PictureType.JPEG; case "image/gif": return PictureData.PictureType.GIF; default: if (!contentType.equals("image/png")) logger.warn(null, "未处理图片类型[{}:{}]!", url, contentType); return PictureData.PictureType.PNG; } }
Example #4
Source File: ImageImpl.java From tephra with MIT License | 5 votes |
private PictureData.PictureType getPictureType(String url, String contentType) { switch (contentType) { case "image/jpeg": return PictureData.PictureType.JPEG; case "image/gif": return PictureData.PictureType.GIF; default: if (!contentType.equals("image/png")) logger.warn(null, "未处理图片类型[{}:{}]!", url, contentType); return PictureData.PictureType.PNG; } }
Example #5
Source File: PowerPointHelper.java From tutorials with MIT License | 4 votes |
/** * Create a sample presentation * * @param fileLocation * File location of the presentation * @throws IOException */ public void createPresentation(String fileLocation) throws IOException { // Create presentation XMLSlideShow ppt = new XMLSlideShow(); XSLFSlideMaster defaultMaster = ppt.getSlideMasters().get(0); // Retriving the slide layout XSLFSlideLayout layout = defaultMaster.getLayout(SlideLayout.TITLE_ONLY); // Creating the 1st slide XSLFSlide slide1 = ppt.createSlide(layout); XSLFTextShape title = slide1.getPlaceholder(0); // Clearing text to remove the predefined one in the template title.clearText(); XSLFTextParagraph p = title.addNewTextParagraph(); XSLFTextRun r1 = p.addNewTextRun(); r1.setText("Baeldung"); r1.setFontColor(new Color(78, 147, 89)); r1.setFontSize(48.); // Add Image ClassLoader classLoader = getClass().getClassLoader(); byte[] pictureData = IOUtils.toByteArray(new FileInputStream(classLoader.getResource("logo-leaf.png").getFile())); XSLFPictureData pd = ppt.addPicture(pictureData, PictureData.PictureType.PNG); XSLFPictureShape picture = slide1.createPicture(pd); picture.setAnchor(new Rectangle(320, 230, 100, 92)); // Creating 2nd slide layout = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT); XSLFSlide slide2 = ppt.createSlide(layout); // setting the tile title = slide2.getPlaceholder(0); title.clearText(); XSLFTextRun r = title.addNewTextParagraph().addNewTextRun(); r.setText("Baeldung"); // Adding the link XSLFHyperlink link = r.createHyperlink(); link.setAddress("http://www.baeldung.com"); // setting the content XSLFTextShape content = slide2.getPlaceholder(1); content.clearText(); // unset any existing text content.addNewTextParagraph().addNewTextRun().setText("First paragraph"); content.addNewTextParagraph().addNewTextRun().setText("Second paragraph"); content.addNewTextParagraph().addNewTextRun().setText("Third paragraph"); // Creating 3rd slide - List layout = defaultMaster.getLayout(SlideLayout.TITLE_AND_CONTENT); XSLFSlide slide3 = ppt.createSlide(layout); title = slide3.getPlaceholder(0); title.clearText(); r = title.addNewTextParagraph().addNewTextRun(); r.setText("Lists"); content = slide3.getPlaceholder(1); content.clearText(); XSLFTextParagraph p1 = content.addNewTextParagraph(); p1.setIndentLevel(0); p1.setBullet(true); r1 = p1.addNewTextRun(); r1.setText("Bullet"); // the next three paragraphs form an auto-numbered list XSLFTextParagraph p2 = content.addNewTextParagraph(); p2.setBulletAutoNumber(AutoNumberingScheme.alphaLcParenRight, 1); p2.setIndentLevel(1); XSLFTextRun r2 = p2.addNewTextRun(); r2.setText("Numbered List Item - 1"); // Creating 4th slide XSLFSlide slide4 = ppt.createSlide(); createTable(slide4); // Save presentation FileOutputStream out = new FileOutputStream(fileLocation); ppt.write(out); out.close(); // Closing presentation ppt.close(); }