The label of footnote are not added when generate docx, and PDF

Hi,
When we generate a docx from JATS XML and convert to PDF.

  1. When generating docx: the labels of footnote at the bottom of page in the target docx are missing, while the labels on the context are added correctly.
    Our code:
Paragraph paragraph = new Paragraph(docx);
Run runp = new Run(document);
runp.setText("accounting for about 75% of membranous nephropathy (MN) cases");
paragraph.appendChild(runp);
Footnote footnote = new Footnote(docx, FootnoteType.FOOTNOTE);
footnote.getFont().setBold(false);
footnote.getFont().setSuperscript(true);
footnote.isAuto(true);
paragraph.appendChild(footnote);
Paragraph para = new Paragraph(docx);
Run run = new Run(document);
run.setText("Renal functions were stable.");
para.appendChild(run);
footnote.appendChild(para);
Run runp1 = new Run(document);
runp1.setText("About 20%-30% IMN patients");
paragraph.appendChild(runp1);

The attached is the sample.
EN-9-19.docx (747.2 KB)
EN-9-19.pdf (975.4 KB)

  1. When convert to PDF, the labels of footnote both on context and the bottom of page are all missing,
    Here is our code:
com.aspose.words.Document doc;
try
{
    File file1 = new File(pdfPath + "\\EN-9-19.docx");
    String path = pdfPath + "\\EN-9-19.pdf";
    File file = new File(path);
    doc = new com.aspose.words.Document(pdfPath + "\\EN-9-19.docx");
    com.aspose.words.Document doc1 = new com.aspose.words.Document();
    doc1.removeAllChildren();
    doc1.appendDocument(doc, ImportFormatMode.USE_DESTINATION_STYLES);
    doc1.getCompatibilityOptions().setUseFELayout(true);
    doc1.getStyles().getDefaultFont().setLocaleIdFarEast(2052);
    try (FileOutputStream os = new FileOutputStream(file)) {
        doc1.save(os, SaveFormat.PDF);
        return path;
    }
}
catch (Exception e1)
{
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

How to solve the 2 quetion?

Best regard,

@linjiale

  1. I would suggest you to use DocumentBuilder to insert footnotes. Upon inserting a footnote it is required to set special styles to the nodes. For example the following simple code that uses DocumentBuilder does the same as your code and footnote is inserted properly:

    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    
    builder.write("accounting for about 75% of membranous nephropathy (MN) cases");
    builder.insertFootnote(FootnoteType.FOOTNOTE, "Renal functions were stable.");
    builder.write("About 20%-30% IMN patients");
    
    doc.save("C:\\Temp\\out.docx");
    

    However, if you need to do this using DOM, it is required to put footnote reference into the footnote content. For example see the following code that does the same as code above using DOM:

    Document doc = new Document();
    
    Paragraph paragraph = new Paragraph(doc);
    paragraph.appendChild(new Run(doc, "accounting for about 75% of membranous nephropathy (MN) cases"));
    
    Footnote footnote = new Footnote(doc, FootnoteType.FOOTNOTE);
    footnote.getFont().setStyleIdentifier(StyleIdentifier.FOOTNOTE_REFERENCE);
    footnote.isAuto(true);
    paragraph.appendChild(footnote);
    
    Paragraph footnotePara = new Paragraph(doc);
    footnotePara.getParagraphFormat().setStyleIdentifier(StyleIdentifier.FOOTNOTE_TEXT);
    Run footnoteRef = new Run(doc);
    footnoteRef.getFont().setStyleIdentifier(StyleIdentifier.FOOTNOTE_REFERENCE);
    footnoteRef.setText("\u0002"); // This is a footnote character
    footnotePara.appendChild(footnoteRef);
    
    footnotePara.appendChild(new Run(doc, "Renal functions were stable."));
    footnote.appendChild(footnotePara);
    
    paragraph.appendChild(new Run(doc, "About 20%-30% IMN patients"));
    
    doc.getFirstSection().getBody().appendChild(paragraph);
    
    doc.save("C:\\Temp\\out.docx");
    

    Here are output document produced by DocumentBuilder and using DOM: out_documentbuilder.docx (7.9 KB) out_dom.docx (7.9 KB).
    As you can see in both document footnotes look the same and reference number is present. However, DocumentBuilder code looks much simpler.

  2. If use once of the above approaches to insert footnotes they look correct in output PDF: out.pdf (28.7 KB)