com.aspose.words

Class HeaderFooterType

  • java.lang.Object
    • com.aspose.words.HeaderFooterType
public class HeaderFooterType 
extends java.lang.Object

Utility class containing constants. Identifies the type of header or footer found in a Word file.
This is a per section header/footer. Do not renumber as the value of the enum used as an index into plcfhdd.

Example:

Deletes all footers from all sections, but leaves headers intact.
Document doc = new Document(getMyDir() + "HeaderFooter.RemoveFooters.doc");

for (Section section : doc.getSections())
{
    // Up to three different footers are possible in a section (for first, even and odd pages).
    // We check and delete all of them.
    HeaderFooter footer;

    footer = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_FIRST);
    if (footer != null) footer.remove();

    // Primary footer is the footer used for odd pages.
    footer = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_PRIMARY);
    if (footer != null) footer.remove();

    footer = section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.FOOTER_EVEN);
    if (footer != null) footer.remove();
}

doc.save(getMyDir() + "\\Artifacts\\HeaderFooter.RemoveFooters.doc");

Example:

Inserts a watermark image into a document using DocumentBuilder.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// The best place for the watermark image is in the header or footer so it is shown on every page.
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);

BufferedImage image = ImageIO.read(new File(getImageDir() + "Watermark.png"));

// Insert a floating picture.
Shape shape = builder.insertImage(image);
shape.setWrapType(WrapType.NONE);
shape.setBehindText(true);

shape.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
shape.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);

// Calculate image left and top position so it appears in the centre of the page.
shape.setLeft((builder.getPageSetup().getPageWidth() - shape.getWidth()) / 2);
shape.setTop((builder.getPageSetup().getPageHeight() - shape.getHeight()) / 2);

doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.InsertWatermark.doc");

Example:

Creates headers and footers in a document using DocumentBuilder.
// Create a blank document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Specify that we want headers and footers different for first, even and odd pages.
builder.getPageSetup().setDifferentFirstPageHeaderFooter(true);
builder.getPageSetup().setOddAndEvenPagesHeaderFooter(true);

// Create the headers.
builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);
builder.write("Header First");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_EVEN);
builder.write("Header Even");
builder.moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY);
builder.write("Header Odd");

// Create three pages in the document.
builder.moveToSection(0);
builder.writeln("Page1");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page2");
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln("Page3");

doc.save(getMyDir() + "\\Artifacts\\DocumentBuilder.HeadersAndFooters.doc");

Field Summary
static final intHEADER_EVEN = 0
Header for even numbered pages.
static final intHEADER_PRIMARY = 1
Primary header, also used for odd numbered pages.
static final intFOOTER_EVEN = 2
Footer for even numbered pages.
static final intFOOTER_PRIMARY = 3
Primary footer, also used for odd numbered pages.
static final intHEADER_FIRST = 4
Header for the first page of the section.
static final intFOOTER_FIRST = 5
Footer for the first page of the section.
 

    • Field Detail

      • HEADER_EVEN = 0

        public static final int HEADER_EVEN
        Header for even numbered pages.
      • HEADER_PRIMARY = 1

        public static final int HEADER_PRIMARY
        Primary header, also used for odd numbered pages.
      • FOOTER_EVEN = 2

        public static final int FOOTER_EVEN
        Footer for even numbered pages.
      • FOOTER_PRIMARY = 3

        public static final int FOOTER_PRIMARY
        Primary footer, also used for odd numbered pages.
      • HEADER_FIRST = 4

        public static final int HEADER_FIRST
        Header for the first page of the section.
      • FOOTER_FIRST = 5

        public static final int FOOTER_FIRST
        Footer for the first page of the section.