| Method from com.lowagie.text.pdf.PdfSignatureAppearance Detail: |
public void close(PdfDictionary update) throws IOException, DocumentException {
try {
if (!preClosed)
throw new DocumentException("preClose() must be called first.");
ByteBuffer bf = new ByteBuffer();
for (Iterator it = update.getKeys().iterator(); it.hasNext();) {
PdfName key = (PdfName)it.next();
PdfObject obj = update.get(key);
PdfLiteral lit = (PdfLiteral)exclusionLocations.get(key);
if (lit == null)
throw new IllegalArgumentException("The key " + key.toString() + " didn't reserve space in preClose().");
bf.reset();
obj.toPdf(null, bf);
if (bf.size() > lit.getPosLength())
throw new IllegalArgumentException("The key " + key.toString() + " is too big. Is " + bf.size() + ", reserved " + lit.getPosLength());
if (tempFile == null)
System.arraycopy(bf.getBuffer(), 0, bout, lit.getPosition(), bf.size());
else {
raf.seek(lit.getPosition());
raf.write(bf.getBuffer(), 0, bf.size());
}
}
if (update.size() != exclusionLocations.size())
throw new IllegalArgumentException("The update dictionary has less keys than required.");
if (tempFile == null) {
originalout.write(bout, 0, boutLen);
}
else {
if (originalout != null) {
raf.seek(0);
int length = (int)raf.length();
byte buf[] = new byte[8192];
while (length > 0) {
int r = raf.read(buf, 0, Math.min(buf.length, length));
if (r < 0)
throw new EOFException("Unexpected EOF");
originalout.write(buf, 0, r);
length -= r;
}
}
}
}
finally {
if (tempFile != null) {
try{raf.close();}catch(Exception ee){}
if (originalout != null)
try{tempFile.delete();}catch(Exception ee){}
}
if (originalout != null)
try{originalout.close();}catch(Exception e){}
}
}
This is the last method to be called when using external signatures. The general sequence is:
preClose(), getDocumentBytes() and close().
update is a PdfDictionary that must have exactly the
same keys as the ones provided in #preClose(HashMap) . |
public static float fitText(Font font,
String text,
Rectangle rect,
float maxFontSize,
int runDirection) {
try {
ColumnText ct = null;
int status = 0;
if (maxFontSize < = 0) {
int cr = 0;
int lf = 0;
char t[] = text.toCharArray();
for (int k = 0; k < t.length; ++k) {
if (t[k] == '\n")
++lf;
else if (t[k] == '\r")
++cr;
}
int minLines = Math.max(cr, lf) + 1;
maxFontSize = Math.abs(rect.getHeight()) / minLines - 0.001f;
}
font.setSize(maxFontSize);
Phrase ph = new Phrase(text, font);
ct = new ColumnText(null);
ct.setSimpleColumn(ph, rect.getLeft(), rect.getBottom(), rect.getRight(), rect.getTop(), maxFontSize, Element.ALIGN_LEFT);
ct.setRunDirection(runDirection);
status = ct.go(true);
if ((status & ColumnText.NO_MORE_TEXT) != 0)
return maxFontSize;
float precision = 0.1f;
float min = 0;
float max = maxFontSize;
float size = maxFontSize;
for (int k = 0; k < 50; ++k) { //just in case it doesn't converge
size = (min + max) / 2;
ct = new ColumnText(null);
font.setSize(size);
ct.setSimpleColumn(new Phrase(text, font), rect.getLeft(), rect.getBottom(), rect.getRight(), rect.getTop(), size, Element.ALIGN_LEFT);
ct.setRunDirection(runDirection);
status = ct.go(true);
if ((status & ColumnText.NO_MORE_TEXT) != 0) {
if (max - min < size * precision)
return size;
min = size;
}
else
max = size;
}
return size;
}
catch (Exception e) {
throw new ExceptionConverter(e);
}
}
Fits the text to some rectangle adjusting the font size as needed. |
public PdfTemplate getAppearance() throws DocumentException {
if (isInvisible()) {
PdfTemplate t = new PdfTemplate(writer);
t.setBoundingBox(new Rectangle(0, 0));
writer.addDirectTemplateSimple(t, null);
return t;
}
if (app[0] == null) {
PdfTemplate t = app[0] = new PdfTemplate(writer);
t.setBoundingBox(new Rectangle(100, 100));
writer.addDirectTemplateSimple(t, new PdfName("n0"));
t.setLiteral("% DSBlank\n");
}
if (app[1] == null && !acro6Layers) {
PdfTemplate t = app[1] = new PdfTemplate(writer);
t.setBoundingBox(new Rectangle(100, 100));
writer.addDirectTemplateSimple(t, new PdfName("n1"));
t.setLiteral(questionMark);
}
if (app[2] == null) {
String text;
if (layer2Text == null) {
StringBuffer buf = new StringBuffer();
buf.append("Digitally signed by ").append(PdfPKCS7.getSubjectFields((X509Certificate)certChain[0]).getField("CN")).append('\n");
SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z");
buf.append("Date: ").append(sd.format(signDate.getTime()));
if (reason != null)
buf.append('\n").append("Reason: ").append(reason);
if (location != null)
buf.append('\n").append("Location: ").append(location);
text = buf.toString();
}
else
text = layer2Text;
PdfTemplate t = app[2] = new PdfTemplate(writer);
t.setBoundingBox(rect);
writer.addDirectTemplateSimple(t, new PdfName("n2"));
if (image != null) {
if (imageScale == 0) {
t.addImage(image, rect.getWidth(), 0, 0, rect.getHeight(), 0, 0);
}
else {
float usableScale = imageScale;
if (imageScale < 0)
usableScale = Math.min(rect.getWidth() / image.getWidth(), rect.getHeight() / image.getHeight());
float w = image.getWidth() * usableScale;
float h = image.getHeight() * usableScale;
float x = (rect.getWidth() - w) / 2;
float y = (rect.getHeight() - h) / 2;
t.addImage(image, w, 0, 0, h, x, y);
}
}
Font font;
if (layer2Font == null)
font = new Font();
else
font = new Font(layer2Font);
float size = font.getSize();
Rectangle dataRect = null;
Rectangle signatureRect = null;
if (render == SignatureRenderNameAndDescription ||
(render == SignatureRenderGraphicAndDescription && this.signatureGraphic != null)) {
// origin is the bottom-left
signatureRect = new Rectangle(
MARGIN,
MARGIN,
rect.getWidth() / 2 - MARGIN,
rect.getHeight() - MARGIN);
dataRect = new Rectangle(
rect.getWidth() / 2 + MARGIN / 2,
MARGIN,
rect.getWidth() - MARGIN / 2,
rect.getHeight() - MARGIN);
if (rect.getHeight() > rect.getWidth()) {
signatureRect = new Rectangle(
MARGIN,
rect.getHeight() / 2,
rect.getWidth() - MARGIN,
rect.getHeight());
dataRect = new Rectangle(
MARGIN,
MARGIN,
rect.getWidth() - MARGIN,
rect.getHeight() / 2 - MARGIN);
}
}
else {
dataRect = new Rectangle(
MARGIN,
MARGIN,
rect.getWidth() - MARGIN,
rect.getHeight() * (1 - TOP_SECTION) - MARGIN);
}
if (render == SignatureRenderNameAndDescription) {
String signedBy = PdfPKCS7.getSubjectFields((X509Certificate)certChain[0]).getField("CN");
Rectangle sr2 = new Rectangle(signatureRect.getWidth() - MARGIN, signatureRect.getHeight() - MARGIN );
float signedSize = fitText(font, signedBy, sr2, -1, runDirection);
ColumnText ct2 = new ColumnText(t);
ct2.setRunDirection(runDirection);
ct2.setSimpleColumn(new Phrase(signedBy, font), signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), signedSize, Element.ALIGN_LEFT);
ct2.go();
}
else if (render == SignatureRenderGraphicAndDescription) {
ColumnText ct2 = new ColumnText(t);
ct2.setRunDirection(runDirection);
ct2.setSimpleColumn(signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), 0, Element.ALIGN_RIGHT);
Image im = Image.getInstance(signatureGraphic);
im.scaleToFit(signatureRect.getWidth(), signatureRect.getHeight());
Paragraph p = new Paragraph();
// must calculate the point to draw from to make image appear in middle of column
float x = 0;
// experimentation found this magic number to counteract Adobe's signature graphic, which
// offsets the y co-ordinate by 15 units
float y = -im.getScaledHeight() + 15;
x = x + (signatureRect.getWidth() - im.getScaledWidth()) / 2;
y = y - (signatureRect.getHeight() - im.getScaledHeight()) / 2;
p.add(new Chunk(im, x + (signatureRect.getWidth() - im.getScaledWidth()) / 2, y, false));
ct2.addElement(p);
ct2.go();
}
if (size < = 0) {
Rectangle sr = new Rectangle(dataRect.getWidth(), dataRect.getHeight());
size = fitText(font, text, sr, 12, runDirection);
}
ColumnText ct = new ColumnText(t);
ct.setRunDirection(runDirection);
ct.setSimpleColumn(new Phrase(text, font), dataRect.getLeft(), dataRect.getBottom(), dataRect.getRight(), dataRect.getTop(), size, Element.ALIGN_LEFT);
ct.go();
}
if (app[3] == null && !acro6Layers) {
PdfTemplate t = app[3] = new PdfTemplate(writer);
t.setBoundingBox(new Rectangle(100, 100));
writer.addDirectTemplateSimple(t, new PdfName("n3"));
t.setLiteral("% DSBlank\n");
}
if (app[4] == null && !acro6Layers) {
PdfTemplate t = app[4] = new PdfTemplate(writer);
t.setBoundingBox(new Rectangle(0, rect.getHeight() * (1 - TOP_SECTION), rect.getRight(), rect.getTop()));
writer.addDirectTemplateSimple(t, new PdfName("n4"));
Font font;
if (layer2Font == null)
font = new Font();
else
font = new Font(layer2Font);
float size = font.getSize();
String text = "Signature Not Verified";
if (layer4Text != null)
text = layer4Text;
Rectangle sr = new Rectangle(rect.getWidth() - 2 * MARGIN, rect.getHeight() * TOP_SECTION - 2 * MARGIN);
size = fitText(font, text, sr, 15, runDirection);
ColumnText ct = new ColumnText(t);
ct.setRunDirection(runDirection);
ct.setSimpleColumn(new Phrase(text, font), MARGIN, 0, rect.getWidth() - MARGIN, rect.getHeight() - MARGIN, size, Element.ALIGN_LEFT);
ct.go();
}
int rotation = writer.reader.getPageRotation(page);
Rectangle rotated = new Rectangle(rect);
int n = rotation;
while (n > 0) {
rotated = rotated.rotate();
n -= 90;
}
if (frm == null) {
frm = new PdfTemplate(writer);
frm.setBoundingBox(rotated);
writer.addDirectTemplateSimple(frm, new PdfName("FRM"));
float scale = Math.min(rect.getWidth(), rect.getHeight()) * 0.9f;
float x = (rect.getWidth() - scale) / 2;
float y = (rect.getHeight() - scale) / 2;
scale /= 100;
if (rotation == 90)
frm.concatCTM(0, 1, -1, 0, rect.getHeight(), 0);
else if (rotation == 180)
frm.concatCTM(-1, 0, 0, -1, rect.getWidth(), rect.getHeight());
else if (rotation == 270)
frm.concatCTM(0, -1, 1, 0, 0, rect.getWidth());
frm.addTemplate(app[0], 0, 0);
if (!acro6Layers)
frm.addTemplate(app[1], scale, 0, 0, scale, x, y);
frm.addTemplate(app[2], 0, 0);
if (!acro6Layers) {
frm.addTemplate(app[3], scale, 0, 0, scale, x, y);
frm.addTemplate(app[4], 0, 0);
}
}
PdfTemplate napp = new PdfTemplate(writer);
napp.setBoundingBox(rotated);
writer.addDirectTemplateSimple(napp, null);
napp.addTemplate(frm, 0, 0);
return napp;
}
|
public Certificate[] getCertChain() {
return this.certChain;
}
Gets the certificate chain. |
public int getCertificationLevel() {
return this.certificationLevel;
}
Gets the certified status of this document. |
public String getContact() {
return this.contact;
}
Gets the signing contact. |
public CRL[] getCrlList() {
return this.crlList;
}
Gets the certificate revocation list. |
public PdfDictionary getCryptoDictionary() {
return cryptoDictionary;
}
Gets the user made signature dictionary. This is the dictionary at the /V key. |
public String getFieldName() {
return fieldName;
}
|
public PdfName getFilter() {
return filter;
}
Gets the filter used to sign the document. |
public Image getImage() {
return this.image;
}
Gets the background image for the layer 2. |
public float getImageScale() {
return this.imageScale;
}
Gets the scaling to be applied to the background image. |
public PdfTemplate getLayer(int layer) {
if (layer < 0 || layer >= app.length)
return null;
PdfTemplate t = app[layer];
if (t == null) {
t = app[layer] = new PdfTemplate(writer);
t.setBoundingBox(rect);
writer.addDirectTemplateSimple(t, new PdfName("n" + layer));
}
return t;
}
|
public Font getLayer2Font() {
return this.layer2Font;
}
Gets the n2 and n4 layer font. |
public String getLayer2Text() {
return layer2Text;
}
Gets the signature text identifying the signer if set by setLayer2Text(). |
public String getLayer4Text() {
return layer4Text;
}
Gets the text identifying the signature status if set by setLayer4Text(). |
public String getLocation() {
return this.location;
}
Gets the signing location. |
public String getNewSigName() {
AcroFields af = writer.getAcroFields();
String name = "Signature";
int step = 0;
boolean found = false;
while (!found) {
++step;
String n1 = name + step;
if (af.getFieldItem(n1) != null)
continue;
n1 += ".";
found = true;
for (Iterator it = af.getFields().keySet().iterator(); it.hasNext();) {
String fn = (String)it.next();
if (fn.startsWith(n1)) {
found = false;
break;
}
}
}
name += step;
return name;
}
Gets a new signature fied name that doesn't clash with any existing name. |
OutputStream getOriginalout() {
return originalout;
}
|
public int getPage() {
return page;
}
Gets the page number of the field. |
public Rectangle getPageRect() {
return pageRect;
}
Gets the rectangle that represent the position and dimension of the signature in the page. |
public PrivateKey getPrivKey() {
return privKey;
}
|
public String getProvider() {
return this.provider;
}
Returns the Cryptographic Service Provider that will sign the document. |
public InputStream getRangeStream() {
return new PdfSignatureAppearance.RangeStream(raf, bout, range);
}
Gets the document bytes that are hashable when using external signatures. The general sequence is:
preClose(), getRangeStream() and close().
|
public String getReason() {
return this.reason;
}
|
public Rectangle getRect() {
return rect;
}
Gets the rectangle representing the signature dimensions. |
public int getRender() {
return render;
}
Gets the rendering mode for this signature. |
public int getRunDirection() {
return runDirection;
}
|
public PdfSigGenericPKCS getSigStandard() {
return sigStandard;
}
|
public Calendar getSignDate() {
return signDate;
}
|
public PdfSignatureAppearance.SignatureEvent getSignatureEvent() {
return this.signatureEvent;
}
Getter for property signatureEvent. |
public Image getSignatureGraphic() {
return signatureGraphic;
}
Gets the Image object to render. |
ByteBuffer getSigout() {
return sigout;
}
|
public PdfStamper getStamper() {
return stamper;
}
Gets the PdfStamper associated with this instance. |
public File getTempFile() {
return tempFile;
}
|
public PdfTemplate getTopLayer() {
if (frm == null) {
frm = new PdfTemplate(writer);
frm.setBoundingBox(rect);
writer.addDirectTemplateSimple(frm, new PdfName("FRM"));
}
return frm;
}
|
public boolean isAcro6Layers() {
return this.acro6Layers;
}
Gets the Acrobat 6.0 layer mode. |
public boolean isInvisible() {
return (rect == null || rect.getWidth() == 0 || rect.getHeight() == 0);
}
Gets the visibility status of the signature. |
public boolean isNewField() {
return this.newField;
}
Checks if a new field was created. |
public boolean isPreClosed() {
return preClosed;
}
Checks if the document is in the process of closing. |
public void preClose() throws IOException, DocumentException {
preClose(null);
}
This is the first method to be called when using external signatures. The general sequence is:
preClose(), getDocumentBytes() and close().
If calling preClose() dont't call PdfStamper.close().
No external signatures are allowed if this method is called. |
public void preClose(HashMap exclusionSizes) throws IOException, DocumentException {
if (preClosed)
throw new DocumentException("Document already pre closed.");
preClosed = true;
AcroFields af = writer.getAcroFields();
String name = getFieldName();
boolean fieldExists = !(isInvisible() || isNewField());
PdfIndirectReference refSig = writer.getPdfIndirectReference();
writer.setSigFlags(3);
if (fieldExists) {
ArrayList widgets = af.getFieldItem(name).widgets;
PdfDictionary widget = (PdfDictionary)widgets.get(0);
writer.markUsed(widget);
widget.put(PdfName.P, writer.getPageReference(getPage()));
widget.put(PdfName.V, refSig);
PdfObject obj = PdfReader.getPdfObjectRelease(widget.get(PdfName.F));
int flags = 0;
if (obj != null && obj.isNumber())
flags = ((PdfNumber)obj).intValue();
flags |= PdfAnnotation.FLAGS_LOCKED;
widget.put(PdfName.F, new PdfNumber(flags));
PdfDictionary ap = new PdfDictionary();
ap.put(PdfName.N, getAppearance().getIndirectReference());
widget.put(PdfName.AP, ap);
}
else {
PdfFormField sigField = PdfFormField.createSignature(writer);
sigField.setFieldName(name);
sigField.put(PdfName.V, refSig);
sigField.setFlags(PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_LOCKED);
int pagen = getPage();
if (!isInvisible())
sigField.setWidget(getPageRect(), null);
else
sigField.setWidget(new Rectangle(0, 0), null);
sigField.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, getAppearance());
sigField.setPage(pagen);
writer.addAnnotation(sigField, pagen);
}
exclusionLocations = new HashMap();
if (cryptoDictionary == null) {
if (PdfName.ADOBE_PPKLITE.equals(getFilter()))
sigStandard = new PdfSigGenericPKCS.PPKLite(getProvider());
else if (PdfName.ADOBE_PPKMS.equals(getFilter()))
sigStandard = new PdfSigGenericPKCS.PPKMS(getProvider());
else if (PdfName.VERISIGN_PPKVS.equals(getFilter()))
sigStandard = new PdfSigGenericPKCS.VeriSign(getProvider());
else
throw new IllegalArgumentException("Unknown filter: " + getFilter());
sigStandard.setExternalDigest(externalDigest, externalRSAdata, digestEncryptionAlgorithm);
if (getReason() != null)
sigStandard.setReason(getReason());
if (getLocation() != null)
sigStandard.setLocation(getLocation());
if (getContact() != null)
sigStandard.setContact(getContact());
sigStandard.put(PdfName.M, new PdfDate(getSignDate()));
sigStandard.setSignInfo(getPrivKey(), getCertChain(), getCrlList());
PdfString contents = (PdfString)sigStandard.get(PdfName.CONTENTS);
PdfLiteral lit = new PdfLiteral((contents.toString().length() + (PdfName.ADOBE_PPKLITE.equals(getFilter())?0:64)) * 2 + 2);
exclusionLocations.put(PdfName.CONTENTS, lit);
sigStandard.put(PdfName.CONTENTS, lit);
lit = new PdfLiteral(80);
exclusionLocations.put(PdfName.BYTERANGE, lit);
sigStandard.put(PdfName.BYTERANGE, lit);
if (certificationLevel > 0) {
addDocMDP(sigStandard);
}
if (signatureEvent != null)
signatureEvent.getSignatureDictionary(sigStandard);
writer.addToBody(sigStandard, refSig, false);
}
else {
PdfLiteral lit = new PdfLiteral(80);
exclusionLocations.put(PdfName.BYTERANGE, lit);
cryptoDictionary.put(PdfName.BYTERANGE, lit);
for (Iterator it = exclusionSizes.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry)it.next();
PdfName key = (PdfName)entry.getKey();
Integer v = (Integer)entry.getValue();
lit = new PdfLiteral(v.intValue());
exclusionLocations.put(key, lit);
cryptoDictionary.put(key, lit);
}
if (certificationLevel > 0)
addDocMDP(cryptoDictionary);
if (signatureEvent != null)
signatureEvent.getSignatureDictionary(cryptoDictionary);
writer.addToBody(cryptoDictionary, refSig, false);
}
if (certificationLevel > 0) {
// add DocMDP entry to root
PdfDictionary docmdp = new PdfDictionary();
docmdp.put(new PdfName("DocMDP"), refSig);
writer.reader.getCatalog().put(new PdfName("Perms"), docmdp);
}
writer.close(stamper.getMoreInfo());
range = new int[exclusionLocations.size() * 2];
int byteRangePosition = ((PdfLiteral)exclusionLocations.get(PdfName.BYTERANGE)).getPosition();
exclusionLocations.remove(PdfName.BYTERANGE);
int idx = 1;
for (Iterator it = exclusionLocations.values().iterator(); it.hasNext();) {
PdfLiteral lit = (PdfLiteral)it.next();
int n = lit.getPosition();
range[idx++] = n;
range[idx++] = lit.getPosLength() + n;
}
Arrays.sort(range, 1, range.length - 1);
for (int k = 3; k < range.length - 2; k += 2)
range[k] -= range[k - 1];
if (tempFile == null) {
bout = sigout.getBuffer();
boutLen = sigout.size();
range[range.length - 1] = boutLen - range[range.length - 2];
ByteBuffer bf = new ByteBuffer();
bf.append('[");
for (int k = 0; k < range.length; ++k)
bf.append(range[k]).append(' ");
bf.append(']");
System.arraycopy(bf.getBuffer(), 0, bout, byteRangePosition, bf.size());
}
else {
try {
raf = new RandomAccessFile(tempFile, "rw");
int boutLen = (int)raf.length();
range[range.length - 1] = boutLen - range[range.length - 2];
ByteBuffer bf = new ByteBuffer();
bf.append('[");
for (int k = 0; k < range.length; ++k)
bf.append(range[k]).append(' ");
bf.append(']");
raf.seek(byteRangePosition);
raf.write(bf.getBuffer(), 0, bf.size());
}
catch (IOException e) {
try{raf.close();}catch(Exception ee){}
try{tempFile.delete();}catch(Exception ee){}
throw e;
}
}
}
This is the first method to be called when using external signatures. The general sequence is:
preClose(), getDocumentBytes() and close().
If calling preClose() dont't call PdfStamper.close().
If using an external signature exclusionSizes must contain at least
the PdfName.CONTENTS key with the size that it will take in the
document. Note that due to the hex string coding this size should be
byte_size*2+2. |
public void setAcro6Layers(boolean acro6Layers) {
this.acro6Layers = acro6Layers;
}
Acrobat 6.0 and higher recommends that only layer n2 and n4 be present. This method sets that mode. |
public void setCertificationLevel(int certificationLevel) {
this.certificationLevel = certificationLevel;
}
Sets the document type to certified instead of simply signed. |
public void setContact(String contact) {
this.contact = contact;
}
Sets the signing contact. |
public void setCrypto(PrivateKey privKey,
Certificate[] certChain,
CRL[] crlList,
PdfName filter) {
this.privKey = privKey;
this.certChain = certChain;
this.crlList = crlList;
this.filter = filter;
}
Sets the cryptographic parameters. |
public void setCryptoDictionary(PdfDictionary cryptoDictionary) {
this.cryptoDictionary = cryptoDictionary;
}
Sets a user made signature dictionary. This is the dictionary at the /V key. |
public void setExternalDigest(byte[] digest,
byte[] RSAdata,
String digestEncryptionAlgorithm) {
externalDigest = digest;
externalRSAdata = RSAdata;
this.digestEncryptionAlgorithm = digestEncryptionAlgorithm;
}
Sets the digest/signature to an external calculated value. |
public void setImage(Image image) {
this.image = image;
}
Sets the background image for the layer 2. |
public void setImageScale(float imageScale) {
this.imageScale = imageScale;
}
Sets the scaling to be applied to the background image. If it's zero the image
will fully fill the rectangle. If it's less than zero the image will fill the rectangle but
will keep the proportions. If it's greater than zero that scaling will be applied.
In any of the cases the image will always be centered. It's zero by default. |
public void setLayer2Font(Font layer2Font) {
this.layer2Font = layer2Font;
}
Sets the n2 and n4 layer font. If the font size is zero, auto-fit will be used. |
public void setLayer2Text(String text) {
layer2Text = text;
}
Sets the signature text identifying the signer. |
public void setLayer4Text(String text) {
layer4Text = text;
}
Sets the text identifying the signature status. |
public void setLocation(String location) {
this.location = location;
}
Sets the signing location. |
void setOriginalout(OutputStream originalout) {
this.originalout = originalout;
}
|
public void setProvider(String provider) {
this.provider = provider;
}
Sets the Cryptographic Service Provider that will sign the document. |
public void setReason(String reason) {
this.reason = reason;
}
|
public void setRender(int render) {
this.render = render;
}
Sets the rendering mode for this signature.
The rendering modes can be the constants SignatureRenderDescription,
SignatureRenderNameAndDescription or SignatureRenderGraphicAndDescription.
The two last modes should be used with Acrobat 6 layer type. |
public void setRunDirection(int runDirection) {
if (runDirection < PdfWriter.RUN_DIRECTION_DEFAULT || runDirection > PdfWriter.RUN_DIRECTION_RTL)
throw new RuntimeException("Invalid run direction: " + runDirection);
this.runDirection = runDirection;
}
Sets the run direction in the n2 and n4 layer. |
public void setSignDate(Calendar signDate) {
this.signDate = signDate;
}
|
public void setSignatureEvent(PdfSignatureAppearance.SignatureEvent signatureEvent) {
this.signatureEvent = signatureEvent;
}
Sets the signature event to allow modification of the signature dictionary. |
public void setSignatureGraphic(Image signatureGraphic) {
this.signatureGraphic = signatureGraphic;
}
Sets the Image object to render when Render is set to SignatureRenderGraphicAndDescription |
void setSigout(ByteBuffer sigout) {
this.sigout = sigout;
}
|
void setStamper(PdfStamper stamper) {
this.stamper = stamper;
}
|
void setTempFile(File tempFile) {
this.tempFile = tempFile;
}
|
public void setVisibleSignature(String fieldName) {
AcroFields af = writer.getAcroFields();
AcroFields.Item item = af.getFieldItem(fieldName);
if (item == null)
throw new IllegalArgumentException("The field " + fieldName + " does not exist.");
PdfDictionary merged = (PdfDictionary)item.merged.get(0);
if (!PdfName.SIG.equals(PdfReader.getPdfObject(merged.get(PdfName.FT))))
throw new IllegalArgumentException("The field " + fieldName + " is not a signature field.");
this.fieldName = fieldName;
PdfArray r = (PdfArray)PdfReader.getPdfObject(merged.get(PdfName.RECT));
ArrayList ar = r.getArrayList();
float llx = ((PdfNumber)PdfReader.getPdfObject((PdfObject)ar.get(0))).floatValue();
float lly = ((PdfNumber)PdfReader.getPdfObject((PdfObject)ar.get(1))).floatValue();
float urx = ((PdfNumber)PdfReader.getPdfObject((PdfObject)ar.get(2))).floatValue();
float ury = ((PdfNumber)PdfReader.getPdfObject((PdfObject)ar.get(3))).floatValue();
pageRect = new Rectangle(llx, lly, urx, ury);
pageRect.normalize();
page = ((Integer)item.page.get(0)).intValue();
int rotation = writer.reader.getPageRotation(page);
Rectangle pageSize = writer.reader.getPageSizeWithRotation(page);
switch (rotation) {
case 90:
pageRect = new Rectangle(
pageRect.getBottom(),
pageSize.getTop() - pageRect.getLeft(),
pageRect.getTop(),
pageSize.getTop() - pageRect.getRight());
break;
case 180:
pageRect = new Rectangle(
pageSize.getRight() - pageRect.getLeft(),
pageSize.getTop() - pageRect.getBottom(),
pageSize.getRight() - pageRect.getRight(),
pageSize.getTop() - pageRect.getTop());
break;
case 270:
pageRect = new Rectangle(
pageSize.getRight() - pageRect.getBottom(),
pageRect.getLeft(),
pageSize.getRight() - pageRect.getTop(),
pageRect.getRight());
break;
}
if (rotation != 0)
pageRect.normalize();
rect = new Rectangle(this.pageRect.getWidth(), this.pageRect.getHeight());
}
Sets the signature to be visible. An empty signature field with the same name must already exist. |
public void setVisibleSignature(Rectangle pageRect,
int page,
String fieldName) {
if (fieldName != null) {
if (fieldName.indexOf('.") >= 0)
throw new IllegalArgumentException("Field names cannot contain a dot.");
AcroFields af = writer.getAcroFields();
AcroFields.Item item = af.getFieldItem(fieldName);
if (item != null)
throw new IllegalArgumentException("The field " + fieldName + " already exists.");
this.fieldName = fieldName;
}
if (page < 1 || page > writer.reader.getNumberOfPages())
throw new IllegalArgumentException("Invalid page number: " + page);
this.pageRect = new Rectangle(pageRect);
this.pageRect.normalize();
rect = new Rectangle(this.pageRect.getWidth(), this.pageRect.getHeight());
this.page = page;
newField = true;
}
Sets the signature to be visible. It creates a new visible signature field. |