for (Paragraph paragraph : footnote.getParagraphs()) {
for (Run run : paragraph.getRuns()) {
run.getFont().setColor(Color.RED);
}
}
To modify the footnote content number style in Aspose.Words for Java, you can adjust the FootnoteOptions
of the document. Unfortunately, the provided code snippet only changes the font color of the footnote text but does not address the numbering style.
Here’s how you can set the footnote numbering style:
- Access the
FootnoteOptions
of the document. - Set the desired numbering style using the
NumberStyle
property.
Here’s an example of how to implement this:
import com.aspose.words.*;
public class ModifyFootnoteNumberStyle {
public static void main(String[] args) throws Exception {
// Load the document
Document doc = new Document("Document.docx");
// Set the footnote numbering style
FootnoteOptions footnoteOptions = doc.getFootnoteOptions();
footnoteOptions.setNumberStyle(FootnoteNumberStyle.UppercaseRoman); // Change to desired style
// Save the modified document
doc.save("ModifiedDocument.docx");
}
}
In this example, the footnote numbering style is set to uppercase Roman numerals. You can choose from various styles such as Arabic
, UppercaseRoman
, LowercaseRoman
, etc., depending on your requirements.
Make sure to adjust the file paths as necessary for your environment. This should help you modify the footnote content number style as needed.
@Crane Could you please attach your input and expected output documents here for our reference? We will check your documents and provide you more information.
Normally, will this operation take effect?
@Crane Could you please attach your input and expected output documents here for our reference? We will check your documents and provide you more information.
original:
footnote.docx (10.8 KB)
current:
output-footnote.docx (10.3 KB)
@Test
void test5() throws Exception {
Document doc = new Document("footnote.docx");
NodeCollection childNodes = doc.getChildNodes(NodeType.FOOTNOTE, true);
for (Object childNode : childNodes) {
if (childNode instanceof Footnote footnote) {
for (Paragraph paragraph : footnote.getParagraphs()) {
for (Run run : paragraph.getRuns()) {
run.getFont().setColor(Color.RED);
}
}
}
}
doc.save("output-footnote.docx");
}
expected:
output-footnote2.docx (10.9 KB)
@Crane Please modify your code like this:
Document doc = new Document("C:\\Temp\\in.docx");
for (Footnote f : (Iterable<Footnote>)doc.getChildNodes(NodeType.FOOTNOTE, true))
{
for (Paragraph paragraph : f.getParagraphs())
{
for (Node n : (Iterable<Node>)paragraph.getChildNodes(NodeType.ANY, false))
{
if (n.getNodeType() == NodeType.RUN)
((Run)n).getFont().setColor(Color.RED);
if (n.getNodeType() == NodeType.SPECIAL_CHAR)
((SpecialChar)n).getFont().setColor(Color.RED);
}
}
}
doc.save("C:\\Temp\\out.docx");