Sign UpSign Up   Sign InSign In Welcome Guest,
Live Chat Live Chat

Understanding difference Placeholder-Textholder-TextFrame

  •  06-11-2007, 8:27 PM

    Understanding difference Placeholder-Textholder-TextFrame

    Attachment: Present (inaccessible)

    Dear AsAd,

     

    FYI: TextHolders are actually Placeholders that have text in them; they are shipped with MS-PowerPoint as a Slide Layout. You cannot create them yourself. The example of TextHolder is the Placeholder, which says “Click to add title” or “Click to add subtitle” etc

     

    TextFrames are like Text Boxes in MS-PowerPoint. Like you can create as many text boxes as you want on a slide, you can create as many textframes using Aspose.Slides.

     

    Now, when we know the difference between them, we should know how to differ between them in Aspose.Slides.

     

    You can differ between TextHolder and TextFrame by watching the Shape.IsTextHolder property.

     

    For example to extract the text out of shape you will write a code like this

     

    if (shp.IsTextHolder)

    {

        TextHolder th = shp.Placeholder as TextHolder;

        Console.WriteLine(th.Text);

        th.Text=th.Text + “ changed”;

    }

    else

    {

        if (shp.TextFrame != null)

        {

            TextFrame tf = shp.TextFrame;

            Console.WriteLine(tf.Text);

            tf.Text=tf.Text + “ changed”;

        }

    }

     

    If you want to read/write all the text on some slide, you will iterate through all the shapes on that slide and read/write the text from them using above code. Complete code for this is shown below.

     

    Besides above method, you can also read the TextHolders from Slide.Placeholders collection. However, this collection has 8 hardcoded placeholders and the first, Slide.Placeholders[0] correspond to Title Placeholder/Textholder, the second is for Body /Subtitle Placeholder/TextHolder and so on...

     

    For example, if your slide has a title placeholder you can read/write its text using this code.

     

    TextHolder th=sld.Placeholders[0] as TextHolder;

    Console.WriteLine(th.Text);

    th.Text=th.Text + “ changed”;

     

    This is the code, I have also attached the sample source presentation along with code and also output presentation generated by me. Hopefully, it clarifies you everything.

     

    Presentation srcPres = new Presentation(@"c:\srcPlaceholder-Textholder-TextFrame.ppt");

    Slide sld = srcPres.GetSlideByPosition(1);

    foreach (Shape shp in sld.Shapes)

    {

    if (shp.IsTextHolder)

    {

    TextHolder th = shp.Placeholder as TextHolder;

    Console.WriteLine(th.Text);

    th.Text = th.Text + " changed";

    }

    else

    {

    if (shp.TextFrame != null)

    {

    TextFrame tf = shp.TextFrame;

    Console.WriteLine(tf.Text);

    tf.Text = tf.Text + " changed";

    }

    }

    }

    srcPres.Write(@"c:\out.ppt");

     


    Many Thanks and Kind Regards,

    Shakeel Faiz
    Support Developer
    Aspose Sialkot Team
    Contact Us
    Aspose - The .NET and Java Component Publisher

    Keep in touch! We're on Twitter and Facebook
View Complete Thread