Example usage for com.lowagie.text.pdf PdfSignatureAppearance setVisibleSignature

List of usage examples for com.lowagie.text.pdf PdfSignatureAppearance setVisibleSignature

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfSignatureAppearance setVisibleSignature.

Prototype

public void setVisibleSignature(String fieldName) 

Source Link

Document

Sets the signature to be visible.

Usage

From source file:questions.stamppages.CertificationSig.java

public static void main(String[] args) {

    PdfReader reader;/*  w ww. ja  v  a 2s .c o m*/
    try {
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
        ks.load(new FileInputStream(KEYSTORE), "f00b4r".toCharArray());
        PrivateKey key = (PrivateKey) ks.getKey("foobar", "r4b00f".toCharArray());
        Certificate[] chain = ks.getCertificateChain("foobar");
        reader = new PdfReader(RESOURCE);
        FileOutputStream os = new FileOutputStream(RESULT);
        PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0');
        PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
        appearance.setCrypto(key, chain, null, PdfSignatureAppearance.SELF_SIGNED);
        appearance.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_FORM_FILLING);
        appearance.setReason("It's personal.");
        appearance.setLocation("Foobar");
        appearance.setVisibleSignature("Certifier_Signature");
        stamper.close();
    } catch (KeyStoreException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (CertificateException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (UnrecoverableKeyException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}