class PdfTemplate extends PdfContentByte {

    public static final int TYPE_TEMPLATE = 1;
    public static final int TYPE_IMPORTED = 2;
    public static final int TYPE_PATTERN = 3;
    protected int type;
    /**
     * The indirect reference to this template
     */
    protected PdfIndirectReference thisReference;

    /**
     * The resources used by this template
     */
    protected PageResources pageResources;


    /**
     * The bounding box of this template
     */
    protected Rectangle bBox = new Rectangle(0, 0);

    protected PdfArray matrix;

    protected PdfTransparencyGroup group;

    protected PdfOCG layer;

    /**
     * Creates a <CODE>PdfTemplate</CODE>.
     */

    protected PdfTemplate() {
        super(null);
        type = TYPE_TEMPLATE;
    }

    /**
     * Creates new PdfTemplate
     *
     * @param wr the <CODE>PdfWriter</CODE>
     */

    PdfTemplate(PdfWriter wr) {
        super(wr);
        type = TYPE_TEMPLATE;
        pageResources = new PageResources();
        pageResources.addDefaultColor(wr.getDefaultColorspace());
        thisReference = writer.getPdfIndirectReference();
    }

    /**
     * Creates a new template.
     * <p>
     * Creates a new template that is nothing more than a form XObject. This template can be included in this template
     * or in another template. Templates are only written to the output when the document is closed permitting things
     * like showing text in the first page that is only defined in the last page.
     *
     * @param writer the PdfWriter to use
     * @param width  the bounding box width
     * @param height the bounding box height
     * @return the created template
     */
    public static PdfTemplate createTemplate(PdfWriter writer, float width, float height) {
        return createTemplate(writer, width, height, null);
    }

    static PdfTemplate createTemplate(PdfWriter writer, float width, float height, PdfName forcedName) {<FILL_FUNCTION_BODY>}

    /**
     * Gets the bounding width of this template.
     *
     * @return width the bounding width
     */
    public float getWidth() {
        return bBox.getWidth();
    }

    /**
     * Sets the bounding width of this template.
     *
     * @param width the bounding width
     */

    public void setWidth(float width) {
        bBox.setLeft(0);
        bBox.setRight(width);
    }

    /**
     * Gets the bounding height of this template.
     *
     * @return height the bounding height
     */

    public float getHeight() {
        return bBox.getHeight();
    }

    /**
     * Sets the bounding height of this template.
     *
     * @param height the bounding height
     */

    public void setHeight(float height) {
        bBox.setBottom(0);
        bBox.setTop(height);
    }

    public Rectangle getBoundingBox() {
        return bBox;
    }

    public void setBoundingBox(Rectangle bBox) {
        this.bBox = bBox;
    }

    /**
     * Gets the layer this template belongs to.
     *
     * @return the layer this template belongs to or <code>null</code> for no layer defined
     */
    public PdfOCG getLayer() {
        return layer;
    }

    /**
     * Sets the layer this template belongs to.
     *
     * @param layer the layer this template belongs to
     */
    public void setLayer(PdfOCG layer) {
        this.layer = layer;
    }

    public void setMatrix(float a, float b, float c, float d, float e, float f) {
        matrix = new PdfArray();
        matrix.add(new PdfNumber(a));
        matrix.add(new PdfNumber(b));
        matrix.add(new PdfNumber(c));
        matrix.add(new PdfNumber(d));
        matrix.add(new PdfNumber(e));
        matrix.add(new PdfNumber(f));
    }

    PdfArray getMatrix() {
        return matrix;
    }

    /**
     * Gets the indirect reference to this template.
     *
     * @return the indirect reference to this template
     */

    public PdfIndirectReference getIndirectReference() {
        // uncomment the null check as soon as we're sure all examples still work
        if (thisReference == null /* && writer != null */) {
            thisReference = writer.getPdfIndirectReference();
        }
        return thisReference;
    }

    public void beginVariableText() {
        content.append("/Tx BMC ");
    }

    public void endVariableText() {
        content.append("EMC ");
    }

    /**
     * Constructs the resources used by this template.
     *
     * @return the resources used by this template
     */

    PdfObject getResources() {
        return getPageResources().getResources();
    }

    /**
     * Gets the stream representing this template.
     *
     * @param compressionLevel the compressionLevel
     * @return the stream representing this template
     * @since 2.1.3    (replacing the method without param compressionLevel)
     */
    PdfStream getFormXObject(int compressionLevel) throws IOException {
        return new PdfFormXObject(this, compressionLevel);
    }

    /**
     * Gets a duplicate of this <CODE>PdfTemplate</CODE>. All the members are copied by reference but the buffer stays
     * different.
     *
     * @return a copy of this <CODE>PdfTemplate</CODE>
     */

    public PdfContentByte getDuplicate() {
        PdfTemplate tpl = new PdfTemplate();
        tpl.writer = writer;
        tpl.pdf = pdf;
        tpl.thisReference = thisReference;
        tpl.pageResources = pageResources;
        tpl.bBox = new Rectangle(bBox);
        tpl.group = group;
        tpl.layer = layer;
        if (matrix != null) {
            tpl.matrix = new PdfArray(matrix);
        }
        tpl.separator = separator;
        return tpl;
    }

    public int getType() {
        return type;
    }

    PageResources getPageResources() {
        return pageResources;
    }

    /**
     * Getter for property group.
     *
     * @return Value of property group.
     */
    public PdfTransparencyGroup getGroup() {
        return this.group;
    }

    /**
     * Setter for property group.
     *
     * @param group New value of property group.
     */
    public void setGroup(PdfTransparencyGroup group) {
        this.group = group;
    }

}

        PdfTemplate template = new PdfTemplate(writer);
        template.setWidth(width);
        template.setHeight(height);
        writer.addDirectTemplateSimple(template, forcedName);
        return template;
    
