News Category

How to reset the position of the date time and slide number for the presentation slides

2017-12-25 09:12:30 Written by  support iceblue
Rate this item
(0 votes)

We have already demonstrated whether to display the additional information for presentation slides on header and footer area, such as hide or display date and time, the slide number, and the footer with the help of Spire.Presentation. This article will show you how to reset the position of the slide number and the date time in C#. We will also demonstrate how to reset the display format for the date and time from MM/dd/yyyy to yy.MM.yyyy on the presentation slides.

Firstly, view the default position of the date time at the left and the slide number at the right.

How to reset the position of the date time and slide number for the presentation slides

Step 1: Create a presentation document and load the file from disk.

Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx", FileFormat.Pptx2013);

Step 2: Get the first slide from the sample document.

ISlide slide = presentation.Slides[0];

Step 3: Reset the position of the slide number to the left and date time to the center, and reset the date time display style.

foreach (IShape shapeToMove in slide.Shapes)
{
    if (shapeToMove.Name.Contains("Slide Number Placeholder"))
    {
        shapeToMove.Left =0;                                                  
     }

    else if (shapeToMove.Name.Contains("Date Placeholder"))
    {
        shapeToMove.Left = presentation.SlideSize.Size.Width / 2;
       
        (shapeToMove as IAutoShape).TextFrame.TextRange.Paragraph.Text = DateTime.Now.ToString("dd.MM.yyyy");
        (shapeToMove as IAutoShape).TextFrame.IsCentered = true;
    }
}

Step 4: Save the document to file.

presentation.SaveToFile("Result.pptx", FileFormat.Pptx2013);

Effective screenshot after reset the position and the format for the date time and slide number.

How to reset the position of the date time and slide number for the presentation slides

Full codes of how to reset the position of slide number and date time:

using Spire.Presentation;
using System;
namespace ResetPosition
{

    class Program
    {

        static void Main(string[] args)
        {
            Presentation presentation = new Presentation();

            presentation.LoadFromFile("Sample.pptx", Spire.Presentation.FileFormat.Pptx2013);

            ISlide slide = presentation.Slides[0];

            foreach (IShape shapeToMove in slide.Shapes)
            {
                if (shapeToMove.Name.Contains("Slide Number Placeholder"))
                {
                    shapeToMove.Left = 0;

                }

                else if (shapeToMove.Name.Contains("Date Placeholder"))
                {
                    shapeToMove.Left = presentation.SlideSize.Size.Width / 2;

                    (shapeToMove as IAutoShape).TextFrame.TextRange.Paragraph.Text = DateTime.Now.ToString("dd.MM.yyyy");
                    (shapeToMove as IAutoShape).TextFrame.IsCentered = true;
                }

            }
            presentation.SaveToFile("Result.pptx", Spire.Presentation.FileFormat.Pptx2013);

        }
    }
}

Additional Info

  • tutorial_title: Reset the position of the date time and slide number
Last modified on Friday, 24 September 2021 09:30