Example usage for com.itextpdf.layout Canvas Canvas

List of usage examples for com.itextpdf.layout Canvas Canvas

Introduction

In this page you can find the example usage for com.itextpdf.layout Canvas Canvas.

Prototype

public Canvas(PdfCanvas pdfCanvas, PdfDocument pdfDocument, Rectangle rootArea) 

Source Link

Document

Creates a new Canvas to manipulate a specific document and content stream, which might be for example a page or PdfFormXObject stream.

Usage

From source file:cl.a2r.wsmicampov2.pdf.EventoPagina.java

/**
 * Manejador del evento de cambio de pagina, agrega el encabezado y pie de pagina
 * @param event Evento de pagina// ww  w.  j  a va 2s. c o  m
 */
@Override
public void handleEvent(Event event) {
    PdfDocumentEvent docEvent = (PdfDocumentEvent) event;
    PdfDocument pdfDoc = docEvent.getDocument();
    PdfPage page = docEvent.getPage();
    PdfCanvas canvas = new PdfCanvas(page.newContentStreamBefore(), page.getResources(), pdfDoc);

    //        Table tablaEncabezado = this.crearTablaEncabezado("Departamento de Recursos Humanos");
    //        Rectangle rectanguloEncabezado = this.crearRectanguloEncabezado(docEvent);        
    //        Canvas canvasEncabezado = new Canvas(canvas, pdfDoc, rectanguloEncabezado);        
    //        canvasEncabezado.add(tablaEncabezado);      

    Table tablaNumeracion = this.crearTablaPie(docEvent);
    Rectangle rectanguloPie = this.crearRectanguloPie(docEvent);
    Canvas canvasPie = new Canvas(canvas, pdfDoc, rectanguloPie);
    canvasPie.add(tablaNumeracion);
}

From source file:org.zafritech.zidingorms.io.pdf.Header.java

@Override
public void handleEvent(Event event) {

    PdfDocumentEvent docEvent = (PdfDocumentEvent) event;
    PdfDocument pdf = docEvent.getDocument();
    PdfPage page = docEvent.getPage();//from w  w  w .j  a va2  s . com

    // No Header on first page
    if (pdf.getPageNumber(page) == 1)
        return;

    Rectangle pageSize = page.getPageSize();

    PdfCanvas pdfCanvas = new PdfCanvas(page.getLastContentStream(), page.getResources(), pdf);

    Canvas canvas = new Canvas(pdfCanvas, pdf, pageSize);

    canvas.showTextAligned(header, pageSize.getWidth() / 2, pageSize.getTop() - 40, TextAlignment.CENTER);
}

From source file:org.zafritech.zidingorms.io.pdf.PageXofY.java

@Override
public void handleEvent(Event event) {

    PdfDocumentEvent docEvent = (PdfDocumentEvent) event;
    PdfDocument pdf = docEvent.getDocument();
    PdfPage page = docEvent.getPage();//from  ww  w.j a  v a 2 s  .  co  m

    int pageNumber = pdf.getPageNumber(page);
    Rectangle pageSize = page.getPageSize();

    PdfCanvas pdfCanvas = new PdfCanvas(page.getLastContentStream(), page.getResources(), pdf);
    Canvas canvas = new Canvas(pdfCanvas, pdf, pageSize);
    Paragraph p = new Paragraph().add("Page ").add(String.valueOf(pageNumber)).add(" of");

    canvas.showTextAligned(p, x, y, TextAlignment.RIGHT);
    pdfCanvas.addXObject(placeholder, x + space, y - descent);

    pdfCanvas.release();
}

From source file:org.zafritech.zidingorms.io.pdf.TableHeader.java

@Override
public void handleEvent(Event event) {

    PdfDocumentEvent docEvent = (PdfDocumentEvent) event;
    PdfDocument pdfDoc = docEvent.getDocument();
    PdfPage page = docEvent.getPage();/*from  w  w  w  . j  av a  2  s .c  o m*/
    PdfCanvas canvas = new PdfCanvas(page.newContentStreamBefore(), page.getResources(), pdfDoc);
    Rectangle rect = new Rectangle(pdfDoc.getDefaultPageSize().getX() + doc.getLeftMargin(),
            pdfDoc.getDefaultPageSize().getTop() - doc.getTopMargin(), 100, getTableheight());

    new Canvas(canvas, pdfDoc, rect).add(table);

}