Add Text and logo in slides- Power Point

Hi
How can i add logo(Image), and copy right text, title, Header Or Footer in slides, when i export my data in PowerPoint. Can We do this task by make MainMaster slide in template PPT file?
Please can you give suitable example.

Thanks & regards
Srrinu

Dear Srinnu,

Thank you for considering Aspose.Slides.

To add logo, you need to add a pictureframe with desired width and height. Please see the code, how to add a pictureframe from Aspose.Slides Wiki.

http://www.aspose.com/Wiki/default.aspx/Aspose.Slides/AddingPictureFrame.html

You can add text by adding TextFrame. To add textframe, please see the Working With Text section.

http://www.aspose.com/Wiki/Default.aspx/Aspose.Slides/

Also, see this thread.

http://www.aspose.com/Community/Forums/88610/ShowThread.aspx

Further, to add title, subtitle, you can use textframes or placeholders. If you want to use placeholders, then you will first add a title slide using Presentation.AddTitleSlide method, and then add text as told in Working With Text section above.

To set header/footer of slide/master slide, please see this thread

<A href="</A> </P></FONT>

Hi msfaiz,

Many many thanks for your response, now i have one master screen, my problem is how can i insert OR add , some text and page number in footer of the master slid.

Can i add logo of my company in right footer for master slide if yes pleas give suitable example.

Sampale code where i m geting Error " object reference not set to …"

Presentation presAsserts = new Presentation();
Slide slid = presAsserts.AddEmptySlide();

MainMaster masterSld = presAsserts.MainMaster;

masterSld.HeaderFooter.IsFooterVisible = true;
masterSld.HeaderFooter.IsDateTimeVisible = true;
masterSld.HeaderFooter.IsPageNumberVisible = true;
masterSld.HeaderFooter.FooterText = “First Slide Footer”;






Thanks and Regards
Srinu

First get the reference to slide master from Presentation.MainMaster.

You can get it like this.

Slide sld=Presentation.MainMaster as Slide;

then, just add pictureframe to footer or change the footer textframe's background as image. You can see these examples in WIKI.

Once you got the reference to footer textframe, you can also add text into it.

e.g

TextFrame footerTextFrame=sld.Shapes[idx].TextFrame; //suppose footer is present at idx index

footerText.Paragraphs[0].Portions[0].Text="Some Text";

Hi,

I also got the same issue () when trying to access the HeaderFooter property of MainMaster.

Please advice if this is a bug?

Thanks,
Thuc

No, it is not a bug, please tell me what you exactly want to do, I can help you achieve it.

I would like to do some things like:

masterSld.HeaderFooter.IsFooterVisible = true;
masterSld.HeaderFooter.IsDateTimeVisible = true;
masterSld.HeaderFooter.IsPageNumberVisible = true;
masterSld.HeaderFooter.FooterText = "First Slide Footer";

But the HeaderFooter is always null.

I am using Aspose.Slides for .NET version 2.8.4.0

Please advice.

You will have to make use of Metacharacters to set HeaderFooter properties of the master slide.

Please see the following code and its output attached by me.

C#

-------------------------------------------------------------------

Presentation pres = new Presentation();

//Make the page number and footer visible visible

Slide sld = pres.GetSlideByPosition(1);

sld.HeaderFooter.IsPageNumberVisible = true;

sld.HeaderFooter.IsFooterVisible = true;

//Add another slide

sld = pres.AddDoubleBodySlide();

sld.HeaderFooter.IsPageNumberVisible = true;

sld.HeaderFooter.IsFooterVisible = true;

//Set the page number and footer on master slide

Slide mstr = pres.GetSlideById(sld.MasterId);

foreach (Shape shp in mstr.Shapes)

{

if (shp.TextFrame != null)

{

TextFrame tf = shp.TextFrame;

if (tf.MetaCharacters != null)

{

MetaCharacterType metaType = tf.MetaCharacters[0];

switch (metaType)

{

case MetaCharacterType.Footer:

tf.Paragraphs[0].Portions[0].Text = " Footer Text";

break;

case MetaCharacterType.SlideNumer:

tf.Paragraphs[0].Portions[0].Text = " of 10";

break;

default:

break;

}

}

}

}

pres.Write("c:\\outHeaderFooter.ppt");

Here is the same code in JAVA as above.

JAVA

Presentation pres = new Presentation();
Slide sld = pres.getSlideByPosition(1);

//Make the page number and footer visible
sld.getHeaderFooter().setFooterVisible(true);
sld.getHeaderFooter().setPageNumberVisible(true);

//Add another slide
sld = pres.addEmptySlide();
sld.getHeaderFooter().setFooterVisible(true);
sld.getHeaderFooter().setPageNumberVisible(true);

