We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Converting thumbnails into a ppt slide - Aspose for Java

Hi,

I have a requirement of converting thumbnail images into a ppt slide using Aspose.slides for Java. Can this be done using Aspose? Please confirm as I need to work on the requirement and determine the results ASAP. Thanks in advance.

Dear waves <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Aspose.Slides let you add any picture/image on slide. You should add your thumbnail image as a PictureFrame. To see, how to add a PictureFrame, please see this link.

http://www.aspose.com/Wiki/default.aspx/Aspose.Slides/AddingPictureFrame.html

Hi,

Thanks for the information. I am using the code snippet you provided but I am facing two problems:

Picture pic = new com.aspose.slides.Picture(pres, iStream);

In the above line, I get a compilation error stating that Picture object type is ambiguous.

Secondly, in the below line of code, I get a compilation error stating that

RenderedOp and JAI cannot be resolved.

RenderedOp img1 = JAI.create("fileload", "C:\\demo.jpg");

Am I missing anything in the above line of code?

Please help me out with these issues. Thanks a lot in advance.

I have commented the lines which are giving you error, actually, you don't need them. Try running the same code with little modifications by me.

I have attached this code, also the output presentation and source image used in it.

import java.awt.Color;

import java.awt.Dimension;

import java.awt.Graphics2D;

import java.awt.image.BufferedImage;

import java.awt.image.RenderedImage;

import java.io.BufferedInputStream;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.util.TreeMap;

import java.util.zip.*;

import javax.imageio.ImageIO;

import com.aspose.slides.*;

import com.aspose.metafiles.*;

public class clsPPTJava {

public static void main(String[] args) {

try

{

AddingPictureFrame();

}

catch(Exception ex)

{

System.out.println(ex.toString());

}

}

public static void AddingPictureFrame() throws Exception

{

try

{

//Instantiate a Presentation object that represents a PPT file

//Presentation pres = new Presentation(new FileInputStream(new File("demo.ppt")));

Presentation pres = new Presentation();

//Accessing a slide using its slide position

Slide slide = pres.getSlideByPosition(1);

//Creating a stream to hold the image file

InputStream iStream = new BufferedInputStream(new FileInputStream("C:\\sunset.jpg"));

//Creating a picture object

//Picture pic = new com.Aspose.Slides.Picture(pres, iStream);

Picture pic = new com.aspose.slides.Picture(pres, iStream);

//Adding the picture object to pictures collection of the presentation

//After the picture object is added, the picture is given a uniqe picture Id

int picId = pres.getPictures().add(pic);

//Using the Java Advanced Imaging Component

//RenderedOp img = JAI.create("fileload", "C:\\demo.jpg");

//Calculating picture width and height

//int pictureWidth = img.getWidth() * 4;

//int pictureHeight = img.getHeight() * 4;

//Calculating slide width and height

int slideWidth = slide.getBackground().getWidth();

int slideHeight = slide.getBackground().getHeight();

//Calculating the width and height of picture frame

//int pictureFrameWidth = (slideWidth/2 - pictureWidth/2);

//int pictureFrameHeight = (slideHeight/2 - pictureHeight/2);

int pictureFrameWidth =(int) pres.getSlideSize().getX();

int pictureFrameHeight =(int) pres.getSlideSize().getY();

//Adding picture frame to the slide

slide.getShapes().addPictureFrame(picId, 0,0, pictureFrameWidth, pictureFrameHeight);

//Writing the presentation as a PPT file

pres.write(new FileOutputStream(new File("c:\\outPres.ppt")));

}

catch(Exception ex)

{

System.out.println(ex.toString());

}

}

}