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

Free Support Forum - aspose.com

Get Font Size of isTextHolder Shape

Hi all,

I want to extract the font size of the text for each each shape that is a textHolder shape.
Currently I have the following:

for (int j = 0; j < slide.getShapes().size(); j++) {
			IShape shape = slide.getShapes().get_Item(j);

			if (shape instanceof IAutoShape) {

				int shapeType = ((IAutoShape) shape).getShapeType();

				if (shape.isTextHolder() || shapeType == ShapeType.Rectangle) {
					ITextFrame tf = ((IAutoShape) shape).getTextFrame();
					IParagraph firstParagraph = tf.getParagraphs().get_Item(0);
					for (IPortion portion : firstParagraph.getPortions()) {
						if (portion.getPortionFormat().getFontHeight() == Float.NaN) {
							IPortionFormatEffectiveData formateffect = portion.createPortionFormatEffective();
							float height = formateffect.getFontHeight();
						} else {
							float height = portion.getPortionFormat().getFontHeight();
						}
					}
				}
			}
		}

However, what I retrieve is always NaN for the font height. Looking forward to some hints on how to use the methods provided by Aspose API correctly.

Best regards,

Paul

@paulrinckens,

I have observed the requirements shared by you and code seems to be fine. Can you please provide the source presentation with us for which you are trying to extract the font height. We will investigate the requirements further on our end to help you out.

@mudassir.fayyaz

Thank you for you response. Please find here an example pptx file for further investigations:
TitleTemplate2.pptx.zip (33.5 KB)

Best regards,

Paul

@paulrinckens,

I have observed your comments. Can you please try to use sample code that i have shared with you. This will help you to achieve your requirements.

for (int j = 0; j < slide.getShapes().size(); j++) {
IShape shape = slide.getShapes().get_Item(j);

        if (shape instanceof IAutoShape) {

            int shapeType = ((IAutoShape) shape).getShapeType();

            if (shape.isTextHolder() || shapeType == ShapeType.Rectangle) {
                ITextFrame tf = ((IAutoShape) shape).getTextFrame();
                IParagraph firstParagraph = tf.getParagraphs().get_Item(0);
                for (IPortion portion : firstParagraph.getPortions()) {
                    if (portion.getPortionFormat() == null || Float.isNaN(portion.getPortionFormat().getFontHeight())) {
                        IPortionFormatEffectiveData formateffect = portion.createPortionFormatEffective();
                        float height = formateffect.getFontHeight();
                    } else {
                        float height = portion.getPortionFormat().getFontHeight();
                    }
                }
            }
        }
    }

Thank you that helped!