Adding Background Image to pptx

Hi ,

Can any one provide the java code to add a background image for pptx files.

package test;

import com.aspose.slides.Picture;
import com.aspose.slides.FillType;
import com.aspose.slides.Presentation;

import com.aspose.slides.Slide;


import com.aspose.slides.Slides;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;


public class Powerpoint {
public static void main(String a[])
{
try

{

//Instantiate a Presentation object that represents a PPT file

Presentation pres = new Presentation(new FileInputStream(new File("D:/MasterBackground.ppt")));

int number = pres.getFirstSlideNumber() + pres.getSlides().getLastSlidePosition() - 1;


//Accessing a slide using its slide position



for(int i=0;i<number;i++){

Slide slide = pres.getSlides().get(i);



//Slide slide = pres.getSlideByPosition(1);

//Disable following master background settings

slide.setFollowMasterBackground(false);

//Setting the fill type of the background to picture

slide.getBackground().getFillFormat().setType(FillType.PICTURE);

//Creating a stream to hold the image file

InputStream iStream = new BufferedInputStream(new FileInputStream("D:/Winter.jpeg"));

//Creating a picture object that will be used as a slide background

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 unique picture Id

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

//Setting the picture Id of the slide background to the Id of the picture object

slide.getBackground().getFillFormat().setPictureId(picId);


}
//Writing the presentation as a PPT file

pres.write(new FileOutputStream(new File("D:/MasterBackground.ppt")));

}catch(Exception ex)

{

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

}


}
}
This code works fine for ppt but I want the code for pptx in a similar output.

This is very important. Any help will very much appreciated.

Regards,

Sam

Hello,

Answered in this thread.

Hi ,

Ca you please give the complete code with the Jar libraries . I am getting errors at lines

BackgroundEx bkg = pres.getSlides().get(0).getBackground();

FileSeekableStream fss = new FileSeekableStream("picture_1.jpg");
RenderedImage image = JAI.create("stream", fss);

I think apart from aspose-slides-2.0.0.4.jar do we need more libraries for this code to work .

Please help !! this is very urgent.

Regards,

Sam

Please check another thread and don’t post the same questions several times.