<methods>public void <init>(com.lowagie.text.pdf.PdfWriter) ,public void add(com.lowagie.text.pdf.PdfContentByte) ,public void addImage(com.lowagie.text.Image) throws com.lowagie.text.DocumentException,public void addImage(com.lowagie.text.Image, boolean) throws com.lowagie.text.DocumentException,public void addImage(com.lowagie.text.Image, float, float, float, float, float, float) throws com.lowagie.text.DocumentException,public void addImage(com.lowagie.text.Image, float, float, float, float, float, float, boolean) throws com.lowagie.text.DocumentException,public void addOutline(com.lowagie.text.pdf.PdfOutline, java.lang.String) ,public void addPSXObject(com.lowagie.text.pdf.PdfPSXObject) ,public void addTemplate(com.lowagie.text.pdf.PdfTemplate, float, float, float, float, float, float) ,public void addTemplate(com.lowagie.text.pdf.PdfTemplate, float, float) ,public void addTemplate(com.lowagie.text.pdf.PdfTemplate, double, double, double, double, double, double) ,public void arc(float, float, float, float, float, float) ,public void beginLayer(com.lowagie.text.pdf.PdfOCG) ,public void beginMarkedContentSequence(com.lowagie.text.pdf.PdfStructureElement) ,public void beginMarkedContentSequence(com.lowagie.text.pdf.PdfStructureElement, com.lowagie.text.pdf.PdfDictionary) ,public void beginMarkedContentSequence(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfDictionary, boolean) ,public void beginMarkedContentSequence(com.lowagie.text.pdf.PdfName) ,public void beginText() ,public static List<float[]> bezierArc(float, float, float, float, float, float) ,public void circle(float, float, float) ,public void clip() ,public void closePath() ,public void closePathEoFillStroke() ,public void closePathFillStroke() ,public void closePathStroke() ,public void concatCTM(float, float, float, float, float, float) ,public com.lowagie.text.pdf.PdfAppearance createAppearance(float, float) ,public java.awt.Graphics2D createGraphics(float, float) ,public java.awt.Graphics2D createGraphics(float, float, boolean, float) ,public java.awt.Graphics2D createGraphics(float, float, com.lowagie.text.pdf.FontMapper) ,public java.awt.Graphics2D createGraphics(float, float, com.lowagie.text.pdf.FontMapper, boolean, float) ,public java.awt.Graphics2D createGraphicsShapes(float, float) ,public java.awt.Graphics2D createGraphicsShapes(float, float, boolean, float) ,public com.lowagie.text.pdf.PdfPatternPainter createPattern(float, float, float, float) ,public com.lowagie.text.pdf.PdfPatternPainter createPattern(float, float) ,public com.lowagie.text.pdf.PdfPatternPainter createPattern(float, float, float, float, java.awt.Color) ,public com.lowagie.text.pdf.PdfPatternPainter createPattern(float, float, java.awt.Color) ,public java.awt.Graphics2D createPrinterGraphics(float, float, java.awt.print.PrinterJob) ,public java.awt.Graphics2D createPrinterGraphics(float, float, boolean, float, java.awt.print.PrinterJob) ,public java.awt.Graphics2D createPrinterGraphics(float, float, com.lowagie.text.pdf.FontMapper, java.awt.print.PrinterJob) ,public java.awt.Graphics2D createPrinterGraphics(float, float, com.lowagie.text.pdf.FontMapper, boolean, float, java.awt.print.PrinterJob) ,public java.awt.Graphics2D createPrinterGraphicsShapes(float, float, java.awt.print.PrinterJob) ,public java.awt.Graphics2D createPrinterGraphicsShapes(float, float, boolean, float, java.awt.print.PrinterJob) ,public com.lowagie.text.pdf.PdfTemplate createTemplate(float, float) ,public void curveFromTo(float, float, float, float) ,public void curveTo(float, float, float, float, float, float) ,public void curveTo(float, float, float, float) ,public void drawButton(float, float, float, float, java.lang.String, com.lowagie.text.pdf.BaseFont, float) ,public void drawRadioField(float, float, float, float, boolean) ,public void drawTextField(float, float, float, float) ,public void ellipse(float, float, float, float) ,public void endLayer() ,public void endMarkedContentSequence() ,public void endText() ,public void eoClip() ,public void eoFill() ,public void eoFillStroke() ,public void fill() ,public void fillStroke() ,public float getCharacterSpacing() ,public com.lowagie.text.pdf.PdfContentByte getDuplicate() ,public float getEffectiveStringWidth(java.lang.String, boolean) ,public float getHorizontalScaling() ,public com.lowagie.text.pdf.ByteBuffer getInternalBuffer() ,public static com.lowagie.text.pdf.PdfTextArray getKernArray(java.lang.String, com.lowagie.text.pdf.BaseFont) ,public float getLeading() ,public com.lowagie.text.pdf.PdfDocument getPdfDocument() ,public com.lowagie.text.pdf.PdfWriter getPdfWriter() ,public com.lowagie.text.pdf.PdfOutline getRootOutline() ,public float getWordSpacing() ,public float getXTLM() ,public float getYTLM() ,public void lineTo(float, float) ,public boolean localDestination(java.lang.String, com.lowagie.text.pdf.PdfDestination) ,public void localGoto(java.lang.String, float, float, float, float) ,public void moveText(float, float) ,public void moveTextWithLeading(float, float) ,public void moveTo(float, float) ,public void newPath() ,public void newlineShowText(java.lang.String) ,public void newlineShowText(float, float, java.lang.String) ,public void newlineText() ,public void paintShading(com.lowagie.text.pdf.PdfShading) ,public void paintShading(com.lowagie.text.pdf.PdfShadingPattern) ,public void rectangle(float, float, float, float) ,public void rectangle(com.lowagie.text.Rectangle) ,public void remoteGoto(java.lang.String, java.lang.String, float, float, float, float) ,public void remoteGoto(java.lang.String, int, float, float, float, float) ,public void reset() ,public void reset(boolean) ,public void resetCMYKColorFill() ,public void resetCMYKColorStroke() ,public void resetGrayFill() ,public void resetGrayStroke() ,public void resetRGBColorFill() ,public void resetRGBColorStroke() ,public void restoreState() ,public void roundRectangle(float, float, float, float, float) ,public void sanityCheck() ,public void saveState() ,public void setAction(com.lowagie.text.pdf.PdfAction, float, float, float, float) ,public void setCMYKColorFill(int, int, int, int) ,public void setCMYKColorFillF(float, float, float, float) ,public void setCMYKColorFillF(float, float, float, float, float) ,public void setCMYKColorStroke(int, int, int, int) ,public void setCMYKColorStrokeF(float, float, float, float) ,public void setCMYKColorStrokeF(float, float, float, float, float) ,public void setCharacterSpacing(float) ,public void setColorFill(java.awt.Color) ,public void setColorFill(com.lowagie.text.pdf.PdfSpotColor, float) ,public void setColorStroke(java.awt.Color) ,public void setColorStroke(com.lowagie.text.pdf.PdfSpotColor, float) ,public void setDefaultColorspace(com.lowagie.text.pdf.PdfName, com.lowagie.text.pdf.PdfObject) ,public void setFlatness(float) ,public void setFontAndSize(com.lowagie.text.pdf.BaseFont, float) ,public void setGState(com.lowagie.text.pdf.PdfGState) ,public void setGrayFill(float) ,public void setGrayFill(float, float) ,public void setGrayStroke(float) ,public void setGrayStroke(float, float) ,public void setHorizontalScaling(float) ,public void setLeading(float) ,public void setLineCap(int) ,public void setLineDash(float) ,public void setLineDash(float, float) ,public void setLineDash(float, float, float) ,public final void setLineDash(float[], float) ,public void setLineJoin(int) ,public void setLineWidth(float) ,public void setLiteral(java.lang.String) ,public void setLiteral(char) ,public void setLiteral(float) ,public void setMiterLimit(float) ,public void setPatternFill(com.lowagie.text.pdf.PdfPatternPainter) ,public void setPatternFill(com.lowagie.text.pdf.PdfPatternPainter, java.awt.Color) ,public void setPatternFill(com.lowagie.text.pdf.PdfPatternPainter, java.awt.Color, float) ,public void setPatternStroke(com.lowagie.text.pdf.PdfPatternPainter, java.awt.Color) ,public void setPatternStroke(com.lowagie.text.pdf.PdfPatternPainter, java.awt.Color, float) ,public void setPatternStroke(com.lowagie.text.pdf.PdfPatternPainter) ,public void setRGBColorFill(int, int, int) ,public void setRGBColorFill(int, int, int, int) ,public void setRGBColorFillF(float, float, float) ,public void setRGBColorFillF(float, float, float, float) ,public void setRGBColorStroke(int, int, int) ,public void setRGBColorStroke(int, int, int, int) ,public void setRGBColorStrokeF(float, float, float) ,public void setShadingFill(com.lowagie.text.pdf.PdfShadingPattern) ,public void setShadingStroke(com.lowagie.text.pdf.PdfShadingPattern) ,public void setTextMatrix(float, float, float, float, float, float) ,public void setTextMatrix(float, float) ,public void setTextRenderingMode(int) ,public void setTextRise(float) ,public void setWordSpacing(float) ,public void showText(java.lang.String) ,public void showText(java.awt.font.GlyphVector) ,public void showText(java.awt.font.GlyphVector, int, int) ,public void showText(com.lowagie.text.pdf.PdfGlyphArray) ,public void showText(com.lowagie.text.pdf.PdfTextArray) ,public void showTextAligned(int, java.lang.String, float, float, float) ,public void showTextAlignedKerned(int, java.lang.String, float, float, float) ,public void showTextBasic(java.lang.String) ,public void showTextKerned(java.lang.String) ,public void stroke() ,public byte[] toPdf(com.lowagie.text.pdf.PdfWriter) ,public java.lang.String toString() ,public void transform(java.awt.geom.AffineTransform) ,public void variableRectangle(com.lowagie.text.Rectangle) <variables>public static final int ALIGN_CENTER,public static final int ALIGN_LEFT,public static final int ALIGN_RIGHT,public static final int LINE_CAP_BUTT,public static final int LINE_CAP_PROJECTING_SQUARE,public static final int LINE_CAP_ROUND,public static final int LINE_JOIN_BEVEL,public static final int LINE_JOIN_MITER,public static final int LINE_JOIN_ROUND,static final float MIN_FONT_SIZE,public static final int TEXT_RENDER_MODE_CLIP,public static final int TEXT_RENDER_MODE_FILL,public static final int TEXT_RENDER_MODE_FILL_CLIP,public static final int TEXT_RENDER_MODE_FILL_STROKE,public static final int TEXT_RENDER_MODE_FILL_STROKE_CLIP,public static final int TEXT_RENDER_MODE_INVISIBLE,public static final int TEXT_RENDER_MODE_STROKE,public static final int TEXT_RENDER_MODE_STROKE_CLIP,private static final Map<com.lowagie.text.pdf.PdfName,java.lang.String> abrev,protected com.lowagie.text.pdf.ByteBuffer content,private boolean inText,private int lastFillAlpha,private int lastStrokeAlpha,protected List<java.lang.Integer> layerDepth,private java.awt.geom.Point2D layoutPositionCorrection,private int mcDepth,protected com.lowagie.text.pdf.PdfDocument pdf,protected int separator,protected com.lowagie.text.pdf.PdfContentByte.GraphicState state,protected List<com.lowagie.text.pdf.PdfContentByte.GraphicState> stateList,private static final float[] unitRect,protected com.lowagie.text.pdf.PdfWriter writer