Aspose API - Inserting Footnote Reference into Footnote Content

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.

@ANDREA.FARRIS You can save/open document in DOCX format before saving it to PDF to fix the problem:

document.save("C:\\Temp\\out.docx");
document = new Document("C:\\Temp\\out.docx"); // fixes the problem with footnote in PDF.
document.save("C:\\Temp\\out.pdf");

It looks like a workaround. I’m looking for a solution that could be used in production code, the core of which is the import/export of large documents. Is there another way to achieve it?

@ANDREA.FARRIS Unfortunately, I do not see other way to resolve the problem.

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): WORDSNET-26238

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.