Free Support Forum - aspose.com

Java cloneSlide method creating white box in slide

I am evaluating the aspose.slides package for Java and have run into one issue. When cloning slides from multiple source presentations, the text placeholders for the resulting presentation’s slides have their background color set to white and border set to black. (I’ve attached an image as an example.) The source slides do not have this formatting applied to the text placeholders. (No fill and no border.) This does not happen with the first slide cloned, so I am wondering if this is a bug or an issue with my code. Here is a snippet of how I am cloning the slides:

public void doCloneSlide (File source, File destination, int slideIndex) throws Exception {    

Presentation pres1;
Presentation pres2;
boolean newPres = false;
pres1 = new Presentation(new FileInputStream(source));
         //if the destination presentation exists open it,
         //otherwise create a new presentation
         if (destination.exists()) {
                pres2 = new Presentation(new FileInputStream(destination));
            } else {
                pres2 = new Presentation();
                //flag that this is a new pres so we can delete the
                //blank slide before saving
                newPres = true;
            }

TreeMap ids = new TreeMap();
 
         Slide slide = pres1.cloneSlide(pres1.getSlides().get(slideIndex),
                     pres2.getSlides().getLastSlidePosition() + 1, pres2, ids);

//delete the blank slide created by new Presentation()
         if (newPres) {
                pres2.getSlides().removeAt(0);
         }

FileOutputStream output = new FileOutputStream(destination);
         pres2.write(output);
         output.close();
    }
}

Thanks,

–Nathan

If I use the cloneSlide method from one presentation to another, it seems to work fine if I share the map between calls so that the same new master is used each time. However, when I then tried to be clever and change the copied slides to use a different master, I got the same formatting problems you described.

I decided it was easiest say that I couldn’t re-format copied slides to the same style as the rest of the slide, although it would be nice if this could be fixed.

This can happen if textholder can’t find master shape on master slide. The most possible reason is wrong changing master.
When you change master slide after cloning check if new master has standard master shapes.
I mean shapes with text "Click to change … ". May be you set wrong master id.

I have found that sharing the same map between calls fixes the formatting issue if the source presentations share the same master. However if the source presentations use different masters the results are corrupt formatting. I’ve attached a zip with two source presentations and two resulting presentations. The first presentation, clone1.ppt, is the result of not sharing the map. The second, clone2.ppt, is the result of sharing the map. Thanks in advance for your help.

At first, never use getSlides().removeAt() function. That is unsafe if you are not sure your slide exactly in this position.
getSlides() returns unsorted collection of slides. Also this collection contains master title slides.
If you accidentally delete master slide presentation can become broken.

You should use single TreeMap for each source presentation.
Also you can use “null” instead but target presentation will have too many master slides after that.

That is small example how to clone slides from 2 source presentations to the empty one.

FileInputStream is1 = new FileInputStream(“source1.ppt”);
FileInputStream is2 = new FileInputStream(“source2.ppt”);
Presentation src1 = new Presentation(is1);
Presentation src2 = new Presentation(is2);

TreeMap tm1 = new TreeMap();
TreeMap tm2 = new TreeMap();

Presentation target = new Presentation();

for (int i = 1; i <= 3; i++) {
src1.cloneSlide(src1.getSlideByPosition(i),
target.getSlides().getLastSlidePosition() + 1, target, tm1);
src2.cloneSlide(src2.getSlideByPosition(i),
target.getSlides().getLastSlidePosition() + 1, target, tm2);
}

target.getSlides().remove(target.getSlideByPosition(1));

FileOutputStream os = new FileOutputStream(new File(“cloned.ppt”));
target.write(os);

Thanks, I’ll try working with this.

Thanks again,

–Nathan

I was able to write a class which clones slides as expected. However, as soon as I try to call this class from ColdFusion I get results similar to the ones described above. (White fills behind text and titles.) ColdFusion uses version 1.4.2_05-b04 of the Java HotSpot Server VM so I’m wondering if this could be the issue. Does anyone have any experience using Aspose.slides with ColdFusion?



Thanks,

--Nathan

Such problem can’t be because of Coldfusion.
Probably you wrote something wrong in your code.
Please provide examples.

Here is the java class I am trying to call:

// class to build the presentation

import com.aspose.slides.*;
import java.io.*;
import java.util.TreeMap;

public class PresBuilder {

    public void buildPres() {

        try {

	FileInputStream is1 = new FileInputStream(new File("test1.ppt"));
	FileInputStream is2 = new FileInputStream(new File("test2.ppt"));
	Presentation src1 = new Presentation(is1);
	Presentation src2 = new Presentation(is2);

	TreeMap tm1 = new TreeMap();
	TreeMap tm2 = new TreeMap();

	Presentation target = new Presentation();

	for (int i = 1; i <= 3; i++) {
		src1.cloneSlide(src1.getSlideByPosition(i),
			target.getSlides().getLastSlidePosition() + 1, target, tm1);
		src2.cloneSlide(src2.getSlideByPosition(i),
			target.getSlides().getLastSlidePosition() + 1, target, tm2);
	}

	target.getSlides().remove(target.getSlideByPosition(1));

	FileOutputStream os = new FileOutputStream(new File("cloned.ppt"));
        target.write(os);


        } catch (Exception e) {
            //System.out.println(e.getMessage());
            e.printStackTrace();
        }
    }
}

Here is how I call the class from Java, which works fine:

// test calling the class from Java
public class PresBuilderTestDrive {

	public static void main (String [] args) {

		PresBuilder presBuilder = new PresBuilder();
		presBuilder.buildPres();
		System.out.println("All done.");

	}
}

And here is how I call the class from a ColdFusion template. This results in the formatting issues.



	presBuilder = createObject("java","PresBuilder");
	presBuilder.buildPres();


Thanks for all the help, I really want to get this sorted out so that I can use the Aspose library.

--Nathan

Should the TreeMap collection passed to the cloneSlide method be unique for each source presentation or each destination presentation? Also, could it be a threading issue? I know TreeMaps are not thread-safe and from what I can tell, calling this code from within ColdFusion is causing the masters collection to become corrupt.

Thanks,

–Nathan

TreeMap collection should be unique for pares source/destination.
The main reason of such external object is we can’t store such information inside
source or destination Presentation object so we decided to use external TreeMap.

Yes, there are possible thread-safe problems with this TreeMap. Also I can’t guarantee
correct work if you change the same presentation from different threads simultaneously.

OK, I think I have this issue figured out. I’m now using a unique TreeMap for each unique pair of source/destination presentations and I’m no longer getting the corrupt formatting.

Thanks for all of your help with this.

–Nathan

And here is how I call the class from a ColdFusion template. This results in the formatting issues.


presBuilder = createObject("java","PresBuilder");
presBuilder.buildPres();






FYI, I updated to the latest version of the library,1.6.2.0, and this example is now working.