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

Free Support Forum - aspose.com

Split functionality

My customer is facing this problem...By using split functionality, I have split one presentation into 10 presentations <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

(basically I have saved each slide as separate presentation)

Now iam trying to read all these 10 presentations which each presentation

has one slide and try to copy into the newly created presentation.

At present iam facing one issue while merging the multiple presentations into one presentation.

My requirement is:

i) Read all the presentations which are under one folder. ( each presentation will have only one slide)

ii) Read the slides from each Presentation and copy to the new Presentation.

Please see the attached file for the code which I have written. I have posted the question in forum also.

But still this issue is not resolved for me. With attached code iam getting the following error:

com.aspose.slides.PptEditException: Slide cloning error.

at com.aspose.slides.Presentation.cloneSlide(SourceFile:1371)

at readMultipleFiles.main(readMultipleFiles.java:45)

Caused by: java.lang.NullPointerException

at com.aspose.slides.Presentation.cloneSlide(SourceFile:1289)

... 1 more

Please help me in this regard and correct me where iam doing wrong.

Kind Regards,

M.Irfan

Hi,

Can i get a quick reply for the above..

thx.

Irfan.

Dear Irfan,

Please attach the presentation, which you split into multiple presentations and then merged them all again, so that we could reproduce it and investigate it.

Hi,

I am unable to attach the document can i mail you?

thx.

Irfan.

