kiwiwings

XSLF - Replacing preview image

Feb 3rd, 2016
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.15 KB | None | 0 0
  1.     @Test
  2.     public void ppt_with_excel() throws IOException, InvalidFormatException {
  3.         FileInputStream fis = new FileInputStream("ppt_with_excel.pptx");
  4.         XMLSlideShow ppt = new XMLSlideShow(fis);
  5.         fis.close();
  6.        
  7.         XSLFSlide sl = ppt.getSlides().get(0);
  8.         XSLFGraphicFrame gf = (XSLFGraphicFrame)sl.getShapes().get(0);
  9.         XSLFPictureShape ps = gf.getFallbackPicture();
  10.         PackagePart pp = ps.getPictureData().getPackagePart();
  11.         // determine click-me image extension
  12.         File clickMe;
  13.         if ("image/x-emf".equals(pp.getContentType())) {
  14.             clickMe = new File("clickMe.emf");
  15.             // else png, gif, ...
  16.         } else {
  17.             throw new IOException("I don't have 'click me' image for content type "+pp.getContentType());
  18.         }
  19.         OutputStream os = pp.getOutputStream();
  20.         InputStream is = new FileInputStream(clickMe);
  21.         IOUtils.copy(is, os);
  22.         is.close();
  23.         os.close();
  24.        
  25.         FileOutputStream fos = new FileOutputStream("bla.pptx");
  26.         ppt.write(fos);
  27.         fos.close();
  28.        
  29.         ppt.close();
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment