class HeaderFooter extends Rectangle {

    // membervariables

    /**
     * Does the page contain a pagenumber?
     */
    private boolean numbered;

    /**
     * This is the <CODE>Phrase</CODE> that comes before the pagenumber.
     */
    private Phrase before = null;

    /**
     * This is number of the page.
     */
    private int pageN;

    /**
     * This is the <CODE>Phrase</CODE> that comes after the pagenumber.
     */
    private Phrase after = null;

    /**
     * This is alignment of the header/footer.
     */
    private int alignment;

    /**
     * This is the <CODE>List</CODE> containing non-text <CODE>Element</CODE>.
     */
    private java.util.List<Element> specialContent = null;

    /**
     * This is the padding of height of header/footer.
     */
    private float padding;

    // constructors

    /**
     * Constructs a <CODE>HeaderFooter</CODE>-object.
     *
     * @param before the <CODE>Phrase</CODE> before the pagenumber
     * @param after  the <CODE>Phrase</CODE> before the pagenumber
     */
    public HeaderFooter(Phrase before, Phrase after) {
        super(0, 0, 0, 0);
        setBorder(TOP + BOTTOM);
        setBorderWidth(1);

        numbered = true;
        this.before = before;
        this.after = after;
    }

    /**
     * Constructs a <CODE>Header</CODE>-object with a pagenumber at the end.
     *
     * @param before   the <CODE>Phrase</CODE> before the pagenumber
     * @param numbered page will be numbered if <CODE>true</CODE>
     */
    public HeaderFooter(Phrase before, boolean numbered) {
        super(0, 0, 0, 0);
        setBorder(TOP + BOTTOM);
        setBorderWidth(1);

        this.numbered = numbered;
        this.before = before;
    }

    /**
     * Constructs a <CODE>Header</CODE>-object with a pagenumber at the beginning.
     *
     * @param numbered page will be numbered if <CODE>true</CODE>
     * @param after    the <CODE>Phrase</CODE> after the pagenumber
     */
    public HeaderFooter(boolean numbered, Phrase after) {
        super(0, 0, 0, 0);
        setBorder(TOP + BOTTOM);
        setBorderWidth(1);

        this.numbered = numbered;
        this.after = after;
    }

    /**
     * Constructs a <CODE>Header</CODE>-object with only a pagenumber.
     *
     * @param numbered <CODE>true</CODE> if the page has to be numbered
     */
    public HeaderFooter(boolean numbered) {
        this(null, true);
        this.numbered = numbered;
    }

    // methods

    /**
     * Checks if the HeaderFooter contains a page number.
     *
     * @return true if the page has to be numbered
     */
    public boolean isNumbered() {
        return numbered;
    }

    /**
     * Gets the part that comes before the pageNumber.
     *
     * @return a Phrase
     */
    public Phrase getBefore() {
        return before;
    }

    /**
     * Gets the part that comes after the pageNumber.
     *
     * @return a Phrase
     */
    public Phrase getAfter() {
        return after;
    }

    /**
     * Sets the page number.
     *
     * @param pageN the new page number
     */
    public void setPageNumber(int pageN) {
        this.pageN = pageN;
    }

    /**
     * Sets the alignment.
     *
     * @param alignment the new alignment
     */
    public void setAlignment(int alignment) {
        this.alignment = alignment;
    }

    /**
     * Gets padding of height of header/footer.
     *
     * @return the padding of height
     */
    public float getPadding() {
        return padding;
    }

    /**
     * Sets padding of height of header/footer.
     *
     * @param padding the new padding of height
     */
    public void setPadding(float padding) {
        this.padding = padding;
    }

    /**
     * Increases current padding by adding new value into it
     *
     * @param augment the new value
     */
    public void addPadding(float augment) {
        padding += augment;
    }

    /**
     * Adds non-text <CODE>Element</CODE> into <CODE>specialContent</CODE>
     *
     * @param element the new non-text <CODE>Element</CODE>
     */
    public void addSpecialContent(Element element) {
        if (specialContent == null) {
            specialContent = new ArrayList<>();
        }
        specialContent.add(element);
    }

    /**
     * Gets <CODE>specialContent</CODE>
     *
     * @return <CODE>specialContent</CODE>
     */
    public List<Element> getSpecialContent() {
        return specialContent;
    }

    // methods to retrieve the membervariables

    /**
     * Gets the <CODE>Paragraph</CODE> that can be used as header or footer.
     *
     * @return a <CODE>Paragraph</CODE>
     */
    public Paragraph paragraph() {<FILL_FUNCTION_BODY>}

