Bug 46196 - Performance problem while converting the ppt slide to png/jpg
Summary: Performance problem while converting the ppt slide to png/jpg
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: HSLF (show other bugs)
Version: 3.5-dev
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-11-12 06:49 UTC by Raghunath Chakinam
Modified: 2014-08-31 20:37 UTC (History)
1 user (show)



Attachments
Sample ppt to convert them into jpeg/png (511.00 KB, application/vnd.ms-powerpoint)
2008-11-23 20:28 UTC, Raghunath Chakinam
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Raghunath Chakinam 2008-11-12 06:49:56 UTC
I am using the below code to convert the single ppt to png slide. But it is taking around 10 seconds for each slide. which will create a huge performance problem.

Here I am giving some background on this issue. 
 I am developing the application which will create a ppt slides to jpg. So here User will upload the ppt. But when ppt contains around 10 slides it is taking around 100 sec which is huge impact on my application response.

Please solve this issue. Thanks in advance.

Please let me know if you have any other code which will resolve this issue.

********************************************************************************
package com.hsbc.servlet;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Date;

import javax.imageio.ImageIO;

import org.apache.poi.hslf.model.Slide;
import org.apache.poi.hslf.usermodel.SlideShow;

public class PPT2PNG {

    public static void main(String args[]) throws Exception {

       System.out.println("Start time:"+new Date());
        int slidenum = 3;
        float scale = 1;
        String file = "WebContent/ppts/RIM-94100.ppt";
        
        FileInputStream is = new FileInputStream(file);
        SlideShow ppt = new SlideShow(is);
        is.close();

        Dimension pgsize = ppt.getPageSize();
        int width = (int)(pgsize.width*scale);
        int height = (int)(pgsize.height*scale);

        Slide[] slide = ppt.getSlides();
        for (int i = 0; i < slide.length; i++) {
            if (slidenum != -1 && slidenum != (i+1)) continue;

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

            BufferedImage img = new BufferedImage(width, height, 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, width, height));

            graphics.scale((double)width/pgsize.width, (double)height/pgsize.height);

            slide[i].draw(graphics);

            String fname = file.replaceAll("\\.ppt", "-" + (i+1) + ".png");
            FileOutputStream out = new FileOutputStream(fname);
            ImageIO.write(img, "png", out);
            out.close();
        }
        System.out.println("End Time:"+new Date());
    }
}
Comment 1 Yegor Kozlov 2008-11-16 05:47:32 UTC
What is your hardware configuration? How much memory do you allocate for JVM?

Can you upload a sample ppt that demonstrate the performance issue?

Yegor
Comment 2 Raghunath Chakinam 2008-11-23 20:28:49 UTC
Created attachment 22918 [details]
Sample ppt to convert them into jpeg/png
Comment 3 Raghunath Chakinam 2008-11-23 20:32:51 UTC
Here I am sending my Hardware configuration:

CPU : Intel core2 duo processor @ 2.33GHz
RAM : 2GB
Hard Drive has 40GB Free space

I am using RAD 7.0.0.2 to run this application.

I have allocated the maximum amount of memory to JVM by specifying the max parameters.

Thanks in advance.
Comment 4 Raghunath Chakinam 2008-12-15 04:38:14 UTC
Is there any update on this issue?
Comment 5 Yegor Kozlov 2008-12-16 07:49:00 UTC
(In reply to comment #4)
> Is there any update on this issue?
> 

not yet.
Comment 6 Dominik Stadler 2014-08-31 20:37:11 UTC
Using the latest version of POI  (3.11-beta2) and the current version of PPT2PNG from the examples area, all 4 slides together are converted in less than 3 seconds, so it seems this was improved greatly since the bug was reported.

Therefore I am closing this as WORKSFORME for now, please reopen if this still takes a long time for you with the latest version of POI.