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

Free Support Forum - aspose.com

How to get the font size and text of each textbox/shape based on Vb.net

Hi,support:

Is there any way to get the font size and text of each textbox/shape based on Vb.net?

Thanks for your help!

@ducaisoft,

Please consider using following example on your end.

Public Shared Sub ExtractFontInfo()
    Dim pres As Presentation = New Presentation("Test.pptx")

    For Each slide As ISlide In pres.Slides

        For Each shape As IShape In slide.Shapes

            If TypeOf shape Is IAutoShape Then
                Dim ashp As IAutoShape = CType(shape, IAutoShape)

                If ashp.TextFrame IsNot Nothing Then
                    Dim textFrame As ITextFrame = ashp.TextFrame

                    For Each para As IParagraph In textFrame.Paragraphs

                        For Each portion As IPortion In para.Portions
                            Console.WriteLine("Text is: " & portion.Text)

                            If portion.PortionFormat IsNot Nothing Then
                                Console.WriteLine("Font Size: " & portion.PortionFormat.FontHeight)
                                Console.WriteLine("Font Name: " & portion.PortionFormat.LatinFont.FontName)
                            End If
                        Next
                    Next
                End If
            End If
        Next
    Next
End Sub

Thanks for your reply.
But this still fail to get the text from textboxes because two reasons:

  1. Dim ashp As IAutoShape = CType(shape, IAutoShape), it report shape is unknown from slide, or word or ppt? which cause abort.
  2. if using Dim ashp As IAutoShape, there is no error and can continue ,but all the shapes in the slide return null nothing, no text for the value of portion.text?
    Why? how to fix them?

@ducaisoft.

Please provide a working sample project along with source file on your end. However, before executing following line, you need to check first if the shape that you are trying to typecast is actually an AutoShape or not.

if the shape is a picture frame, when executing Dim ashp As IAutoShape = CType(shape, IAutoShape),it will throw exception.

@ducaisoft,

This is programming error as you are trying to typecast a different shape to some other shape object. Therefore, I shared that you need to verify the shape type before typecasting the shape object to some shape.