Example usage for com.lowagie.text.pdf PdfContentByte transform

List of usage examples for com.lowagie.text.pdf PdfContentByte transform

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfContentByte transform.

Prototype

public void transform(AffineTransform af) 

Source Link

Document

Concatenates a transformation to the current transformation matrix.

Usage

From source file:org.mapfish.print.scalebar.ScalebarDrawer.java

License:Open Source License

public void renderImpl(Rectangle rectangle, PdfContentByte dc) {
    dc.saveState();//w  ww.  ja  v  a 2  s  .  c o m
    try {
        //sets the transformation for drawing the labels and do it
        final AffineTransform rotate = getRotationTransform(block.getBarDirection());
        final AffineTransform labelTransform = AffineTransform.getTranslateInstance(rectangle.getLeft(),
                rectangle.getBottom());
        labelTransform.concatenate(rotate);
        labelTransform.translate(leftLabelMargin, maxLabelHeight);
        dc.transform(labelTransform);
        dc.setColorStroke(block.getColorVal());
        dc.setFontAndSize(pdfFont.getCalculatedBaseFont(false), pdfFont.getSize());
        drawLabels(dc);

        dc.restoreState();
        dc.saveState();

        //sets the transformation for drawing the bar and do it
        final AffineTransform lineTransform = AffineTransform.getTranslateInstance(rectangle.getLeft(),
                rectangle.getBottom());
        lineTransform.concatenate(rotate);
        lineTransform.translate(leftLabelMargin, labelDistance + maxLabelHeight);
        dc.transform(lineTransform);
        dc.setLineWidth((float) block.getLineWidth());
        dc.setColorStroke(block.getColorVal());
        drawBar(dc);
    } finally {
        dc.restoreState();
    }
}

From source file:org.viafirma.util.QRCodeUtil.java

License:Apache License

/**
 * Genera un justificante de firma de un fichero pdf de entrada.
 * /*from ww  w .j av a  2s.  co  m*/
 * @param input
 *            Fichero pdf de entrada
 * @param texto
 * @param textoQR
 * @param codFirma
 * @param out
 * @throws ExcepcionErrorInterno
 */
public void firmarPDF(InputStream input, String texto, String texto2Line, String textoQR, String codFirma,
        OutputStream out) throws ExcepcionErrorInterno {
    // leemos el pdf utilizando iText.
    try {
        // Recuperamos el documento original
        PdfReader reader = new PdfReader(input);

        // Obtenemos el tamao de la pgina
        Rectangle pageSize = reader.getPageSize(1);

        // Creamos un nuevo documento del mismo tamao que el original
        Document document = new Document(pageSize);

        // creo una instancia para escritura en el documento
        PdfWriter writer = PdfWriter.getInstance(document, out);
        document.open();

        // insertamos la portada del documento que estamos firmando.
        float escala = (pageSize.getHeight() - 350) / pageSize.getHeight();

        // Aadimos al documento la imagen de cabecera y de pie
        addContent(texto, texto2Line, textoQR, codFirma, document, pageSize, true, false);

        PdfContentByte cb = writer.getDirectContent();

        PdfImportedPage portada = writer.getImportedPage(reader, 1);
        cb.setRGBColorStroke(0xCC, 0xCC, 0xCC);
        cb.transform(AffineTransform.getTranslateInstance(document.leftMargin(), 210));
        cb.transform(AffineTransform.getScaleInstance(escala, escala));
        cb.addTemplate(portada, 0, 0);// , escala, 0, 0, escala,dx,dy);
        document.close();
        out.close();
    } catch (Exception e) {
        throw new ExcepcionErrorInterno(CodigoError.ERROR_INTERNO, e);
    }
}

From source file:org.viafirma.util.QRCodeUtil.java

License:Apache License

/**
 * Genera un documento sellado en fichero pdf.
 * /*from  ww w.j  a v  a2  s .c  o m*/
 * @param input
 *            Fichero pdf de entrada
 * @param texto
 * @param textoQR
 * @param codFirma
 * @param out
 * @throws ExcepcionErrorInterno
 */
public void firmarPDFSellado(InputStream input, String texto, String texto2Line, String textoQR,
        String codFirma, OutputStream out) throws ExcepcionErrorInterno {
    // leemos el pdf utilizando iText.
    try {
        // Recuperamos el documento original
        PdfReader reader = new PdfReader(input);

        // Obtenemos el tamao de la pgina
        Rectangle pageSize = reader.getPageSize(1);

        // Creamos un nuevo documento del mismo tamao que el original
        Document document = new Document(pageSize);

        // creo una instancia para escritura en el documento
        PdfWriter writer = PdfWriter.getInstance(document, out);
        document.open();

        // Aadimos al documento la imagen de cabecera y de pie
        float altoCabeceraYPie = addContent(texto, texto2Line, textoQR, codFirma, document, pageSize, true,
                true);
        altoCabeceraYPie = altoCabeceraYPie + document.topMargin();
        // insertamos la portada del documento que estamos firmando.
        float escala = (pageSize.getHeight() - altoCabeceraYPie) / pageSize.getHeight();

        PdfContentByte cb = writer.getDirectContent();

        PdfImportedPage portada = writer.getImportedPage(reader, 1);
        cb.setRGBColorStroke(0xCC, 0xCC, 0xCC);
        cb.transform(AffineTransform.getScaleInstance(escala, escala));
        cb.transform(AffineTransform.getTranslateInstance(document.leftMargin() * 2.5,
                ALTO_ETIQUETA + document.topMargin()));

        cb.addTemplate(portada, 0, 0);// , escala, 0, 0, escala,dx,dy);
        document.close();
        out.close();
    } catch (Exception e) {
        throw new ExcepcionErrorInterno(CodigoError.ERROR_INTERNO, e);
    }
}