//Set the page number and footer text on master slide
Slide mstr = pres.getSlideById(sld.getMasterId());
int shpsCount = mstr.getShapes().size();

for (int i = 0; i < shpsCount; i++) {
    com.aspose.slides.Shape shp = mstr.getShapes().get(i);
    TextFrame tf = shp.getTextFrame();

    if (tf != null) {
        MetaCharacters metaChars = tf.getMetaCharacters();
        if (metaChars != null) {
            int metaType = metaChars.get(0);
            if (metaType == MetaCharacterType.FOOTER) {
                Paragraph para = tf.getParagraphs().get(0);
                Portion port = para.getPortions().get(0);
                port.setText(" Footer Text");
            }//if
            else if (metaType == MetaCharacterType.SLIDE_NUMBER) {
                Paragraph para = tf.getParagraphs().get(0);
                Portion port = para.getPortions().get(0);
                port.setText(" of 10");
            }//else if
        }//if metacharacters are not null
    }//if text frame is not null
}//for

pres.write(new FileOutputStream("c:\\outHeaderFooter.ppt"));

Hi msfaiz,

The above code for java works fine ,I modified the above code to header and set the header text , but it is not visible , is there any possiblilty to create header in PPT.

Regards

Janakiraman

Dear Janakiraman,

You should add a textframe on master slide at the top, which will work as a header text on all normal slides.

Hi,

I have added the TextFrame using below code

Shape shp1 = slide.getShapes().addRectangle(

2500, 400, 2000, 370);

shp1.getLineFormat().setShowLines(false);

TextFrame tf1 = shp1.addTextFrame("");

tf1.setText( " AAAAAAAAAAA ");

Portion port1 = tf1.getParagraphs().get(0).getPortions().get(0);

but the the thing is i want to set the header as you did for Footer and setting Slide number using

MetaCharacters.

How to set the Header using MetaCharacterType.HEADER

Regards

Janakiraman

Dear Janakiraman,

Header does not appear on Normal view. It appears in Notes Page view. See the image below and area marked by red color.

To make it appear in normal view, you need to add a textframe on master slide.

To open notes page view, follow View – > Notes Page

Hi msfaiz,

Thanks for your reply.

Is it possible to create Header and Footer (as you said using TextFrame )in PPTX file using .Net or Java.

Regards

Janakiraman

Dear Janakiraman,

Adding textframe inside PPTX is under development, so it is not possible right now.

Hi Msfaiz

This code is work fine .but i need something extra… I need Slide number format in (Page 1 of 2)
I tried to insert new Portions to Paragraphs[0] but did not get the out put I need.
Any suggestion?.

thanks
Gayan



msfaiz:

You will have to make use of Metacharacters to set HeaderFooter properties of the master slide.

Please see the following code and its output attached by me.

C#

-------------------------------------------------------------------

Presentation pres = new Presentation();

//Make the page number and footer visible visible

Slide sld = pres.GetSlideByPosition(1);

sld.HeaderFooter.IsPageNumberVisible = true;

sld.HeaderFooter.IsFooterVisible = true;

//Add another slide

sld = pres.AddDoubleBodySlide();

sld.HeaderFooter.IsPageNumberVisible = true;

sld.HeaderFooter.IsFooterVisible = true;

//Set the page number and footer on master slide

Slide mstr = pres.GetSlideById(sld.MasterId);

foreach (Shape shp in mstr.Shapes)

{

if (shp.TextFrame != null)

{

TextFrame tf = shp.TextFrame;

if (tf.MetaCharacters != null)

{

MetaCharacterType metaType = tf.MetaCharacters[0];

switch (metaType)

{

case MetaCharacterType.Footer:

tf.Paragraphs[0].Portions[0].Text = " Footer Text";

break;

case MetaCharacterType.SlideNumer:

tf.Paragraphs[0].Portions[0].Text = " of 10";

break;

default:

break;

}

}

}

}

pres.Write("c:\\outHeaderFooter.ppt");

Hello,

It’s better to use template presentation with already added “Page x of y” frame instead of creating this text from scratch. Also you can add these frames as static text. Most probably you already know the page numbers of slides when you generate a presentation.

One additional comment. MS PowerPoint always inserts ‘*’ character at the metacharacter position so it’s better to do the same with generated textframes.

Hi, adding “1 of n” code works fine for templates created in 2003 but for 2007 presentations it doesnt display it why is that ?

Hi Aneef,

Thanks for considering Aspose.Slides.

Your query has also been responded in another similar thread. Please follow this link for further details.

We are sorry for your nuisance,

I’m trying to use your example code to replace text in datetime fields, but it appears to only append text to the datetime field. My need is to replace the datetime information with custom text in an arbitrary PowerPoint presentation.