Hi
In Aspose Words for Java, we are using the following code snippet for inserting the footer text
for (Section s : doc.getSections())
{
s.getPageSetup().setDifferentFirstPageHeaderFooter(false);
s.getPageSetup().setOddAndEvenPagesHeaderFooter(false);
// Move to the section.
builder.moveToSection(doc.getSections().indexOf(s));
// Move to footer and put some text
builder.moveToHeaderFooter(com.aspose.words.HeaderFooterType.FOOTER_PRIMARY);
// builder.moveToHeaderFooter(com.aspose.words.HeaderFooterType.FOOTER_EVEN);
// builder.moveToHeaderFooter(com.aspose.words.HeaderFooterType.FOOTER_FIRST);
builder.getFont().setName("Arial");
builder.getFont().setBold(false);
builder.getFont().setSize(10);
builder.write(footerText);
We are using the licensed version of Aspose. The footer text is showing in grey colour.
How to change the footer text to red colour?
Thanks
@Rama_Menon
Cause
The footer text appearing in grey color is likely due to the default font color setting in the document. When you set the font properties for the footer text, you need to explicitly specify the color as well.
Solution
To change the footer text color to red, you can set the font color using the setColor
method on the font object. Here’s how you can modify your existing code to include this change.
Code
Here’s an updated version of your code snippet that sets the footer text color to red:
for (Section s : doc.getSections()) {
s.getPageSetup().setDifferentFirstPageHeaderFooter(false);
s.getPageSetup().setOddAndEvenPagesHeaderFooter(false);
// Move to the section.
builder.moveToSection(doc.getSections().indexOf(s));
// Move to footer and put some text
builder.moveToHeaderFooter(com.aspose.words.HeaderFooterType.FOOTER_PRIMARY);
builder.getFont().setName("Arial");
builder.getFont().setBold(false);
builder.getFont().setSize(10);
builder.getFont().setColor(Color.RED); // Set the font color to red
builder.write(footerText);
}
Next Steps
Run the updated code to see if the footer text now appears in red. If you still encounter issues, ensure that there are no conflicting styles or settings in your document that might override the font color. If the problem persists, consider checking the document’s style settings or consult the documentation for further troubleshooting.
Please let me know if this resolves your issue!
@Rama_Menon This is an expected behavior, MS Word visually displays content of header/footer a little grayed. This is done to visually differentiate header/footer and main document content. But if print or convert the document to PDF header/footer content is rendered with normal color.
@alexey.noskov
ok,so if we include the below code as suggested by the bot
builder.getFont().setColor(Color.RED); // Set the font color to red
will it print in red colour when printed or convert the document to PDF?
@Rama_Menon Yes, the text color will be red in the output PDF.
@alexey.noskov
In evaluation version it shows the footer text in red colour .
In the Temp licensed version , it is showing the footer text in grey colour. How is it behaving differently?
Thanks
@Rama_Menon Could you please elaborate the problem and attach your output and expected output documents along with code that will allow us to reproduce the problem?
@alexey.noskov
Had shared the code snippet earlier. So the problem is , we want the footer text to be red in colour.In the temporary licensed version we are seeing the footer text in gray colour.
But in the evaluation version, we can see the footer text in red colour.
Attaching the footer text portions for both evaluation version and the one from the temporary licensed version for your reference.
screenshot of footer text.docx (60.9 KB)
@Rama_Menon As I can see setting font color works as expected. Here is simple text code:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
for (Section s : doc.getSections())
{
s.getPageSetup().setDifferentFirstPageHeaderFooter(false);
s.getPageSetup().setOddAndEvenPagesHeaderFooter(false);
// Move to the section.
builder.moveToSection(doc.getSections().indexOf(s));
// Move to footer and put some text
builder.moveToHeaderFooter(com.aspose.words.HeaderFooterType.FOOTER_PRIMARY);
builder.getFont().setName("Arial");
builder.getFont().setBold(false);
builder.getFont().setSize(10);
// Uncomment to make text red
builder.getFont().setColor(Color.RED);
builder.write("This is test footer text");
}
doc.save("C:\\Temp\\out.docx");
out.docx (7.7 KB)
Works the same in both evaluation and licensed modes.
@alexey.noskov
ok,should color variable be of java.awt package , as follows:
java.awt.Color footerColor = java.awt.Color.RED;
@Rama_Menon Yes, the color is set using java.awt.Color
.