Example usage for org.apache.poi.hslf.usermodel HSLFSlide draw

List of usage examples for org.apache.poi.hslf.usermodel HSLFSlide draw

Introduction

In this page you can find the example usage for org.apache.poi.hslf.usermodel HSLFSlide draw.

Prototype

@Override
    public void draw(Graphics2D graphics) 

Source Link

Usage

From source file:com.github.codeurjc.slidesconverter.PowerPointToHTML.java

License:Apache License

public void generateSlideImage(HSLFSlide slide) throws IOException {

    float scale = 0.5f;

    int sWidth = (int) (width * scale);
    int sHeight = (int) (height * scale);

    String title = slide.getTitle();
    System.out.println("Rendering slide " + slide.getSlideNumber() + (title == null ? "" : ": " + title));

    BufferedImage img = new BufferedImage(sWidth, sHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = img.createGraphics();
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    graphics.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);

    graphics.setPaint(Color.white);
    graphics.fill(new Rectangle2D.Float(0, 0, sWidth, sHeight));

    graphics.scale((double) sWidth / width, (double) sHeight / height);

    try {//from   w w w. ja  va 2 s.c o m

        slide.draw(graphics);

        Path imagePath = htmlFile.getParent().resolve(Paths.get(getImageFileName(slide.getSlideNumber())));

        OutputStream out = Files.newOutputStream(imagePath);
        ImageIO.write(img, "png", out);
        out.close();

    } catch (Exception e) {
        System.err.println("Exception rendering slide " + slide.getSlideNumber() + ": " + title);
    }
}

From source file:testppttopdf.TestPptToPdf.java

/**
 * @param args the command line arguments
 *//*ww w . j  a v  a  2  s . c  o  m*/
public static void main(String[] args) throws FileNotFoundException, IOException, COSVisitorException {
    // TODO code application logic here
    FileInputStream is = new FileInputStream("/home/sagar/Desktop/Shareback/test.ppt");
    HSLFSlideShow ppt = new HSLFSlideShow(is);
    is.close();

    Dimension pgsize = ppt.getPageSize();

    int idx = 1;
    for (HSLFSlide slide : ppt.getSlides()) {

        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
        slide.draw(graphics);

        // save the output
        FileOutputStream out = new FileOutputStream("/home/sagar/Desktop/Shareback/img/slide-" + idx + ".jpg");
        javax.imageio.ImageIO.write(img, "jpg", out);
        out.close();

        idx++;
    }

    String someimg = "/home/sagar/Desktop/Shareback/img/";

    PDDocument document = new PDDocument();
    File file = new File(someimg);
    if (file.isDirectory()) {
        for (File f : file.listFiles()) {

            InputStream in = new FileInputStream(f);

            BufferedImage bimg = ImageIO.read(in);
            float width = bimg.getWidth();
            float height = bimg.getHeight();
            PDPage page = new PDPage(new PDRectangle(width + 10, height + 10));
            document.addPage(page);
            PDXObjectImage img = new PDJpeg(document, new FileInputStream(f));
            PDPageContentStream contentStream = new PDPageContentStream(document, page);
            contentStream.drawImage(img, 0, 0);
            contentStream.close();
            in.close();
        }

        document.save("/home/sagar/Desktop/Shareback/test-generated.pdf");
        document.close();
    } else {
        System.out.println(someimg + "is not a Directory");
    }

}