Example usage for com.itextpdf.text Rectangle getRight

List of usage examples for com.itextpdf.text Rectangle getRight

Introduction

In this page you can find the example usage for com.itextpdf.text Rectangle getRight.

Prototype

public float getRight(final float margin) 

Source Link

Document

Returns the upper right x-coordinate, considering a given margin.

Usage

From source file:de.sign.SignMain.java

License:Open Source License

public void sign() throws DocumentException, IOException, GeneralSecurityException {

    PdfReader reader = new PdfReader(this.orgFile);
    OutputStream os = new FileOutputStream(this.orgFile.replace(".pdf", "SIGN.pdf"));
    PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0');

    // Create appearance
    PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
    Rectangle cropBox = reader.getCropBox(1);
    float width = 50;
    float height = 50;
    Rectangle rectangle = new Rectangle(cropBox.getRight(width) - 20, cropBox.getTop(height) - 20,
            cropBox.getRight() - 20, cropBox.getTop() - 20);
    appearance.setVisibleSignature(rectangle, 1, "sig");
    appearance.setLocation(getHostname());
    appearance.setReason("Evidence of document integrity");
    appearance.setCertificationLevel(1); // 1 = CERTIFIED_NO_CHANGES_ALLOWED
    appearance.setAcro6Layers(false);/*w  w  w. ja va 2s .  c o m*/
    appearance.setLayer2Text("");

    //Sign
    Security.addProvider(new BouncyCastleProvider());
    TSAClient tsc = new TSAClientBouncyCastle(this.tsa_URL);
    ExternalDigest digest = new BouncyCastleDigest();
    ExternalSignature signature = new PrivateKeySignature(getPrivateKey(), "SHA-1", "BC");
    MakeSignature.signDetached(appearance, digest, signature, getCertificateChain(), null, null, tsc, 0,
            CryptoStandard.CMS);
}

From source file:direccion.GeneradorFormato.java

@Override
public void onEndPage(PdfWriter writer, Document document) {

    Rectangle rect = writer.getBoxSize("art");
    Image imghead = null;/*from  w  w  w.j a v  a 2s. c  o  m*/
    PdfContentByte cbhead = null;

    //        try {
    //            imghead = Image.getInstance("LogoSapito5.png");
    //            imghead.setAbsolutePosition(0, 0);
    //            imghead.setAlignment(Image.ALIGN_CENTER);
    //            imghead.scalePercent(10f);
    //            cbhead = writer.getDirectContent();
    //            PdfTemplate tp = cbhead.createTemplate(100, 150);
    //            tp.addImage(imghead);
    //            cbhead.addTemplate(tp, 100, 715);
    //        } catch (BadElementException e) {
    //            e.printStackTrace();
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        } catch (DocumentException e) {
    //            e.printStackTrace();
    //        }

    Phrase headPhraseImg = new Phrase(cbhead + "",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 7, Font.NORMAL));

    Calendar c1 = Calendar.getInstance();
    Calendar c2 = new GregorianCalendar();
    String dia, mes, annio;
    dia = Integer.toString(c1.get(Calendar.DATE));
    mes = Integer.toString(c1.get(Calendar.MONTH));
    annio = Integer.toString(c1.get(Calendar.YEAR));
    Date fecha = new Date();
    String fechis = dia + "/" + mes + "/" + annio;

    Paragraph parrafo5 = new Paragraph(fechis,
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo5),
            rect.getRight(450), rect.getTop(-80), 0);

    Paragraph parrafo7 = new Paragraph("Empresa Sapito S.A. de C.V.",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo7),
            rect.getBottom(250), rect.getTop(-60), 0);

    Paragraph parrafo8 = new Paragraph("Reporte algoooooo",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo8),
            rect.getBottom(250), rect.getTop(-40), 0);

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase(
            "      _____________________________________________________________________________________    "),
            rect.getBorder(), rect.getTop(650), 0);

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase(
            "      _____________________________________________________________________________________    "),
            rect.getBorder(), rect.getTop(-24), 0);

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase(
            "      _____________________________________________________________________________________    "),
            rect.getBorder(), rect.getTop(-20), 0);

    Paragraph parrafo6 = new Paragraph(String.format("Pg %d", writer.getPageNumber()),
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo6),
            rect.getRight(-35), rect.getTop(-80), 0);
}

From source file:gov.nih.nci.firebird.service.pdf.AdditionalContent.java

License:Open Source License

private void addText(PdfReader reader, PdfStamper stamper, ColumnText text) throws DocumentException {
    Rectangle pageSize = reader.getPageSize(1);
    int newPageNumber = reader.getNumberOfPages() + 1;
    do {/*from   w  w  w.  j a va2 s. co  m*/
        stamper.insertPage(newPageNumber, pageSize);
        PdfContentByte newContent = stamper.getOverContent(newPageNumber);
        text.setCanvas(newContent);
        text.setSimpleColumn(pageSize.getLeft(MARGIN_SIZE), pageSize.getTop(MARGIN_SIZE),
                pageSize.getRight(MARGIN_SIZE), pageSize.getBottom(MARGIN_SIZE));
        newPageNumber++;
    } while (ColumnText.hasMoreText(text.go()));
}