none
How to add page number to Powerpoint prsentation using Interop.Powerpoint in c# ? RRS feed

  • Question

  • I need to add page numbers after merging power point slides to the footer section.

    Can somebody share the sample code to add page numbers?

    Thanks


    VM7258

    Tuesday, May 15, 2012 5:41 PM

Answers

  • Hi vm7258,

    As far as I know that In presetation hasn't existed "Footer". I mean that there only a placeholder has been insert into slide to show the index of the slide. Maybe you can approach it via following snippet.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Office.Tools.Ribbon;
    using PowerPoint = Microsoft.Office.Interop.PowerPoint;
    
    namespace PowerPointAddIn1
    {
        public partial class Ribbon1
        {
            private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, RibbonControlEventArgs e)
            {
                PowerPoint.Application ppapp = Globals.ThisAddIn.Application;
                PowerPoint.Presentation pp = ppapp.ActivePresentation;
                foreach (PowerPoint.Slide slide in pp.Slides)
                {
                    PowerPoint.Shape shape = slide.Shapes.AddLabel(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 620, 490, 100, 50);
                    shape.TextFrame.TextRange.Text = slide.SlideIndex.ToString();
                }
            }
        }
    }

    Best Regards,

    T.X.

    • Marked as answer by vm7258 Wednesday, May 16, 2012 1:49 PM
    Wednesday, May 16, 2012 3:00 AM

All replies

  • Hi vm7258,

    As far as I know that In presetation hasn't existed "Footer". I mean that there only a placeholder has been insert into slide to show the index of the slide. Maybe you can approach it via following snippet.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Office.Tools.Ribbon;
    using PowerPoint = Microsoft.Office.Interop.PowerPoint;
    
    namespace PowerPointAddIn1
    {
        public partial class Ribbon1
        {
            private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
            {
    
            }
    
            private void button1_Click(object sender, RibbonControlEventArgs e)
            {
                PowerPoint.Application ppapp = Globals.ThisAddIn.Application;
                PowerPoint.Presentation pp = ppapp.ActivePresentation;
                foreach (PowerPoint.Slide slide in pp.Slides)
                {
                    PowerPoint.Shape shape = slide.Shapes.AddLabel(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 620, 490, 100, 50);
                    shape.TextFrame.TextRange.Text = slide.SlideIndex.ToString();
                }
            }
        }
    }

    Best Regards,

    T.X.

    • Marked as answer by vm7258 Wednesday, May 16, 2012 1:49 PM
    Wednesday, May 16, 2012 3:00 AM
  • T.X

    It worked and Thanks for your response.

    VM


    VM7258

    Wednesday, May 16, 2012 1:50 PM