Hi,
How can i get the title of each slide in a presentation, with the methods getName() in Slide and with getTitle() presentation i get no results.
Is it possible to get all infos like print time, autjor, edittime, creatdime with one mtehod??
Thanks so far
The function you mentioned are used to read the properties of presentation not slides.
If you want to read the title of the slide or any other text on slide, then you will have to deal with placeholders and textframes to extract the text inside them.
Please read Developer Guide on Aspose.Slides Wiki and Manage Text section.
So, i have to use the methods in Placeholder, Placeholders and textframe to get the information?
Dear Derauf,
Yes, exactly. For your ease, I have written a simple code that reads the text from all the placeholders from the first slide of source presentation which is attached with this post.
This is the code, you can also get it from attachment
import java.io.File;
import java.io.FileInputStream;
import com.aspose.slides.*;
public class clsPPTPractice {
/*
@param
args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
clsPPTPractice pptPrac = new clsPPTPractice();
pptPrac.ExtractText();
} catch (Exception ex) {
}
}
void ExtractText() {
try {
File file = new File("c:\\srcTitleSlide.ppt");
FileInputStream fin = new FileInputStream(file);
Presentation srcPres = new Presentation(fin);
Slide sld = srcPres.getSlideByPosition(1);
Placeholders phlds = sld.getPlaceholders();
int phldsCount = phlds.size();
for (int i = 0; i < phldsCount; i++) {
Placeholder phld = phlds.get(i);
TextHolder thld = (TextHolder) phld;
System.out.println(thld.getText());
}
} catch (Exception ex) {
}
}
}
Is it possible to get only the title from the slide?
Dear Derauf,
Each slide has a collection of placeholders which contains 8 placeholders that are hardcoded. If I am not mistaken, the first placeholder i.e the placeholder at index 0 contains the title of the slide.
So you can get the title of the slide from first placeholder of each slide.
Have you used my code which I posted earlier? please use it, it will give you an idea how to extract text from placeholder.
Hi,
I used your code and it works fine, thank you for your support. I wrote my own Code and the codes works perfectly with PowerPoint Slides without a Master.
But when i want to use the code with Master Slides to get the title of the slides (yes, it is the index 0) i get an java.lang.NullPointerException.
When i surround the methods with a try/catch block to catch en Exception ex, the code works fine and i get the title without errors.
Is it possible to get the titles from Masters without catching the Exception??
Here is my Code Stuff:
Slide[] Folien_Array;
// Doing some stuff to get the slides of a presentation. In Folien_Array there a the whole slides from a presentation.
Placeholders[] test = new Placeholders[Folien_Array.length];
for (int i=0;i<Folien_Array.length;i++) {
test[i] = Folien_Array[i].getPlaceholders(); //Collection von Placeholdern
}
int size = test[0].size();
System.out.println("anzahl der Placeholder: " + test.length);
System.out.println("Anzahl vbnvn: " + size);
for (int i=0; i<test.length;i++) {
try {
Placeholder aua = test[i].get(0);
TextHolder th = (TextHolder)aua;
System.out.println("Die Titel: " + th.getText());
}
catch(Exception e) {}
Dear Derauf,
Actually, placeholders are hardcoded, first placeholder is always header placeholder, second is for sub-header or first body placeholders, so on. There are total 8 placeholders.
If your slide does not have a header placeholder, then placeholder at index 0 will be null, so you should see it at index greater than 0
Please read this post to get an idea about it
The Problem is, that i get a ClassCastException, when i use Slides with MasterLayout. If i catch the Exception it works fine and i get all Stuff in form of text on the Slide.
But it seems to be impossible to use this without getting this Exception.
Also with your example i get the Exception.
Is it a problem in my code, when i catch the Exception?
Please provide me your source presentation, so I test your code on it and provide you any solution of it.
package Testpackage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import com.aspose.slides.*;
public class clsPPTPractise {
/**
* @param args
* @throws PptException
* @throws IOException
*/
public static void main(String[] args) throws IOException, PptException {
clsPPTPractise pptPrac=new clsPPTPractise();
pptPrac.ExtractText();
}
void ExtractText() throws FileNotFoundException, PptException
{
File file=new File(“PowerPointDateien/test5.ppt”);
FileInputStream fin=new FileInputStream(file);
Presentation srcPres=new Presentation(fin);
Slide sld=srcPres.getSlideByPosition(1);
Placeholders phlds= sld.getPlaceholders();
int phldsCount=phlds.size();
System.out.println(phldsCount);
for(int i=0; i<phldsCount; i++)
{
Placeholder phld=phlds.get(i);
TextHolder thld=(TextHolder)phld;
System.out.println(thld.getText());
}
}
}
Dear Derauf,
I found out that your slide contains an empty placeholder that is why, when we cast it into the TextHolder object, it throws exception.
Actually, placeholder’s content can be anything like text, graph, image etc. We can cast the placeholder into textholder provided if its contents are text.
In order to avoid it, the placeholder must contain some text, so that we could cast it into texholder object. That’s why, I have modified your slide by inserting a single space inside the empty placeholder, see test6.ppt attached by me and run the code provided.
I have also added one more check to avoid null pointer exception, it is highlighted below
import java.io.File;
import java.io.FileInputStream;
import com.aspose.slides.*;
public class clsPPTPractice {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
clsPPTPractice pptPrac = new clsPPTPractice();
pptPrac.ExtractText();
} catch (Exception ex) {
}
}
void ExtractText() {
try {
//File file=new File("c:\\srcTitleSlide.ppt");
File file = new File("c:\\test6.ppt");
FileInputStream fin = new FileInputStream(file);
Presentation srcPres = new Presentation(fin);
Slide sld = srcPres.getSlideByPosition(1);
Placeholders phlds = sld.getPlaceholders();
int phldsCount = phlds.size();
for (int i = 0; i < phldsCount; i++) {
Placeholder phld = phlds.get(i);
if (phld != null) {
TextHolder thld = (TextHolder) phld;
System.out.println("[Text]=" + thld.getText());
}
}
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
}