Search in sources :

Example 31 with R

use of org.docx4j.wml.R in project docx4j-template by vindell.

the class AddingTableOfContent method addTableOfContentField.

/**
 * (不知道该怎么翻译, 因此将英文原注释保留)
 *  Adds the field that Word uses to create a table of content to the paragraph.
 *
 *  First we create a run and a text. Then we indicate that all spaces in the
 *  text are to be preserved and set the value to that of the TOC field.
 *  This field definition takes some arguments. The exact definition can be
 *  found in §17.16.5.58 of the Office Open XML standard. In this case we
 *  specify that we want to include all paragrapsh formatted with headings of
 *  levels 1-3 (\0 “1-3”). We also specify that we want all entries to be
 *  hyperlinks (\h), that we want to hide tab leader and page numbers in Web
 *  layout view (\z), and that we want to use the applied paragraph outline
 *  level (\\u).
 *  Finally we take the text and use it to create a JAXB element containing text
 *  and add this to the run, which we then add to the given paragraph.
 *
 *  将Word用于创建目录表的域添加到段落中.
 *
 *  首先创建一个可运行块和一个文本. 然后指出文本中所有的空格都被保护并给TOC域设置值. 这个域定义
 *  需要一些参数, 确切定义可以在Office Open XML标准的§17.16.5.58找到, 这种情况我们指定所有
 *  段落使用1-3级别的标题来格式化(\0 "1-3"). 我们同时指定所有的实体作为超链接(\h), 而且在Web
 *  视图中隐藏标签和页码(\z), 我们要使用段落大纲级别应用(\\u).
 *  最后使用文本对象创建了一个JAXB元素包含文本并添加到随后被添加到段落中的可运行块中.
 *
 *  @param paragraph
 */
private static void addTableOfContentField(P paragraph) {
    R run = factory.createR();
    Text txt = new Text();
    txt.setSpace("preserve");
    txt.setValue("TOC \\o \"1-3\" \\h \\z \\u");
    run.getContent().add(factory.createRInstrText(txt));
    paragraph.getContent().add(run);
}
Also used : R(org.docx4j.wml.R) Text(org.docx4j.wml.Text)

Example 32 with R

use of org.docx4j.wml.R in project docx4j-template by vindell.

the class WmlElementUtils method createFooter.

/**
 *  First we create a footer, a paragraph, a run and a text. We add the given
 *  given content to the text and add that to the run. The run is then added to
 *  the paragraph, which is in turn added to the footer. Finally we return the
 *  footer.
 *  @param content
 *  @return
 */
public static Ftr createFooter(String content) {
    Ftr footer = factory.createFtr();
    P paragraph = factory.createP();
    R run = factory.createR();
    Text text = new Text();
    text.setValue(content);
    run.getContent().add(text);
    paragraph.getContent().add(run);
    footer.getContent().add(paragraph);
    return footer;
}
Also used : P(org.docx4j.wml.P) R(org.docx4j.wml.R) Ftr(org.docx4j.wml.Ftr) Text(org.docx4j.wml.Text)

Example 33 with R

use of org.docx4j.wml.R in project docx4j-template by vindell.

the class ParagraphUtils method addInlineImageToParagraph.

/**
 *  向新的段落中添加内联图片并返回这个段落.
 *  这个方法与前面例子中的方法没有区别.
 * @param inline
 * @return
 */
public static P addInlineImageToParagraph(Inline inline) {
    // Now add the in-line image to a paragraph
    ObjectFactory factory = new ObjectFactory();
    P paragraph = factory.createP();
    R run = factory.createR();
    paragraph.getContent().add(run);
    Drawing drawing = factory.createDrawing();
    run.getContent().add(drawing);
    drawing.getAnchorOrInline().add(inline);
    return paragraph;
}
Also used : P(org.docx4j.wml.P) Drawing(org.docx4j.wml.Drawing) R(org.docx4j.wml.R) ObjectFactory(org.docx4j.wml.ObjectFactory)

Example 34 with R

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

the class DocxBuilder method createIt.

public static P createIt() {
    org.docx4j.wml.ObjectFactory wmlObjectFactory = new org.docx4j.wml.ObjectFactory();
    P p = wmlObjectFactory.createP();
    // Create object for pPr
    PPr ppr = wmlObjectFactory.createPPr();
    p.setPPr(ppr);
    // Create object for rPr
    ParaRPr pararpr = wmlObjectFactory.createParaRPr();
    ppr.setRPr(pararpr);
    // Create object for u
    U u = wmlObjectFactory.createU();
    pararpr.setU(u);
    u.setVal(org.docx4j.wml.UnderlineEnumeration.SINGLE);
    // Create object for lang
    CTLanguage language = wmlObjectFactory.createCTLanguage();
    pararpr.setLang(language);
    language.setVal("en-AU");
    // Create object for jc
    Jc jc = wmlObjectFactory.createJc();
    ppr.setJc(jc);
    jc.setVal(org.docx4j.wml.JcEnumeration.CENTER);
    // Create object for r
    R r = wmlObjectFactory.createR();
    p.getContent().add(r);
    // Create object for rPr
    RPr rpr = wmlObjectFactory.createRPr();
    r.setRPr(rpr);
    // Create object for u
    U u2 = wmlObjectFactory.createU();
    rpr.setU(u2);
    u2.setVal(org.docx4j.wml.UnderlineEnumeration.SINGLE);
    // Create object for lang
    CTLanguage language2 = wmlObjectFactory.createCTLanguage();
    rpr.setLang(language2);
    language2.setVal("en-AU");
    // Create object for t (wrapped in JAXBElement)
    Text text = wmlObjectFactory.createText();
    JAXBElement<org.docx4j.wml.Text> textWrapped = wmlObjectFactory.createRT(text);
    r.getContent().add(textWrapped);
    text.setValue("Underlined and centred");
    return p;
}
Also used : Text(org.docx4j.wml.Text) P(org.docx4j.wml.P) CTLanguage(org.docx4j.wml.CTLanguage) R(org.docx4j.wml.R) PPr(org.docx4j.wml.PPr) U(org.docx4j.wml.U) RPr(org.docx4j.wml.RPr) ParaRPr(org.docx4j.wml.ParaRPr) ParaRPr(org.docx4j.wml.ParaRPr) Jc(org.docx4j.wml.Jc)

