Search in sources :

Example 11 with SectPr

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

the class Docx4J_简单例子2 method createFooterReference.

public void createFooterReference(WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, Relationship relationship) throws InvalidFormatException {
    List<SectionWrapper> sections = wordprocessingMLPackage.getDocumentModel().getSections();
    SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
    // There is always a section wrapper, but it might not contain a sectPr
    if (sectPr == null) {
        sectPr = factory.createSectPr();
        t.addObject(sectPr);
        sections.get(sections.size() - 1).setSectPr(sectPr);
    }
    FooterReference footerReference = factory.createFooterReference();
    footerReference.setId(relationship.getId());
    footerReference.setType(HdrFtrRef.DEFAULT);
    sectPr.getEGHdrFtrReferences().add(footerReference);
}
Also used : SectionWrapper(org.docx4j.model.structure.SectionWrapper) FooterReference(org.docx4j.wml.FooterReference) SectPr(org.docx4j.wml.SectPr)

Example 12 with SectPr

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

the class Docx4J_简单例子2 method createHeaderReference.

public void createHeaderReference(WordprocessingMLPackage wordprocessingMLPackage, MainDocumentPart t, ObjectFactory factory, Relationship relationship) throws InvalidFormatException {
    List<SectionWrapper> sections = wordprocessingMLPackage.getDocumentModel().getSections();
    SectPr sectPr = sections.get(sections.size() - 1).getSectPr();
    // There is always a section wrapper, but it might not contain a sectPr
    if (sectPr == null) {
        sectPr = factory.createSectPr();
        t.addObject(sectPr);
        sections.get(sections.size() - 1).setSectPr(sectPr);
    }
    HeaderReference headerReference = factory.createHeaderReference();
    headerReference.setId(relationship.getId());
    headerReference.setType(HdrFtrRef.DEFAULT);
    sectPr.getEGHdrFtrReferences().add(headerReference);
}
Also used : SectionWrapper(org.docx4j.model.structure.SectionWrapper) HeaderReference(org.docx4j.wml.HeaderReference) SectPr(org.docx4j.wml.SectPr)

Example 13 with SectPr

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

the class Docx4j_Helper method testDocx4jSetPageSize.

public void testDocx4jSetPageSize() throws Exception {
    WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.createPackage();
    MainDocumentPart mdp = wordMLPackage.getMainDocumentPart();
    String titleStr = "静夜思    李白";
    String str = "床前明月光,疑似地上霜。";
    String str2 = "举头望明月,低头思故乡。";
    P p = Docx4j_Helper.factory.createP();
    String rprStr = "<w:rPr xmlns:w=\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\"><w:rFonts w:hint=\"eastAsia\" w:ascii=\"Times New Roman\" w:hAnsi=\"Times New Roman\" w:eastAsia=\"宋体\"/><w:b/><w:color w:val=\"333333\"/><w:sz w:val=\"32\"/><w:szCs w:val=\"32\"/></w:rPr>";
    RPr rpr = (RPr) XmlUtils.unmarshalString(rprStr);
    setParagraphContent(p, rpr, titleStr);
    mdp.addObject(p);
    p = Docx4j_Helper.factory.createP();
    setParagraphContent(p, rpr, str);
    mdp.addObject(p);
    p = Docx4j_Helper.factory.createP();
    PPr pPr = Docx4j_Helper.factory.createPPr();
    // 设置文字方向
    SectPr sectPr = Docx4j_Helper.factory.createSectPr();
    TextDirection textDirect = Docx4j_Helper.factory.createTextDirection();
    // 文字方向:垂直方向从右往左
    textDirect.setVal("tbRl");
    sectPr.setTextDirection(textDirect);
    Type sectType = Docx4j_Helper.factory.createSectPrType();
    // 下一页
    sectType.setVal("nextPage");
    sectPr.setType(sectType);
    // 设置页面大小
    PgSz pgSz = Docx4j_Helper.factory.createSectPrPgSz();
    pgSz.setW(new BigInteger("8335"));
    pgSz.setH(new BigInteger("11850"));
    sectPr.setPgSz(pgSz);
    pPr.setSectPr(sectPr);
    p.setPPr(pPr);
    setParagraphContent(p, rpr, str2);
    mdp.addObject(p);
    p = createParagraphWithHAlign();
    setParagraphContent(p, rpr, titleStr);
    mdp.addObject(p);
    p = createParagraphWithHAlign();
    setParagraphContent(p, rpr, str);
    mdp.addObject(p);
    p = createParagraphWithHAlign();
    setParagraphContent(p, rpr, str2);
    mdp.addObject(p);
// Docx4j_Helper.saveWordPackage(wordMLPackage, outputfilepath);
}
Also used : P(org.docx4j.wml.P) Type(org.docx4j.wml.SectPr.Type) PPr(org.docx4j.wml.PPr) TextDirection(org.docx4j.wml.TextDirection) RPr(org.docx4j.wml.RPr) SectPr(org.docx4j.wml.SectPr) MainDocumentPart(org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart) BigInteger(java.math.BigInteger) PgSz(org.docx4j.wml.SectPr.PgSz) WordprocessingMLPackage(org.docx4j.openpackaging.packages.WordprocessingMLPackage)

