Madecho
September 18, 2024, 5:14am
1
i’m trying to change FootnoteSeparator
, i wish all the FootnoteSeparator
in the file can be changed to Single Space and 0 firstLineIndent. my codes is :
Document document = new Document("src/test/resources/docx/test.docx", loadOptions);
FootnoteSeparatorCollection footnoteSeparators = document.getFootnoteSeparators();
for (FootnoteSeparator footnoteSeparator : footnoteSeparators)
{
for (Paragraph paragraph : footnoteSeparator.getParagraphs())
{
ParagraphFormat paragraphFormat = paragraph.getParagraphFormat();
paragraphFormat.setFirstLineIndent(0);
paragraphFormat.setLineSpacingRule(LineSpacingRule.EXACTLY);
}
}
document.save("src/test/resources/docx/result.docx");
however it doesn’t work, how can i adjust my codes since there’s no example now. my document is here
test.docx (2.4 MB)
@Madecho Your code is correct and properly changes the separator properties. Here is XML that represents footnote separator before changes:
<w:footnote w:type="separator" w:id="-1">
<w:p w14:paraId="756DBA6F" w14:textId="77777777" w:rsidR="005C6A08" w:rsidRDefault="005C6A08">
<w:pPr>
<w:spacing w:line="240" w:lineRule="auto"/>
<w:ind w:firstLine="480"/>
</w:pPr>
<w:r>
<w:separator/>
</w:r>
</w:p>
</w:footnote>
And here is XML after chnages:
<w:footnote w:type="separator" w:id="0">
<w:p w:rsidR="005C6A08" w14:paraId="756DBA6F" w14:textId="77777777">
<w:pPr>
<w:spacing w:line="240" w:lineRule="exact" />
<w:ind w:firstLine="0" />
</w:pPr>
<w:r>
<w:separator />
</w:r>
</w:p>
</w:footnote>
Could you please provide the expected output you would like to get? We will check it and provide you more information.
Madecho
September 18, 2024, 6:19am
3
@alexey.noskov
this is the output of my code , still no changed
and i wish it can be changed to
@Madecho As shown in my previous post, the changes are properly applied to the separator. Could you please attach the expected output in DOCX format?
Madecho
September 18, 2024, 6:38am
5
@alexey.noskov result.docx (3.4 MB)
here’s the result I want.
@Madecho Thank you for additional information, but the attached result document does not correspond the input document attached earlier, so we cannot check the both documents for differences. Could you please attach input and expected output, which is created by modifying the input document in MS Word?
Madecho
September 18, 2024, 6:46am
7
@alexey.noskov ok.
here is the input
test.docx (3.4 MB)
and here is the ouput
result.docx (3.4 MB)
like i mentioned above , what i expeted to change didn’t work
@Madecho Unfortunately, I cannot reproduce the problem on my side. Here are footnote separator properties from your expected output document:
<w:footnote w:type="separator" w:id="0">
<w:p>
<w:pPr>
<w:spacing w:line="240" w:lineRule="exact" />
<w:ind w:firstLine="0" />
</w:pPr>
<w:r>
<w:separator />
</w:r>
</w:p>
</w:footnote>
<w:footnote w:type="continuationSeparator" w:id="1">
<w:p>
<w:pPr>
<w:spacing w:line="240" w:lineRule="exact" />
<w:ind w:firstLine="0" />
</w:pPr>
<w:r>
<w:continuationSeparator />
</w:r>
</w:p>
</w:footnote>
After running the following code:
Document doc = new Document("C:\\Temp\\in.docx");
FootnoteSeparatorCollection footnoteSeparators = doc.getFootnoteSeparators();
for (FootnoteSeparator footnoteSeparator : footnoteSeparators)
{
for (Paragraph paragraph : footnoteSeparator.getParagraphs())
{
ParagraphFormat paragraphFormat = paragraph.getParagraphFormat();
paragraphFormat.setFirstLineIndent(0);
paragraphFormat.setLineSpacingRule(LineSpacingRule.EXACTLY);
}
}
doc.save("C:\\Temp\\out.docx");
The output document has exactly the same properties:
<w:footnote w:type="separator" w:id="0">
<w:p>
<w:pPr>
<w:spacing w:line="240" w:lineRule="exact" />
<w:ind w:firstLine="0" />
</w:pPr>
<w:r>
<w:separator />
</w:r>
</w:p>
</w:footnote>
<w:footnote w:type="continuationSeparator" w:id="1">
<w:p>
<w:pPr>
<w:spacing w:line="240" w:lineRule="exact" />
<w:ind w:firstLine="0" />
</w:pPr>
<w:r>
<w:continuationSeparator />
</w:r>
</w:p>
</w:footnote>
Here is the output document produced on my side: out.docx (3.4 MB)
Madecho
September 18, 2024, 6:58am
9
@alexey.noskov yes, that’s also my question. how should i adjust my code to change it ? is it due to me file ? or my code ? I want to get that expected ouput that I want on the above.
@Madecho As I have mentioned your code on my side produces the same document as your expected output. See the document attached above.
Madecho
September 18, 2024, 7:34am
11
@alexey.noskov alexey. here is my orignal file.
test.docx (24.9 KB)
how can i adjust my FootnoteSeparator from
to
I just change the paragraphformat of FootnoteSeparator 's firstline Indent to ‘none’ and single space.
@Madecho Please modify your code like this:
Document doc = new Document("C:\\Temp\\in.docx");
FootnoteSeparatorCollection footnoteSeparators = doc.getFootnoteSeparators();
for (FootnoteSeparator footnoteSeparator : footnoteSeparators)
{
for (Paragraph paragraph : footnoteSeparator.getParagraphs())
{
ParagraphFormat paragraphFormat = paragraph.getParagraphFormat();
paragraphFormat.setFirstLineIndent(0);
paragraphFormat.setCharacterUnitFirstLineIndent(0);
}
}
doc.save("C:\\Temp\\out.docx");
Madecho
September 18, 2024, 7:45am
13
@alexey.noskov ohhh it works !!! why ? just one line different. Please , could you explain that ? i really want to know it
@Madecho Indents in MS Word documents can be set using absolute units, i.e. ParagraphFormat.FirstLineIndent
, and using characters, i.e. ParagraphFormat.CharacterUnitFirstLineIndent
. In the footnote separator properties in your document the indent is specified only in absolute units.
<w:ind w:firstLine="480"/>
But in Normal stylde in your document both indents are specified:
<w:ind w:firstLine="640" w:firstLineChars="200"/>
When FirstLineIndent
is reset to zero in your old code, MS Word uses the inherited CharacterUnitFirstLineIndent value from the style. So it is required to reset both properties.