Search code examples
docx4jfootnotes

How to modify footnote placeholder in docx4j


I have a docx file which contains a footnote. I have a placeholder in the footnote text that needs to be replaced. While extracting the nodes and modifying the textvalue that placeholder went unpassed. For some reason I think it is not picking up the text provided in the footnote.

Can u please guide me as to how u get to replace a placeholder in the footnote.


Solution

  • Since @JasonPlutext's answer did not work for my case I am posting what worked for me

    FootnotesPart fp = template.getMainDocumentPart().getFootnotesPart();
    List<Object> texts = fp.getJAXBNodesViaXPath("//w:t", true);
    
    for(Object obj : texts) {
        Text text = (Text) ((JAXBElement) obj).getValue();
        String textValue = text.getValue();
        // do variable replacement
        text.setValue(textValue);
    }
    

    But still I face the issue when exporting this as pdf using Docx4J.toPDF(..); The output does not pick up the footnote reference.