Footer Is Not Getting Inserted in Presentation Using Aspose.Slides for Java

Hi
Was trying to insert footer text using Aspose Slides for Java API 23.7 version to a PPTX file.
Referred this link Presentation Header and Footer|Aspose.Slides Documentation
The code snippet used to insert footer text:

pres.getHeaderFooterManager().setAllFootersText(footerText + pres.getCurrentDateTime() + footerText1);
pres.getHeaderFooterManager().setAllFootersVisibility(true);

Footer is not getting inserted.
Can see one text box with “Footer” like image as below:

image.png (1.4 KB)

Also the footer text I wish to insert is like “some text” ,then current date and then “some more text”

like for example “Some text 03/28/2024 Some more text”

How to do that?

Could see only a method like pres.getCurrentDateTime().

Attaching the pptx file ,in which was trying to insert footer text.

pptx.zip (639.3 KB)

Thanks

@Rama_Menon,
Thank you for contacting support.

It seems there is an issue with the PowerPoint presentation itself that you provided, as even in PowerPoint it is impossible to insert the footer. screenshot.png (395.6 KB)

The problem is not related to Aspose.Slides. Unfortunately, I don’t see how to help you.

When i had tried manually inserting the footer in this powerpoint slide, I was able to insert the footer text “Some text 03/28/2024 Some more text”,as you can see here:

image.png (38.9 KB)

@Rama_Menon,
Thank you for the additional information.

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESJAVA-39424

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@Rama_Menon,
Our developers have investigated the case. Please try using the following code snippet:

pres.getHeaderFooterManager().setAllFootersVisibility(true);
pres.getHeaderFooterManager().setAllFootersText(footerText + pres.getCurrentDateTime() + footerText1);

Thanks. Tried the recommended code snippet.

 pres.getHeaderFooterManager().setAllFootersVisibility(true);
 pres.getHeaderFooterManager().setAllFootersText(footerText + pres.getCurrentDateTime() + footerText1);
 pres.save(fileDir+File.separator+fname,SaveFormat.Pptx);

Now it is inserting the footer text. But not in uniformity.

It is right aligned and sometimes with font size smaller etc. We want it to be centered in the bottom in a line or two.Not sure what is the reason.

The pptx files before inserting footer and after inserting footer are uploaded in this link

https://drive.google.com/drive/folders/1-aeXB3nuX7ImuFdybI1y-gNq2_Cf2_CE?usp=sharing

Also how do we give font colour to the footer text.

Thanks

@Rama_Menon,
You can find all footer shapes, change their position and size, and set the color of text like this:

String footerText = "Once printed, this document is reference only. This document is valid for Tue Apr 30 11:30:21 IST 2024/on the date printed. Please reference Agile for the latest revision";
float footerWidth = 600;
float footerHeight = 40;
Color footerColor = Color.RED;

Presentation presentation = new Presentation(inputFilePath);
Dimension2D slideSize = presentation.getSlideSize().getSize();

float footerX = (float)(slideSize.getWidth() - footerWidth) / 2;
float footerY  = (float)(slideSize.getHeight() - footerHeight - 20);

presentation.getHeaderFooterManager().setAllFootersVisibility(true);
presentation.getHeaderFooterManager().setAllFootersText(footerText);

for(ISlide slide : presentation.getSlides()) {
    for (IShape shape : slide.getShapes()) { // Searching for a footer placeholder.
        if (shape.getPlaceholder() != null &&
            shape.getPlaceholder().getType() == PlaceholderType.Footer) {
            IAutoShape footerShape = (IAutoShape) shape;

            // Set the footer shapes to be centered at the bottom.
            footerShape.setX(footerX);
            footerShape.setY(footerY);
            footerShape.setWidth(footerWidth);
            footerShape.setHeight(footerHeight);

            // Center the footer text.
            IParagraph paragraph = footerShape.getTextFrame().getParagraphs().get_Item(0);
            paragraph.getParagraphFormat().setAlignment(TextAlignment.Center);

            // Change the color of the footers.
            IPortion textPortion = paragraph.getPortions().get_Item(0);
            IFillFormat fillFormat = textPortion.getPortionFormat().getFillFormat();
            fillFormat.setFillType(FillType.Solid);
            fillFormat.getSolidFillColor().setColor(footerColor);
            break;
        }
    }
}

