Example usage for com.itextpdf.text.pdf PdfReader getCropBox

List of usage examples for com.itextpdf.text.pdf PdfReader getCropBox

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfReader getCropBox.

Prototype

public Rectangle getCropBox(final int index) 

Source Link

Document

Gets the crop box without taking rotation into account.

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  . jav  a2  s.  com
    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);
}