    private Font getFont() {
        if (before != null) {
            return before.getFont();
        }

        if (after != null) {
            return after.getFont();
        }

        return null;
    }

    /**
     * Gets the alignment of this HeaderFooter.
     *
     * @return alignment
     */
    public int alignment() {
        return alignment;
    }
}

        Paragraph paragraph;

        if (before != null) {
            paragraph = new Paragraph(before.getLeading());
            paragraph.add(before);

            // Adding a Paragraph to another Paraghraph adds a newline that needs to be removed in headers and footers
            if (before instanceof Paragraph
                    &&
                    paragraph.size() >= 2
                    &&
                    "\n".equals(paragraph.get(paragraph.size() - 1).toString())) {
                paragraph.remove(paragraph.size() - 1);
            }
        } else {
            paragraph = new Paragraph();
        }

        if (numbered) {
            Font font = getFont();
            if (font != null) {
                paragraph.addSpecial(new Chunk(String.valueOf(pageN), font));
            } else {
                paragraph.addSpecial(new Chunk(String.valueOf(pageN)));
            }
        }

        if (after != null) {
            paragraph.addSpecial(after);
        }

        paragraph.setAlignment(alignment);

        return paragraph;
    
<methods>public void <init>(float, float, float, float) ,public void <init>(float, float) ,public void <init>(float, float, float, float, int) ,public void <init>(float, float, int) ,public void <init>(com.lowagie.text.Rectangle) ,public void cloneNonPositionParameters(com.lowagie.text.Rectangle) ,public void disableBorderSide(int) ,public void enableBorderSide(int) ,public java.awt.Color getBackgroundColor() ,public int getBorder() ,public java.awt.Color getBorderColor() ,public java.awt.Color getBorderColorBottom() ,public java.awt.Color getBorderColorLeft() ,public java.awt.Color getBorderColorRight() ,public java.awt.Color getBorderColorTop() ,public float getBorderWidth() ,public float getBorderWidthBottom() ,public float getBorderWidthLeft() ,public float getBorderWidthRight() ,public float getBorderWidthTop() ,public float getBottom() ,public float getBottom(float) ,public ArrayList<com.lowagie.text.Element> getChunks() ,public float getGrayFill() ,public float getHeight() ,public float getLeft() ,public float getLeft(float) ,public float getRelativeTop() ,public float getRight() ,public float getRight(float) ,public int getRotation() ,public float getTop() ,public float getTop(float) ,public float getWidth() ,public boolean hasBorder(int) ,public boolean hasBorders() ,public boolean isContent() ,public boolean isNestable() ,public boolean isUseVariableBorders() ,public void normalize() ,public boolean process(com.lowagie.text.ElementListener) ,public com.lowagie.text.Rectangle rectangle(float, float) ,public com.lowagie.text.Rectangle rotate() ,public void setBackgroundColor(java.awt.Color) ,public void setBorder(int) ,public void setBorderColor(java.awt.Color) ,public void setBorderColorBottom(java.awt.Color) ,public void setBorderColorLeft(java.awt.Color) ,public void setBorderColorRight(java.awt.Color) ,public void setBorderColorTop(java.awt.Color) ,public void setBorderWidth(float) ,public void setBorderWidthBottom(float) ,public void setBorderWidthLeft(float) ,public void setBorderWidthRight(float) ,public void setBorderWidthTop(float) ,public void setBottom(float) ,public void setGrayFill(float) ,public void setLeft(float) ,public void setRelativeTop(float) ,public void setRight(float) ,public void setRotation(int) ,public void setTop(float) ,public void setUseVariableBorders(boolean) ,public void softCloneNonPositionParameters(com.lowagie.text.Rectangle) ,public java.lang.String toString() ,public int type() <variables>public static final int BOTTOM,public static final int BOX,public static final int LEFT,public static final int NO_BORDER,public static final int RIGHT,public static final int TOP,public static final int UNDEFINED,protected java.awt.Color backgroundColor,protected int border,protected java.awt.Color borderColor,protected java.awt.Color borderColorBottom,protected java.awt.Color borderColorLeft,protected java.awt.Color borderColorRight,protected java.awt.Color borderColorTop,protected float borderWidth,protected float borderWidthBottom,protected float borderWidthLeft,protected float borderWidthRight,protected float borderWidthTop,protected float llx,protected float lly,protected float offsetToTop,protected int rotation,protected float urx,protected float ury,protected boolean useVariableBorders