@Test public void testGetThumbnail() throws IOException { log.info("testGetThumbnail"); assertNotNull(provider.getThumbnail(pptxFile)); assertNotNull(provider.getThumbnail(pptFile)); }
@Override public InputStream getThumbnail(Resource resource) throws IOException { if (dclm != null) { Thread.currentThread().setContextClassLoader(dclm.getDynamicClassLoader()); } SlideShow<?, ?> ppt = null; MediaType mt = MediaType.parse(resource.adaptTo(File.class).getContentType()); try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = resource.adaptTo(InputStream.class)) { if (mt.is(MediaType.MICROSOFT_POWERPOINT)) { ppt = new HSLFSlideShow(is); } else { ppt = new XMLSlideShow(is); } Dimension dim = ppt.getPageSize(); List<? extends Slide<?, ?>> slides = ppt.getSlides(); BufferedImage img = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, dim.width, dim.height)); if (slides != null && !slides.isEmpty()) { slides.get(0).draw(graphics); } ImageIO.write(img, OutputFileFormat.PNG.toString(), baos); return new ByteArrayInputStream(baos.toByteArray()); } finally { if (ppt != null) { ppt.close(); } } }
SlideShowThumbnailProvider implements ThumbnailProvider { @Override public InputStream getThumbnail(Resource resource) throws IOException { if (dclm != null) { Thread.currentThread().setContextClassLoader(dclm.getDynamicClassLoader()); } SlideShow<?, ?> ppt = null; MediaType mt = MediaType.parse(resource.adaptTo(File.class).getContentType()); try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = resource.adaptTo(InputStream.class)) { if (mt.is(MediaType.MICROSOFT_POWERPOINT)) { ppt = new HSLFSlideShow(is); } else { ppt = new XMLSlideShow(is); } Dimension dim = ppt.getPageSize(); List<? extends Slide<?, ?>> slides = ppt.getSlides(); BufferedImage img = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, dim.width, dim.height)); if (slides != null && !slides.isEmpty()) { slides.get(0).draw(graphics); } ImageIO.write(img, OutputFileFormat.PNG.toString(), baos); return new ByteArrayInputStream(baos.toByteArray()); } finally { if (ppt != null) { ppt.close(); } } } }
SlideShowThumbnailProvider implements ThumbnailProvider { @Override public InputStream getThumbnail(Resource resource) throws IOException { if (dclm != null) { Thread.currentThread().setContextClassLoader(dclm.getDynamicClassLoader()); } SlideShow<?, ?> ppt = null; MediaType mt = MediaType.parse(resource.adaptTo(File.class).getContentType()); try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = resource.adaptTo(InputStream.class)) { if (mt.is(MediaType.MICROSOFT_POWERPOINT)) { ppt = new HSLFSlideShow(is); } else { ppt = new XMLSlideShow(is); } Dimension dim = ppt.getPageSize(); List<? extends Slide<?, ?>> slides = ppt.getSlides(); BufferedImage img = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, dim.width, dim.height)); if (slides != null && !slides.isEmpty()) { slides.get(0).draw(graphics); } ImageIO.write(img, OutputFileFormat.PNG.toString(), baos); return new ByteArrayInputStream(baos.toByteArray()); } finally { if (ppt != null) { ppt.close(); } } }  }
SlideShowThumbnailProvider implements ThumbnailProvider { @Override public InputStream getThumbnail(Resource resource) throws IOException { if (dclm != null) { Thread.currentThread().setContextClassLoader(dclm.getDynamicClassLoader()); } SlideShow<?, ?> ppt = null; MediaType mt = MediaType.parse(resource.adaptTo(File.class).getContentType()); try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = resource.adaptTo(InputStream.class)) { if (mt.is(MediaType.MICROSOFT_POWERPOINT)) { ppt = new HSLFSlideShow(is); } else { ppt = new XMLSlideShow(is); } Dimension dim = ppt.getPageSize(); List<? extends Slide<?, ?>> slides = ppt.getSlides(); BufferedImage img = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, dim.width, dim.height)); if (slides != null && !slides.isEmpty()) { slides.get(0).draw(graphics); } ImageIO.write(img, OutputFileFormat.PNG.toString(), baos); return new ByteArrayInputStream(baos.toByteArray()); } finally { if (ppt != null) { ppt.close(); } } }  @Override boolean applies(Resource resource); @Override InputStream getThumbnail(Resource resource); }
SlideShowThumbnailProvider implements ThumbnailProvider { @Override public InputStream getThumbnail(Resource resource) throws IOException { if (dclm != null) { Thread.currentThread().setContextClassLoader(dclm.getDynamicClassLoader()); } SlideShow<?, ?> ppt = null; MediaType mt = MediaType.parse(resource.adaptTo(File.class).getContentType()); try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); InputStream is = resource.adaptTo(InputStream.class)) { if (mt.is(MediaType.MICROSOFT_POWERPOINT)) { ppt = new HSLFSlideShow(is); } else { ppt = new XMLSlideShow(is); } Dimension dim = ppt.getPageSize(); List<? extends Slide<?, ?>> slides = ppt.getSlides(); BufferedImage img = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = img.createGraphics(); graphics.setPaint(Color.white); graphics.fill(new Rectangle2D.Float(0, 0, dim.width, dim.height)); if (slides != null && !slides.isEmpty()) { slides.get(0).draw(graphics); } ImageIO.write(img, OutputFileFormat.PNG.toString(), baos); return new ByteArrayInputStream(baos.toByteArray()); } finally { if (ppt != null) { ppt.close(); } } }  @Override boolean applies(Resource resource); @Override InputStream getThumbnail(Resource resource);  }