Free Support Forum - aspose.com

Reading font style from PPTX

Hi,

How I can read font style from PPTX file?

Thanks, Zeljko.

Hi,

Here is a sample code for that:

try {

FileInputStream is=new FileInputStream("d:\\ppt\\zFONTSTYLE.pptx");

PresentationEx pres = new PresentationEx(is);

is.close();

SlideEx sld= pres.getSlides().get(0);

for(int i=0;i<sld.getShapes().size();i++)

{

System.out.print("hello");

com.aspose.slides.pptx.ShapeEx shp=sld.getShapes().get(i);

if( shp instanceof AutoShapeEx)

{

AutoShapeEx ashp=(AutoShapeEx)shp;

TextFrameEx tf=ashp.getTextFrame();

if(tf!=null)

{

PortionEx port = tf.getParagraphs().get(0).getPortions().get(0);

System.out.println("Font Name = " + port.getRawLatinFont().getFontName() + " , Font Height = " + port.getRawFontHeight());

if (port.getRawFontBold() == NullableBool.TRUE)

System.out.println(" Is Font Bold = True");

}

}

}

} catch (IOException e) {

e.printStackTrace();

}

}

Thanks Muhammad.

Can you help me with getting font color from PortionEx?

Zeljko

Hi,

Its answered in this thread.

msabir:

Hi,

Here is a sample code for that:

try {

FileInputStream is=new FileInputStream("d:\\ppt\\zFONTSTYLE.pptx");

PresentationEx pres = new PresentationEx(is);

is.close();

SlideEx sld= pres.getSlides().get(0);

for(int i=0;i<sld.getShapes().size();i++)

{

System.out.print("hello");

com.aspose.slides.pptx.ShapeEx shp=sld.getShapes().get(i);

if( shp instanceof AutoShapeEx)

{

AutoShapeEx ashp=(AutoShapeEx)shp;

TextFrameEx tf=ashp.getTextFrame();

if(tf!=null)

{

PortionEx port = tf.getParagraphs().get(0).getPortions().get(0);

System.out.println("Font Name = " + port.getRawLatinFont().getFontName() + " , Font Height = " + port.getRawFontHeight());

if (port.getRawFontBold() == NullableBool.TRUE)

System.out.println(" Is Font Bold = True");

}

}

}

} catch (IOException e) {

e.printStackTrace();

}

}



Code you gave me dose not work.

Exception occures near :

System.out.println("Font Name = " + port.getRawLatinFont().getFontName() + " , Font Height = " + port.getRawFontHeight());

Hi,

It will work with only one limitation already discussed with you in this thread.

Hi,

You said me to select the placeholder and change its font. How I can do it.

Thanks,

Zeljko

Hi,

It seems there is some misunderstanding. Let us first check this code works or not. Use this code with the attached presentation. Does it work or not?

Hi,

This code work fine with file from attachment.0

Thanks

Hi,

I confirmed that code above works fine, but I can not use that code for any document. I need
code example for any pptx document. It is urgent!!!

Thanks,

Zeljko

Hi Zelijkoar,

As already discussed with you in this thread, there is a problem accessing font styles that are inherited from the master slide and this problem has been reported. This will be fixed by the second or third week of December, next month. After that, you will be able to access any font styles in any PPTX document.