Search in sources :

Example 1 with CTFtnEdnRef

use of org.docx4j.wml.CTFtnEdnRef in project TranskribusCore by Transkribus.

the class DocxBuilder method addFootnote.

public static void addFootnote(int i, String text, FootnotesPart footnotesPart, R r) throws JAXBException, Docx4JException {
    // Add the note number in the run
    CTFtnEdnRef ftnednref = factory.createCTFtnEdnRef();
    JAXBElement<org.docx4j.wml.CTFtnEdnRef> ftnednrefWrapped = factory.createRFootnoteReference(ftnednref);
    r.getContent().add(ftnednrefWrapped);
    ftnednref.setId(BigInteger.valueOf(i));
    // escape the special chars for XML
    String escapedText = StringEscapeUtils.escapeXml(text);
    /*
	     * Test: try to set footnote reference
	     */
    org.docx4j.wml.RPr props = factory.createRPr();
    RStyle rStyle = new RStyle();
    rStyle.setVal("FootnoteReference");
    props.setRStyle(rStyle);
    r.setRPr(props);
    // Create a footnote in the footnotesPart
    String openXML = "<w:footnote w:id=\"" + i + "\" xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\" xmlns:xml=\"http://www.w3.org/XML/1998/namespace\">" + "<w:p>" + "<w:pPr>" + "<w:pStyle w:val=\"FootnoteText\"/>" + "<w:rPr>" + "<w:lang w:val=\"en-AU\"/>" + "</w:rPr>" + "</w:pPr>" + "<w:r>" + "<w:rPr>" + "<w:rStyle w:val=\"FootnoteReference\"/>" + "<w:vertAlign w:val=\"superscript\" />" + "</w:rPr>" + "<w:footnoteRef/>" + "</w:r>" + "<w:r>" + "<w:t xml:space=\"preserve\"> </w:t>" + "</w:r>" + "<w:r>" + "<w:rPr>" + "<w:lang w:val=\"en-AU\"/>" + "</w:rPr>" + "<w:t>" + escapedText + "</w:t>" + "</w:r>" + "</w:p>" + "</w:footnote>";
    CTFtnEdn ftnedn = (CTFtnEdn) XmlUtils.unmarshalString(openXML, Context.jc, CTFtnEdn.class);
    footnotesPart.getContents().getFootnote().add(ftnedn);
}
Also used : CTFtnEdnRef(org.docx4j.wml.CTFtnEdnRef) CTFtnEdn(org.docx4j.wml.CTFtnEdn) RStyle(org.docx4j.wml.RStyle) RPr(org.docx4j.wml.RPr)

Aggregations

CTFtnEdn (org.docx4j.wml.CTFtnEdn)1 CTFtnEdnRef (org.docx4j.wml.CTFtnEdnRef)1 RPr (org.docx4j.wml.RPr)1 RStyle (org.docx4j.wml.RStyle)1