presentation.save(outputFilePath, SaveFormat.Pptx);
presentation.dispose();

Manage Placeholder|Aspose.Slides Documentation
Text Formatting|Aspose.Slides Documentation

Thanks for the code.

Can you let us know the package to be used for

Color footerColor = Color.RED;

in the Aspose Slides Java API.

or is it java.awt.Color package to be used?

@andrey.potapov
Used the java.awt.Color package.

Footer is getting inserted, but looks like the existing footer text gets removed.

Like if you see the power point slide before inserting the footer text, there is an existing footer text like “PR003110 REV 001”. That is getting removed.

Is it possible to preserve the existing footer text also?

Also the footer text is shown in upper case in some slides .

Uploading the powerpoint after inserting the footer text using the code you had mentioned.

pptfile.zip (4.9 MB)

@Rama_Menon,

Yes, that is it.

I am working on the remaining issues and will get back to you soon.

@Rama_Menon,
Could you kindly share a presentation file created in PowerPoint manually based on the “PR003109.pptx” file and containing the footer with the expected result?

Is it possible to have both the footer text like "“Once printed, this document is reference only. This document is valid for Tue Apr 30 11:30:21 IST 2024/on the date printed. Please reference Agile for the latest revision” that one in the center and the existing footer "PR003109 REV 001"on the right of it .

@Rama_Menon,
Because the footer placeholder is already taken, you can add new shapes to slides with the text you mentioned. It looks like you want to add watermarks to presentation slides. The following code example shows you how to do this:

String footerText = "Once printed, this document is reference only. " +
                    "This document is valid for Tue Apr 30 11:30:21 IST 2024/on the date printed. " +
                    "Please reference Agile for the latest revision";
float footerWidth = 600;
float footerHeight = 40;
Color footerColor = Color.RED;
int fontHeight = 14;

Presentation presentation = new Presentation(inputFilePath);
try {
    Dimension2D slideSize = presentation.getSlideSize().getSize();

    float footerX = (float) (slideSize.getWidth() - footerWidth) / 2;
    float footerY = (float) (slideSize.getHeight() - footerHeight - 20);

    for (ISlide slide : presentation.getSlides()) {
        IAutoShape footerShape = slide.getShapes().addAutoShape(
                ShapeType.Rectangle, footerX, footerY, footerWidth, footerHeight);

        footerShape.getFillFormat().setFillType(FillType.NoFill);
        footerShape.getLineFormat().getFillFormat().setFillType(FillType.NoFill);

        footerShape.getTextFrame().setText(footerText);

        IParagraph paragraph = footerShape.getTextFrame().getParagraphs().get_Item(0);
        paragraph.getParagraphFormat().setAlignment(TextAlignment.Center);
        paragraph.getParagraphFormat().getDefaultPortionFormat().setFontHeight(fontHeight);

        // Set the text color for the footer.
        IFillFormat fillFormat = paragraph.getParagraphFormat().getDefaultPortionFormat().getFillFormat();
        fillFormat.setFillType(FillType.Solid);
        fillFormat.getSolidFillColor().setColor(footerColor);

        // Lock the footer shape.
        footerShape.getAutoShapeLock().setSelectLocked(true);
        footerShape.getAutoShapeLock().setSizeLocked(true);
        footerShape.getAutoShapeLock().setTextLocked(true);
        footerShape.getAutoShapeLock().setPositionLocked(true);
        footerShape.getAutoShapeLock().setGroupingLocked(true);
    }

    presentation.save(outputFilePath, SaveFormat.Pptx);
}
finally {
    presentation.dispose();
}

Watermark|Aspose.Slides Documentation