How to Right Align the Default Slide Number in PPTX Document in Java?

Hi Team,

I know to get the slide number, we need to use the below code snippet


But could you please help how can we make this slide number to be right aligned in the slide? by default its center aligned… Need to align the slide number… please help.


Thank you for posting the question. Please share the following files:

  • presentation file showing the slide number
  • presentation file edited in PowerPoint with the expected look of the slide number

Then we will assist you to achieve the result.

Hi @andrey.potapov,

Please find the attached presentation. (26.8 KB)

Slide1 -> the default alignment of page number.
Slide 2 -> the alignment which I am expecting

Please help how I can achieve the slide2 alignment of page number using aspose.

Thilak Babu

You can change the position of the slide number shape like this:

var slideSize = presentation.getSlideSize().getSize();
var newX = slideSize.getWidth() - shape.getWidth() - 20;

Please also note that the position of slide numbers in your PowerPoint presentation is defined in a master slide. MasterSlide.png (76.5 KB). Perhaps, you should change the position of slide numbers on the master or layout slides.

Hi @andrey.potapov

I have enabled the slide number visibility.
I don’t understand the shape.getWidth()
shape.setX((float)newX); … Where can i get slide number shape?
Could you please post the sample code.

Hi @andrey.potapov,

Have you given the code snippet in java? I don’t think so… Also could you please let us know whats the shape object? how to get that instance ?

Thilak Babu

@Thilakbabu, @manikandan1234,
Please try using the following code example. It changes the position of the slide number on the first slide in the presentation you attached.

var presentation = new Presentation("slidenumber-example.pptx");

var slideSize = presentation.getSlideSize().getSize();

var firstSlide = presentation.getSlides().get_Item(0);
for (var shape : firstSlide.getShapes()) {
    // Find the shape of the slide number.
    if (shape.getPlaceholder() != null && shape.getPlaceholder().getType() == PlaceholderType.SlideNumber) {
        // Change the position.
        var newX = slideSize.getWidth() - shape.getWidth() - 20;
        shape.setX((float) newX);
}"output.pptx", SaveFormat.Pptx);