Free Support Forum - aspose.com

Exception while reading the PPT file

I get the following error when trying to read a PPT file.

java.lang.NoSuchMethodError: java.lang.Integer.valueOf(I)Ljava/lang/Integer;
at com.aspose.slides.Table.getRowsNumber(SourceFile:214)
at com.aspose.slides.Table.(SourceFile:122)
at com.aspose.slides.Slide.(SourceFile:188)
at com.aspose.slides.Presentation.if(SourceFile:330)
at com.aspose.slides.Presentation.(SourceFile:455)
at com.la.utility.ppt.MSPowerPointReader.main(MSPowerPointReader.java:36)
Exception in thread "main"

I am using JDK 1.4.2.

Thanks

Dear reach,

Please provide your source code and source presentation to look into this problem.

MSPowerPointReader mspowerpointreader = new MSPowerPointReader();
FileInputStream fIS = new FileInputStream(new File(“C:\Projects\MSOfficeParser\A.PPT”));
Presentation pres = new Presentation(fIS);
Slides slides = pres.getSlides();

Dear reach,

The code looks fine and should run well. I think, the exception is caused by the A.ppt. Can you please provide it to verify it?

Thank you for your reply.

I have attached the file. I have renamed it to A.doc. Please change it to A.ppt

Thanks

Dear reach,

I did not get this exception, I am using JRE1.6 and Aspose.Slides 1.7.2.0

Thank you for your help. Is that the same version that is bundled with Aspose.Total. I looked up the Sun documentation and the error that I am getting is because I am using jdk 142 and Integer.valueOf(int) is introduced with jdk5.0.

I will try it with JDK 5.0

Please let me know if I am in the right direction.

Dear reach,

Sorry for confusion, I am using JDK 6.0

Thank you. I ran the code with jdk 5.0 and it worked. Now I have another problem. I am trying to read the attached PPT and it returns the placeholders as null.

Below is the code I am using to read this slide.

try
{
MSPowerPointReader mspowerpointreader = new MSPowerPointReader();
FileInputStream fIS = new FileInputStream(new File("C:\\Projects\\MSOfficeParser\\A.PPT"));
Presentation pres = new Presentation(fIS);
Slides slides = pres.getSlides();
int size = slides.size();
System.out.println("Size "+size);

if (size > 0)
{

for(int i=0;i<size;i++)
{
Slide singleSlide = slides.get(i);
processSlide(singleSlide);
}
}

}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void processSlide(Slide singleSlide)
{
try
{
Placeholders placeHolders = singleSlide.getPlaceholders();
System.out.println(singleSlide.getName());
System.out.println("TAGS " +singleSlide.getTags());
Tags tags = singleSlide.getTags();
int tagSize = tags.size();
for (int j=0;j<tagSize;j++)
{
System.out.println("Tag "+tags.getTagName(j));
}
int size = placeHolders.size();
if(size > 0)
{
for (int i=0;i<size;i++)
{
TextHolder textHolder = (TextHolder)placeHolders.get(i);
if(textHolder !=null)
{
System.out.println("Text in Place Holder " + i + "is " +
textHolder.getText());
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}

Please let me know what I am missing.

Dear reach,

First you should use the Slide.getSlidePosition method to get normal slide. You should not get them from Presentation.Slides collection.
The slide position always start from 1

Slide.Placeholders collection contains 8 hardcoded Placeholder objects.
The first placeholder object at index 0 is for title and so on.

Dear faiz,

I am sorry I am not following. I get the slide from the Slides collection. I iterate through them and get all the placeholders using method Slide.getPlaceHolders() which in my case is returning null for each element in the collection.

Let me know if I am missing something or if you have some sample code that I could use.

Thanks

Dear reach,

You should iterate through slides like this

int numSlides=pres.getSlides().getLastSlidePosition();

for(int i=1; i<=numSlides; i++)

{

Slide singleSlide=pres.getSlideByPosition(i);

processSlide(singleSlide);

- - - - - - - -

FYI: Presentation.getSlides() collection also contains title masters along with normal slides, for this reason, Aspose.Slides provide the method Presentation.getSlideByPosition to retrieve normal slides by their position in presentation.

Dear faiz,

Thank you again for your response. I tried the code that you sent to me and I still get all the placeholders as null.

Below is the source code that I now have.

try
{
MSPowerPointReader mspowerpointreader = new MSPowerPointReader();
FileInputStream fIS = new FileInputStream(new File("C:\\Projects\\MSOfficeParser\\A1.PPT"));
Presentation pres = new Presentation(fIS);
/*
Slides slides = pres.getSlides();
int size = slides.size();
System.out.println("Size "+size);
*/
int size = pres.getSlides().getLastSlidePosition();
if (size > 0)
{

for(int i=1;i<=size;i++)
{
Slide singleSlide = pres.getSlideByPosition(i);
processSlide(singleSlide);
}
}

}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void processSlide(Slide singleSlide)
{
try
{
System.out.println("Slide Position "+singleSlide.getSlidePosition());
Placeholders placeHolders = singleSlide.getPlaceholders();
// System.out.println(singleSlide.getName());
// System.out.println("TAGS " +singleSlide.getTags());
// Tags tags = singleSlide.getTags();
// int tagSize = tags.size();
// for (int j=0;j<tagSize;j++)
// {
// System.out.println("Tag "+tags.getTagName(j));
//}
int size = placeHolders.size();
if(size > 0)
{
for (int i=0;i<size;i++)
{
TextHolder textHolder = (TextHolder)placeHolders.get(i);
if(textHolder !=null)
{
System.out.println("Text in Place Holder " + i + "is " +
textHolder.getText());
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}

Please let me know if I need to do anything else.

Regards

Dear reach,

I have checked your presentation A1.ppt, it contains a single slide which does not have any placeholder. Instead, it has one TextFrame and one table object

You can see it by iterating through all shapes and checking the return value of Shape.isTextHolder() method. If it returns true, then the shape is a placeholder containing text which can be converted to textholder, otherwise it is a non-placeholder.

The difference between TextHolder and TextFrame is that TextHolder is a Placeholder having text while TextFrame is a TextBox in MS PowerPoint.

You cannot create Placeholders (Textholders); they are shipped with MS-PowerPoint as Slide Lay Outs

However you can create as many Text Boxes (Text Frames) as you want on a slide.

Dear Faiz,

Thank you for all the help. I am able to get the text of the Powerpoint slide.

Regards

Hi,
is this the only solution? Using JDK6?
I have to use J2SE 4, is that not supported?

Thanks.

Dear vland,

Please see the system requirements for Aspose.Slides for JAVA

http://www.aspose.com/wiki/default.aspx/Aspose.Slides/SystemRequirements.html

System Requirements of Aspose.Slides for Java