Hi Team,
I know to get the slide number, we need to use the below code snippet
slide.getHeaderFooterManager().setSlideNumberVisibility(true)
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.
Thanks
Thilak
@Thilakbabu,
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. slidenumber-example.zip (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.
Thanks,
Thilak Babu
@Thilakbabu,
You can change the position of the slide number shape like this:
var slideSize = presentation.getSlideSize().getSize();
var newX = slideSize.getWidth() - shape.getWidth() - 20;
shape.setX((float)newX);
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.
presentation.getPresentation().getHeaderFooterManager().setAllSlideNumbersVisibility(true);
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 ?
Thanks,
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);
break;
}
}
presentation.save("output.pptx", SaveFormat.Pptx);
presentation.dispose();