getSlideByPosition returns null


#1

Hello!


I try to produce a lot of test presentations with aspose.powerpoint java edition

so at the beginnig of the export i create the slides i need.
and later in the programm i take the slide with

Slide temp = pres.getSlideByPosition(slidePosition);

in my example the presentation has 11 slides. but i got a null, when trying to get slide number 2.

is this an error in the api or maybe i have to take the slides in a different way.


#2

Please always provide examples of ppt file in such situation.


#3

i dont have the ppt file, because the export stops with a nullpointer exception.


#4

Do you create this file by yourself?
Could you explain how you do it and why you think it has 11 slides?


#5
  1. i load objects from a database.
    2. i create a presentation from a template
    3. for each object i create a slide by doing this:
    for (int i = 0; i < fo_col.size() - 1; i++) {
    Slide tmps = tmpss.get(0);
    pres.cloneSlide(tmps, pres.getSlides().getLastSlidePosition() + 1);
    }

    4. i fill the slides

#6

Are you sure tmpss.get(0) is normal slide and not “master title slide”?
Try to use tmpss.getSlideByPosition(1) instead.


#7

By the way, you use wrong cloneSlide function.
cloneSlide with 2 parameters can be used for cloning slides inside one presentation only
but you copy slides to another presentation.
As a result you always will have broken ppt files.


#8
alcrus wrote:
By the way, you use wrong cloneSlide function.
cloneSlide with 2 parameters can be used for cloning slides inside one presentation only
but you copy slides to another presentation.
As a result you always will have broken ppt files.


oh, and what is the right way to create a slide?

#9

TreeMap ids = new TreeMap();
tmpss.cloneSlide(tmps, pres.getSlides().getLastSlidePosition() + 1, pres, ids);

1. cloneSlide should called from source presentation. tmpss.cloneSlide(…);
2. 3d param is target presentation. pres
3. last parameter is empty TreeMap or even null if you don’t need to control how masters will be cloned.


#10

if i open a template by doing this:
Presentation template = new Presentation(new FileInputStream(new File(“templates/BSH.pot”)));

then clone some slides:
Slides tmpss = template.getSlides();
for (int i = 0; i < 2; i++) {
Slide tmps = tmpss.get(0);
template.cloneSlide(tmps, template.getSlides().getLastSlidePosition() + 1);
}

and after some work with the presentation i do a:

template.write(“other.ppt”);


this seems to be ok for me and the presentation is not broken.
but is this the right way??


#11

Please replace
Slide tmps = tmpss.get(0);
with
Slide tmps = tmpss.getSlideByPosition(1);

Other things are ok in this example.