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

Free Support Forum - aspose.com

Wrong format after changing text in cloned slide with master slide


I’m trying to clone a slide and change the text in a textframe. The attached slide sjm_title_slide.ppt has a master template that determines the styles, and I’m trying to apply text to the title textbox that currently has no text. The textbox has its alt-text set to ‘title’ which lets the code below find it.

After running the code, the text in the second slide in the produced presentation (which has the same filename as the input + ‘.new.ppt’) comes out with text matching the title box of the master slide master layout (NOT the layout used by the cloned slide) - most notably the wrong colour. In addition the master slide is quite different from the input.

It looks like it’s the operation of replacing the text that’s losing the formatting (since the first slide produced has the correct formatting) - is there a different way I can set the text whilst preserving the format?

import com.aspose.slides.*;

import java.io.;

import java.util.TreeMap;

public class CloneTest


public static void main(String[] args)




License license = new License();

license.setLicense(new FileInputStream(""));

// Presentation I want to copy FROM

Presentation toCopy = new Presentation(new FileInputStream(args[0]));

Slide slideToCopy = toCopy.getSlideByPosition(1);

// Presentation I’ll copy TO

Presentation presentation = new Presentation();

// Clone the slide from toCopy into ‘presentation’

Slide whatShouldLookLike = toCopy.cloneSlide(slideToCopy, 2, presentation, new java.util.TreeMap());

Slide newSlide = toCopy.cloneSlide(slideToCopy, 3, presentation, new java.util.TreeMap());

// Remove the blank slide Aspose gives us


// Find the ‘title’

Shape shape = newSlide.findShape(“title”);

TextFrame tf = shape.getTextFrame();

tf.setText(“textframe - the formatting is wrong”); // This text comes out black text, size 44

/* - comment the line above and uncomment this and it’s also black text, size 44

Paragraph origPara = tf.getParagraphs().get(0);


Paragraph para = new Paragraph(origPara);

para.setText(“paragraph - the formatting is wrong”);



presentation.write(new FileOutputStream(args[0] + “.new.ppt”));



catch (Exception ex) { System.out.println(ex.toString()); }



Hi Steve,

I have worked with the presentation and code snippet shared by you. The issue is that you are setting text for the shape directly on textframe level. When you will do so, all the inherent properties of the text formatting in that text frame will get reset. There are certain font related properties that are set on paragraphs level and some at portion levels. In order to retain all the text related properties in the cloned slide shape, the text must be replaced on portion level. I have made the following correction in your code snippet and it works fine. Please share, if you still face any issue.

tf.getParagraphs().get(0).getPortions().get(0).setText("textframe - the formatting is wrong");

Thanks and Regards,

Hi Mudassir,

Many thanks for the quick response. Is there a way to preserve the formatting when new paragraphs /portions are added? In our example we often replace the text with multiple paragraphs (in order to get the spacing to render correctly).



Never mind - the copy constructors seem to preserve formatting. Thanks again for the quick response, appreciate it.