Hi,
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)
{
try
{
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
presentation.getSlides().removeAt(0);
// 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);
tf.getParagraphs().clear();
Paragraph para = new Paragraph(origPara);
para.setText(“paragraph - the formatting is wrong”);
tf.getParagraphs().add(para);
*/
presentation.write(new FileOutputStream(args[0] + “.new.ppt”));
ofstream.close();
}
catch (Exception ex) { System.out.println(ex.toString()); }
}
}