Removing background image from ppt and pptx

Hi,

Can anyone please give the Java code to remove background image from ppt and pptx files.

This is very urgent , any help is appreciated.

I am using the following java code to insert an image:

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")));

Regards,

Sam

Hello Sam,

To remove background image on ppt slide you just need to set NO_FILL fill type:

slide.setFollowMasterBackground(false);
slide.getBackground().getFillFormat().setType(FillType.NO_FILL);

On pptx slides access to a slide background already implemented but not released yet. I will check if it’s possible to provide new version for you today or tomorrow.

Hi Alexey Zhilin,

Any update on how to add a backgroung image and remove the background image for pptx files.

This is very urgent , any help is appreciated.

Regards,

Sam

Hello Sam,

There is new version of Aspose.Slides for Java with access to a slide background.

For example to remove background image (and also disable all fill styles of background) on the first slide in a presentation you should use this code:

SlideEx slide = presentation.getSlides().get(0);

BackgroundEx bkg = slide.getBackground();
bkg.setType(BackgroundTypeEx.OWN_BACKGROUND);
bkg.getFillFormat().setFillType(FillTypeEx.NOFILL);

Hi Alexey Zhilin,

Thanks for you quick response

Can you please also provide the java code to add an image to background slide for pptx which is similar to above mentioned java code for ppt.

This is very urgent , any help is really very much appreciated.

Regards,

Sam

That is example how to set background image:

BackgroundEx bkg = pres1.getSlides().get(0).getBackground();
bkg.setType(BackgroundTypeEx.OWN_BACKGROUND);
bkg.getFillFormat().setFillType(FillTypeEx.PICTURE);
bkg.getFillFormat().getPictureFillFormat().setPictureFillMode(PictureFillModeEx.TILE);

FileSeekableStream fss = new FileSeekableStream(“picture_1.jpg”);
RenderedImage image = JAI.create(“stream”, fss);
ImageEx pic = pres1.getImages().addImage(image);
bkg.getFillFormat().getPictureFillFormat().getPicture().setImage(pic);

Hi Alexey Zhilin,

Are there any extra Jar libraries that needs to be loaded for this code to work apart from aspose slides?

Please help !!

Regards,

Sam

Hello,

JAI and JAI-ImageIO is standard requirement for Aspose.Slides for Java. Also I’d suggest to have Aspose.Metafiles in case presentations have any wmf/emf metafiles inside.

Example I provided has these additional imports:
import javax.media.jai.JAI;
import com.sun.media.jai.codec.FileSeekableStream;

From JAI you need only these jars:
jai_codec.jar
jai_core.jar
jai-imageio.jar
Other JAI files and jars are not necessary.

Hi Alexey Zhilin,

Thanks for you update , as per your code

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

there is no method getBackground available for aspose-slides-2.0.0.4.jar version

how did you declare your pres1,

Is it like below mentioned way ?

PresentationEx pres1 = new Presentation(new FileInputStream(new File("D:/MasterBackground.pptx"))); or any other way ?

Please help !!

Regards,

Sam

Hi Alexey Zhilin,

Sorry my mistake , got the version right .

Thanks so much for you help !!! really appreciate your work.

Regards,

Sam