Search in sources :

Example 6 with SectPr

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

the class AddingAFooter method createFooterReference.

/**
 *  First we retrieve the document sections from the package. As we want to add
 *  a footer, we get the last section and take the section properties from it.
 *  The section is always present, but it might not have properties, so we check
 *  if they exist to see if we should create them. If they need to be created,
 *  we do and add them to the main document part and the section.
 *  Then we create a reference to the footer, give it the id of the relationship,
 *  set the type to header/footer reference and add it to the collection of
 *  references to headers and footers in the section properties.
 *
 * @param relationship
 */
private static void createFooterReference(Relationship relationship) {
    List<SectionWrapper> sections = wordMLPackage.getDocumentModel().getSections();
    SectPr sectionProperties = sections.get(sections.size() - 1).getSectPr();
    // There is always a section wrapper, but it might not contain a sectPr
    if (sectionProperties == null) {
        sectionProperties = factory.createSectPr();
        wordMLPackage.getMainDocumentPart().addObject(sectionProperties);
        sections.get(sections.size() - 1).setSectPr(sectionProperties);
    }
    FooterReference footerReference = factory.createFooterReference();
    footerReference.setId(relationship.getId());
    footerReference.setType(HdrFtrRef.DEFAULT);
    sectionProperties.getEGHdrFtrReferences().add(footerReference);
}
Also used : SectionWrapper(org.docx4j.model.structure.SectionWrapper) FooterReference(org.docx4j.wml.FooterReference) SectPr(org.docx4j.wml.SectPr)

Example 7 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 8 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 9 with SectPr

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

the class Docx4J_简单例子 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 10 with SectPr

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

the class Docx4J_简单例子 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)

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