Hi Support,
I need to put Footnote Reference into Footnote Content in programmatic way because I’d like to have a control of its position in Footnote Content.
I found a similar Topic that shows how to do so: The label of footnote are not added when generate docx, and PDF - #2 by alexey.noskov
I tried to do the same with the following code snippet:
@Test
void asposeDocument_addFootnote() throws Exception {
// given
Document document = new Document();
// and: Footnote
Footnote footnote = new Footnote(document, FootnoteType.FOOTNOTE);
footnote.getFont().setStyleIdentifier(StyleIdentifier.FOOTNOTE_REFERENCE);
footnote.isAuto(true);
Paragraph footnoteParagraph = new Paragraph(document);
footnoteParagraph.getParagraphFormat().setStyleIdentifier(StyleIdentifier.FOOTNOTE_TEXT);
Run footnoteReferenceMark = new Run(document);
footnoteReferenceMark.getFont().setStyleIdentifier(StyleIdentifier.FOOTNOTE_REFERENCE);
footnoteReferenceMark.setText("\u0002");
footnoteParagraph.appendChild(footnoteReferenceMark);
footnoteParagraph.appendChild(new Run(document, "Footnote text."));
footnote.appendChild(footnoteParagraph);
// and: Paragraph with appended Footnote
Paragraph paragraph = new Paragraph(document);
paragraph.appendChild(new Run(document, "Some text"));
paragraph.appendChild(footnote);
document.getFirstSection().getBody().appendChild(paragraph);
// expect
document.save("aspose-add-footnote.docx");
document.save("aspose-add-footnote.pdf");
}
Result in Word:
Result in PDF:
Files:
aspose-add-footnote.docx (7.9 KB)
aspose-add-footnote.pdf (16.0 KB)
It displays correctly in Word, but not in PDF.
There is no such issue when the method DocumentBuilder#insertFootnote is used.
I noticed that the method DocumentBuilder#insertFootnote uses internally SpecialChar object instead of Run as a representation of Footnote Reference. Unfortunately, there is no possibility to create an instance of SpecialChar due to its package-private access.
In this case, I’d like to ask how to insert Footnote Reference into Footnote Content so it renders properly when saving to Word and PDF?
Thank you in advance.