Example 35 with R

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

the class DocxBuilder method getDocxTable.

private static Tbl getDocxTable(WordprocessingMLPackage wPMLpackage, boolean isWordBased, int rows, int cols, List<HashMap<Integer, TrpTableCellType>> allRows, int tablesize, MainDocumentPart mdp) throws Exception {
    int writableWidthTwips = wPMLpackage.getDocumentModel().getSections().get(0).getPageDimensions().getWritableWidthTwips();
    int cellWidthTwips = new Double(Math.floor((writableWidthTwips / cols))).intValue();
    Tbl table = TblFactory.createTable(0, 0, cellWidthTwips);
    TblGrid tblGrid = factory.createTblGrid();
    for (int i = 0; i < cols; i++) {
        TblGridCol col = factory.createTblGridCol();
        col.setW(BigInteger.valueOf(cellWidthTwips));
        tblGrid.getGridCol().add(col);
    }
    table.setTblGrid(tblGrid);
    int i = 0;
    for (HashMap<Integer, TrpTableCellType> entry : allRows) {
        Tr row = factory.createTr();
        table.getContent().add(row);
        i++;
        int d = 0;
        if (entry.keySet().size() != cols) {
            logger.debug("size of entries does not match columns ");
        }
        for (Integer key : entry.keySet()) {
            Tc cell = factory.createTc();
            row.getContent().add(cell);
            String rowSpan = null;
            int colSpan = 1;
            boolean mergedVertical = false;
            int colsize = cellWidthTwips;
            if (entry.get(key) != null) {
                if (entry.get(key).getRowSpan() > 1) {
                    mergedVertical = true;
                    rowSpan = "restart";
                }
                // PageXmlUtils.buildPolygon(entry.get(key).getCoords().getPoints()).getBounds().getMaxX();
                double maxX = entry.get(key).getBoundingBox().getMaxX();
                // PageXmlUtils.buildPolygon(entry.get(key).getCoords().getPoints()).getBounds().getMinX();
                double minX = entry.get(key).getBoundingBox().getMinX();
                double colsizeRel = maxX - minX;
                double colsizetmp = colsizeRel / (double) tablesize;
                // logger.debug("colsizetmp " + colsizetmp);
                colsize = (int) (writableWidthTwips * colsizetmp);
                colSpan = entry.get(key).getColSpan();
                // logger.debug("colsize " + colsize);
                // logger.debug("text in this cell is " + entry.get(key).getUnicodeTextFromLines());
                int colID = entry.get(key).getCol();
                int rowID = entry.get(key).getRow();
            } else {
                // logger.debug("no cell for this column ");
                mergedVertical = true;
            }
            applyGridSpan(cell, colSpan, rowSpan, colsize, mergedVertical);
            P columnPara = factory.createP();
            // P columnPara = (P) column.getContent().get(0);
            cell.getContent().add(columnPara);
            d++;
            Text tx = factory.createText();
            R run = factory.createR();
            if (entry.get(key) != null) {
                // old solution till now: tx.setValue(entry.get(key).getUnicodeTextFromLines());
                if (entry.get(key).getUnicodeTextFromLines() != "") {
                    exportTextRegion(entry.get(key), isWordBased, columnPara, mdp);
                }
            }
            run.getContent().add(tx);
            columnPara.getContent().add(run);
        }
    }
    return table;
}
Also used : TrpTableCellType(eu.transkribus.core.model.beans.pagecontent_trp.TrpTableCellType) Text(org.docx4j.wml.Text) Tc(org.docx4j.wml.Tc) BigInteger(java.math.BigInteger) P(org.docx4j.wml.P) R(org.docx4j.wml.R) TblGrid(org.docx4j.wml.TblGrid) Tr(org.docx4j.wml.Tr) Tbl(org.docx4j.wml.Tbl) TblGridCol(org.docx4j.wml.TblGridCol)

Aggregations

R (org.docx4j.wml.R)93 P (org.docx4j.wml.P)58 Text (org.docx4j.wml.Text)53 PPr (org.docx4j.wml.PPr)23 Jc (org.docx4j.wml.Jc)18 RPr (org.docx4j.wml.RPr)18 Drawing (org.docx4j.wml.Drawing)17 ObjectFactory (org.docx4j.wml.ObjectFactory)17 CTVerticalJc (org.docx4j.wml.CTVerticalJc)16 STVerticalJc (org.docx4j.wml.STVerticalJc)13 FldChar (org.docx4j.wml.FldChar)11 BigInteger (java.math.BigInteger)10 Inline (org.docx4j.dml.wordprocessingDrawing.Inline)10 BinaryPartAbstractImage (org.docx4j.openpackaging.parts.WordprocessingML.BinaryPartAbstractImage)10 Tc (org.docx4j.wml.Tc)10 CTBorder (org.docx4j.wml.CTBorder)8 PBdr (org.docx4j.wml.PPrBase.PBdr)8 Ftr (org.docx4j.wml.Ftr)7 File (java.io.File)6 Tr (org.docx4j.wml.Tr)6