public class readMultipleFiles {
public static void main(String[] args) throws SQLException, IOException {
try{
File dir = new File("D://output");
String[] children = dir.list();
if (children == null) {
System.out.println(" **** Directory is Empty ****");
} else {
for (int i=0; i<children.length; i++) {
String filename = children[i];
System.out.println(" File Name >>>> "+filename);
if(!filename.endsWith(".ppt")){
System.out.println(" *** File is not PPT file ***");
break;
}
Presentation srcPres = new Presentation(new FileInputStream( dir + "/" + filename ));
Point size = new Point(3,3);

Presentation newPres = new Presentation();
newPres.setSlideSize(size);

//TreeMap ids = new TreeMap();
for (int iSlidesCounter = 0; iSlidesCounter < children.length; iSlidesCounter++) {
// ids.clear();
// newPres.cloneSlide(newPres.getSlides().get(0), 2, srcPres, new TreeMap());
// SunnewPres.getSlides().remove(newPres.getSlideByPosition(2));

// newPres.cloneSlide(newPres.getSlides().get(0),
// srcPres.getSlides().getLastSlidePosition()+1,
// srcPres, ids);

Slide srcSld = srcPres.getSlideByPosition( 0 );
srcPres.cloneSlide(srcSld, srcPres.getSlides().getLastSlidePosition()+1 , newPres, new TreeMap());
newPres.write(new FileOutputStream("d://output/newslide.ppt"));
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}

import java.awt.Point;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.TreeMap;

import com.aspose.slides.Presentation;
import com.aspose.slides.Slide;


public class readMultipleFiles {
public static void main(String[] args) throws SQLException, IOException {
try{
File dir = new File("D://output");
String[] children = dir.list();
if (children == null) {
System.out.println(" **** Directory is Empty ****");
} else {
for (int i=0; i<children.length; i++) {
String filename = children[i];
System.out.println(" File Name >>>> "+filename);
if(!filename.endsWith(".ppt")){
System.out.println(" *** File is not PPT file ***");
break;
}
Presentation srcPres = new Presentation(new FileInputStream( dir + "/" + filename ));
Point size = new Point(3,3);

Presentation newPres = new Presentation();
newPres.setSlideSize(size);

//TreeMap ids = new TreeMap();
for (int iSlidesCounter = 0; iSlidesCounter < children.length; iSlidesCounter++) {
// ids.clear();
// newPres.cloneSlide(newPres.getSlides().get(0), 2, srcPres, new TreeMap());
// SunnewPres.getSlides().remove(newPres.getSlideByPosition(2));

// newPres.cloneSlide(newPres.getSlides().get(0),
// srcPres.getSlides().getLastSlidePosition()+1,
// srcPres, ids);

Slide srcSld = srcPres.getSlideByPosition( 0 );
srcPres.cloneSlide(srcSld, srcPres.getSlides().getLastSlidePosition()+1 , newPres, new TreeMap());
newPres.write(new FileOutputStream("d://output/newslide.ppt"));
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}

Slide srcSld = srcPres.getSlideByPosition( 0 );
Slide positions numbered from 1. Position 0 will return null or master slide which can’t be cloned.

Point size = new Point(3,3);
newPres.setSlideSize(size);
Normal size of slides in a presentation is 5760x4320.
Are you sure slide 3x3 will be visible without microscope?

import java.awt.Point;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.TreeMap;

import com.aspose.slides.Presentation;
import com.aspose.slides.Slide;


public class readMultipleFiles {
public static void main(String[] args) throws SQLException, IOException {
try{
File dir = new File("D://output");
String[] children = dir.list();
if (children == null) {
System.out.println(" **** Directory is Empty ****");
} else {
for (int i=0; i<children.length; i++) {
String filename = children[i];
System.out.println(" File Name >>>> "+filename);
if(!filename.endsWith(".ppt")){
System.out.println(" *** File is not PPT file ***");
break;
}
Presentation srcPres = new Presentation(new FileInputStream( dir + "/" + filename ));
Point size = new Point(5760,4320);
Presentation newPres = new Presentation();
newPres.setSlideSize(size);
System.out.println("SLIDE Size ==="+size);

for (int iSlidesCounter = 0; iSlidesCounter < children.length; iSlidesCounter++) {
Slide srcSld = srcPres.getSlideByPosition( 1 );
srcPres.cloneSlide(srcSld, srcPres.getSlides().getLastSlidePosition()+1 , newPres, new TreeMap());
newPres.getSlides().remove(newPres.getSlideByPosition(1));
newPres.write(new FileOutputStream("d://output/NewPresenation.ppt"));

}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}

Thanks for your reply.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Yes you’re right. I have done the changes what you suggested in the mail and with that iam able to proceed bit further.

But Still Iam facing one issue to achieve this.When iam trying to merging the slides by reading individual PPT’s, the destination PPT is holding the last PPT’s slide.

My understanding here is…each time in the loop clone method is replacing old slide with new slide.

Please see the above code of and correct me where iam wrong.

Scenario:

I have 3 ppts (slide1.ppt, slide2.ppt, slide3.ppt) in the output folder and each ppt has only one slide.

Iam expecting 3 slides in the NewPresentation.ppt file at the end.

But with the code I have attached, NewPresentation.ppt file is holding one slide which is from slide3.ppt

Please help me here. It is very urgent. Quick reply is appreciated.

Thanks & Regards, M.IRfan.

Hello Irfan,

This is the correct code.

try{

File dir = new File("D://output");

String[] children = dir.list();

if (children == null) {

System.out.println(" **** Directory is Empty ****");

} else {

Presentation newPres = new Presentation();

for (int i=0; i<children.length; i++) {

String filename = children[i];

System.out.println(" File Name >>>> "+filename);

if(!filename.endsWith(".ppt")){

System.out.println(" *** File is not PPT file ***");

break;

}

Presentation srcPres = new Presentation(new FileInputStream( dir + "/" + filename ));

Point size = new Point(5760,4320);

//newPres.setSlideSize(size);

System.out.println("SLIDE Size ==="+size);

int srcPresLastSlidePosition=srcPres.getSlides().getLastSlidePosition();

TreeMap map=new TreeMap();

for (int iSlidesCounter = 1; iSlidesCounter <= srcPresLastSlidePosition; iSlidesCounter++) {

Slide srcSld = srcPres.getSlideByPosition( iSlidesCounter );

srcPres.cloneSlide(srcSld, newPres.getSlides().getLastSlidePosition()+1 , newPres, map);

}

}

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

newPres.write(new FileOutputStream("d://output/NewPresenation.ppt"));

}

}catch(Exception e){

e.printStackTrace();

}