Here is the code in JAVA, it does the same thing as the above code in C#
JAVA Code:
-----------------------------------------------------------------
public static void ChangeTemplate() throws Exception
{
String dirPath = "D:\\downloads\\Change Design From Template";
System.out.print("Which template do you want to follow?");
System.out.print("Press 1 for Template1.");
System.out.print("Press 2 for Template2.");
char ch = (char) System.in.read();
String template="";
if (ch == '1')
template = "Template1.pot";
else
template =
"Template2.pot";
Presentation srcTemplate =
new Presentation(new FileInputStream( dirPath + "\\" + template));
//Source file whose template is to be changed
Presentation srcPres =
new Presentation(new FileInputStream( dirPath + "\\source.ppt" ));
//Clone slide from template to import master and delete extraneous slide
Slide sld = srcTemplate.cloneSlide(srcTemplate.getSlideByPosition(1),
1, srcPres,
new TreeMap());
//Save the master id of the newly cloned slide
long mstrId = sld.getMasterId();
//Delete the extraneous slide
srcPres.getSlides().remove(sld);
//Get the master slide
Slide mstrSld = srcPres.getSlideById(mstrId);
//Change the master of all the normal slides in source presentation
int lastSlidePos=srcPres.getSlides().getLastSlidePosition();
for (int i = 1; i <= lastSlidePos; i++)
{
Slide normSld = srcPres.getSlideByPosition(i);
normSld.changeMaster(mstrSld,
true);
}
//Finally write the source presentation with new template on disk
srcPres.write(
new FileOutputStream(dirPath + "\\outWithTemplate.ppt"));
System.
out.print("\noutWithTemplate.ppt Created.");
}
-----------------------------------------------------------------
Many Thanks and Kind Regards,
Shakeel Faiz
Support Engineer
Aspose Tyumen Team