You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Jayasree <ja...@gmail.com> on 2013/07/30 07:15:19 UTC

Unable to remove image from pptx file using xslf api

Hi All,

I am trying to generate pptx file using 1 pptx file as template. 
For replacing new image with old one in template, I tried to remove image 
from template pptx file. But poi framework throwing an exception. 

java.lang.IllegalArgumentException: Unsupported shape: 
org.apache.poi.xslf.usermodel.XSLFPictureShape 

Code:
 if (shape instanceof XSLFPictureShape){
			//work with Picture			
			XSLFPictureShape picshape = (XSLFPictureShape)
shape;
			Rectangle2D rectangle = picshape.getAnchor();
				try{
					boolean remove = slide.removeShape
(picshape);
					System.out.println("slide 
removed ::"+remove);
					File img = new File
("C:/Jayasree", "defualt.png");
					byte[] data = IOUtils.toByteArray
(new FileInputStream(img));
					int pictureIndex = ppt.addPicture
(data, XSLFPictureData.PICTURE_TYPE_PNG);
					XSLFPictureShape newpicshape = 
slide.createPicture(pictureIndex);
					newpicshape.setAnchor(rectangle);
				}catch(Exception e){
					e.printStackTrace();
				}
}


Thanks in advance..


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org