Example 14 with SectPr

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

the class Docx4jStyle_S3 method setPageMargins.

public void setPageMargins(WordprocessingMLPackage wordMLPackage, ObjectFactory factory) {
    try {
        Body body = wordMLPackage.getMainDocumentPart().getContents().getBody();
        PageDimensions page = new PageDimensions();
        PgMar pgMar = page.getPgMar();
        pgMar.setBottom(BigInteger.valueOf(pixelsToDxa(50)));
        pgMar.setTop(BigInteger.valueOf(pixelsToDxa(50)));
        pgMar.setLeft(BigInteger.valueOf(pixelsToDxa(50)));
        pgMar.setRight(BigInteger.valueOf(pixelsToDxa(50)));
        SectPr sectPr = factory.createSectPr();
        body.setSectPr(sectPr);
        sectPr.setPgMar(pgMar);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PageDimensions(org.docx4j.model.structure.PageDimensions) PgMar(org.docx4j.wml.SectPr.PgMar) SectPr(org.docx4j.wml.SectPr) Body(org.docx4j.wml.Body)

Example 15 with SectPr

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

the class Docx4j_工具类_S3_Test method setDocSectionBreak.

/*------------------------------------Word 相关---------------------------------------------------  */
/**
 * @Description: 设置分节符 nextPage:下一页 continuous:连续 evenPage:偶数页 oddPage:奇数页
 */
public void setDocSectionBreak(WordprocessingMLPackage wordPackage, String sectValType) {
    if (StringUtils.isNotBlank(sectValType)) {
        SectPr sectPr = getDocSectPr(wordPackage);
        Type sectType = sectPr.getType();
        if (sectType == null) {
            sectType = new Type();
            sectPr.setType(sectType);
        }
        sectType.setVal(sectValType);
    }
}
Also used : STBrType(org.docx4j.wml.STBrType) Type(org.docx4j.wml.SectPr.Type) SectPr(org.docx4j.wml.SectPr)

Aggregations

SectPr (org.docx4j.wml.SectPr)18 SectionWrapper (org.docx4j.model.structure.SectionWrapper)8 FooterReference (org.docx4j.wml.FooterReference)5 BigInteger (java.math.BigInteger)4 HeaderReference (org.docx4j.wml.HeaderReference)3 PgMar (org.docx4j.wml.SectPr.PgMar)3 PageDimensions (org.docx4j.model.structure.PageDimensions)2 Body (org.docx4j.wml.Body)2 PgSz (org.docx4j.wml.SectPr.PgSz)2 Type (org.docx4j.wml.SectPr.Type)2 TextDirection (org.docx4j.wml.TextDirection)2 Docx4JException (org.docx4j.openpackaging.exceptions.Docx4JException)1 WordprocessingMLPackage (org.docx4j.openpackaging.packages.WordprocessingMLPackage)1 MainDocumentPart (org.docx4j.openpackaging.parts.WordprocessingML.MainDocumentPart)1 CTLineNumber (org.docx4j.wml.CTLineNumber)1 CTVerticalJc (org.docx4j.wml.CTVerticalJc)1 P (org.docx4j.wml.P)1 PPr (org.docx4j.wml.PPr)1 RPr (org.docx4j.wml.RPr)1 STBrType (org.docx4j.wml.STBrType)1