|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.lowagie.text.pdf.AcroFields
public class AcroFields
Query and change fields in existing documents either by method calls or by FDF merging.
| Nested Class Summary | |
|---|---|
private static class |
AcroFields.InstHit
|
static class |
AcroFields.Item
The field representations for retrieval and modification. |
private static class |
AcroFields.RevisionStream
|
private static class |
AcroFields.SorterComparator
|
| Field Summary | |
|---|---|
private boolean |
append
|
private static int |
DA_COLOR
|
private static int |
DA_FONT
|
private static int |
DA_SIZE
|
static int |
FIELD_TYPE_CHECKBOX
A field type. |
static int |
FIELD_TYPE_COMBO
A field type. |
static int |
FIELD_TYPE_LIST
A field type. |
static int |
FIELD_TYPE_NONE
A field type invalid or not found. |
static int |
FIELD_TYPE_PUSHBUTTON
A field type. |
static int |
FIELD_TYPE_RADIOBUTTON
A field type. |
static int |
FIELD_TYPE_SIGNATURE
A field type. |
static int |
FIELD_TYPE_TEXT
A field type. |
private java.util.HashMap |
fieldCache
Holds value of property fieldCache. |
(package private) java.util.HashMap |
fields
|
private boolean |
generateAppearances
Holds value of property generateAppearances. |
private boolean |
lastWasString
|
private java.util.HashMap |
localFonts
|
(package private) PdfReader |
reader
|
private java.util.HashMap |
sigNames
|
private static java.util.HashMap |
stdFieldFontNames
|
private int |
topFirst
|
private int |
totalRevisions
Holds value of property totalRevisions. |
(package private) PdfWriter |
writer
|
| Constructor Summary | |
|---|---|
AcroFields(PdfReader reader,
PdfWriter writer)
|
|
| Method Summary | |
|---|---|
void |
exportAsFdf(FdfWriter writer)
Export the fields as a FDF. |
java.io.InputStream |
extractRevision(java.lang.String field)
Extracts a revision from the document. |
(package private) void |
fill()
|
(package private) PdfAppearance |
getAppearance(PdfDictionary merged,
java.lang.String text,
java.lang.String fieldName)
|
java.lang.String[] |
getAppearanceStates(java.lang.String fieldName)
Gets the list of appearance names. |
java.util.ArrayList |
getBlankSignatureNames()
Gets the field names that have blank signatures. |
java.lang.String |
getField(java.lang.String name)
Gets the field value. |
java.util.HashMap |
getFieldCache()
Gets the appearances cache. |
AcroFields.Item |
getFieldItem(java.lang.String name)
Gets the field structure. |
float[] |
getFieldPositions(java.lang.String name)
Gets the field box positions in the document. |
java.util.HashMap |
getFields()
Gets all the fields. |
int |
getFieldType(java.lang.String fieldName)
Gets the field type. |
(package private) java.awt.Color |
getMKColor(PdfArray ar)
|
int |
getRevision(java.lang.String field)
Gets this field revision. |
PdfDictionary |
getSignatureDictionary(java.lang.String name)
Gets the signature dictionary, the one keyed by /V. |
java.util.ArrayList |
getSignatureNames()
Gets the field names that have signatures and are signed. |
int |
getTotalRevisions()
Gets the total number of revisions this document has. |
boolean |
isGenerateAppearances()
Gets the property generateAppearances. |
(package private) boolean |
isInAP(PdfDictionary dic,
PdfName check)
|
private void |
markUsed(PdfObject obj)
|
boolean |
removeField(java.lang.String name)
Removes a field from the document. |
boolean |
removeField(java.lang.String name,
int page)
Removes a field from the document. |
boolean |
removeFieldsFromPage(int page)
Removes all the fields from page. |
private int |
removeRefFromArray(PdfArray array,
PdfObject refo)
|
boolean |
renameField(java.lang.String oldName,
java.lang.String newName)
Renames a field. |
boolean |
setField(java.lang.String name,
java.lang.String value)
Sets the field value. |
boolean |
setField(java.lang.String name,
java.lang.String value,
java.lang.String display)
Sets the field value and the display string. |
void |
setFieldCache(java.util.HashMap fieldCache)
Sets a cache for field appearances. |
boolean |
setFieldProperty(java.lang.String field,
java.lang.String name,
int value,
int[] inst)
Sets a field property. |
boolean |
setFieldProperty(java.lang.String field,
java.lang.String name,
java.lang.Object value,
int[] inst)
Sets a field property. |
void |
setFields(FdfReader fdf)
Sets the fields by FDF merging. |
void |
setFields(XfdfReader xfdf)
Sets the fields by XFDF merging. |
void |
setGenerateAppearances(boolean generateAppearances)
Sets the option to generate appearances. |
boolean |
signatureCoversWholeDocument(java.lang.String name)
Checks is the signature covers the entire document or just part of it. |
private static java.lang.Object[] |
splitDAelements(java.lang.String da)
|
private void |
updateByteRange(PdfPKCS7 pkcs7,
PdfDictionary v)
|
PdfPKCS7 |
verifySignature(java.lang.String name)
Verifies a signature. |
PdfPKCS7 |
verifySignature(java.lang.String name,
java.lang.String provider)
Verifies a signature. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
PdfReader reader
PdfWriter writer
java.util.HashMap fields
private int topFirst
private java.util.HashMap sigNames
private boolean append
private static final int DA_FONT
private static final int DA_SIZE
private static final int DA_COLOR
public static final int FIELD_TYPE_NONE
public static final int FIELD_TYPE_PUSHBUTTON
public static final int FIELD_TYPE_CHECKBOX
public static final int FIELD_TYPE_RADIOBUTTON
public static final int FIELD_TYPE_TEXT
public static final int FIELD_TYPE_LIST
public static final int FIELD_TYPE_COMBO
public static final int FIELD_TYPE_SIGNATURE
private boolean lastWasString
private boolean generateAppearances
private java.util.HashMap localFonts
private static final java.util.HashMap stdFieldFontNames
private int totalRevisions
private java.util.HashMap fieldCache
| Constructor Detail |
|---|
AcroFields(PdfReader reader,
PdfWriter writer)
| Method Detail |
|---|
void fill()
public java.lang.String[] getAppearanceStates(java.lang.String fieldName)
fieldName - the fully qualified field name
null if the field does not existpublic int getFieldType(java.lang.String fieldName)
FIELD_TYPE_PUSHBUTTON,
FIELD_TYPE_CHECKBOX, FIELD_TYPE_RADIOBUTTON,
FIELD_TYPE_TEXT, FIELD_TYPE_LIST,
FIELD_TYPE_COMBO or FIELD_TYPE_SIGNATURE.
If the field does not exist or is invalid it returns
FIELD_TYPE_NONE.
fieldName - the field name
public void exportAsFdf(FdfWriter writer)
writer - the FDF writer
public boolean renameField(java.lang.String oldName,
java.lang.String newName)
oldName - the old field namenewName - the new field name
true if the renaming was successful, false
otherwiseprivate static java.lang.Object[] splitDAelements(java.lang.String da)
PdfAppearance getAppearance(PdfDictionary merged,
java.lang.String text,
java.lang.String fieldName)
throws java.io.IOException,
DocumentException
java.io.IOException
DocumentExceptionjava.awt.Color getMKColor(PdfArray ar)
public java.lang.String getField(java.lang.String name)
name - the fully qualified field name
public boolean setFieldProperty(java.lang.String field,
java.lang.String name,
java.lang.Object value,
int[] inst)
BaseFont.java.awt.Color.Float.
java.awt.Color.
If null removes the background.java.awt.Color.
If null removes the border.
field - the field namename - the property namevalue - the property valueinst - an array of int indexing into AcroField.Item.merged elements to process.
Set to null to process all
true if the property exists, false otherwise
public boolean setFieldProperty(java.lang.String field,
java.lang.String name,
int value,
int[] inst)
field - the field namename - the property namevalue - the property valueinst - an array of int indexing into AcroField.Item.merged elements to process.
Set to null to process all
true if the property exists, false otherwise
public void setFields(FdfReader fdf)
throws java.io.IOException,
DocumentException
fdf - the FDF form
java.io.IOException - on error
DocumentException - on error
public void setFields(XfdfReader xfdf)
throws java.io.IOException,
DocumentException
xfdf - the XFDF form
java.io.IOException - on error
DocumentException - on error
public boolean setField(java.lang.String name,
java.lang.String value)
throws java.io.IOException,
DocumentException
name - the fully qualified field namevalue - the field value
true if the field was found and changed,
false otherwise
java.io.IOException - on error
DocumentException - on error
public boolean setField(java.lang.String name,
java.lang.String value,
java.lang.String display)
throws java.io.IOException,
DocumentException
name - the fully qualified field namevalue - the field valuedisplay - the string that is used for the appearance
true if the field was found and changed,
false otherwise
java.io.IOException - on error
DocumentException - on error
boolean isInAP(PdfDictionary dic,
PdfName check)
public java.util.HashMap getFields()
AcroFields.Item.
public AcroFields.Item getFieldItem(java.lang.String name)
name - the name of the field
null if the field
does not existpublic float[] getFieldPositions(java.lang.String name)
float
multiple of 5. For each of this groups the values are: [page, llx, lly, urx,
ury].
name - the field name
null if field does not exist
private int removeRefFromArray(PdfArray array,
PdfObject refo)
public boolean removeFieldsFromPage(int page)
page.
page - the page to remove the fields from
true if any field was removed, false otherwise
public boolean removeField(java.lang.String name,
int page)
name are removed from the document otherwise only the fields in
that particular page are removed.
name - the field namepage - the page to remove the field from or -1 to remove it from all the pages
true if the field exists, false otherwisepublic boolean removeField(java.lang.String name)
name - the field name
true if the field exists, false otherwisepublic boolean isGenerateAppearances()
public void setGenerateAppearances(boolean generateAppearances)
true.
generateAppearances - the option to generate appearancespublic java.util.ArrayList getSignatureNames()
public java.util.ArrayList getBlankSignatureNames()
public PdfDictionary getSignatureDictionary(java.lang.String name)
name - the field name
null if the field is not
a signaturepublic boolean signatureCoversWholeDocument(java.lang.String name)
name - the signature field name
true if the signature covers the entire document,
false otherwisepublic PdfPKCS7 verifySignature(java.lang.String name)
KeyStore kall = PdfPKCS7.loadCacertsKeyStore();
PdfReader reader = new PdfReader("my_signed_doc.pdf");
AcroFields af = reader.getAcroFields();
ArrayList names = af.getSignatureNames();
for (int k = 0; k < names.size(); ++k) {
String name = (String)names.get(k);
System.out.println("Signature name: " + name);
System.out.println("Signature covers whole document: " + af.signatureCoversWholeDocument(name));
PdfPKCS7 pk = af.verifySignature(name);
Calendar cal = pk.getSignDate();
Certificate pkc[] = pk.getCertificates();
System.out.println("Subject: " + PdfPKCS7.getSubjectFields(pk.getSigningCertificate()));
System.out.println("Document modified: " + !pk.verify());
Object fails[] = PdfPKCS7.verifyCertificates(pkc, kall, null, cal);
if (fails == null)
System.out.println("Certificates verified against the KeyStore");
else
System.out.println("Certificate failed: " + fails[1]);
}
name - the signature field name
PdfPKCS7 class to continue the verification
public PdfPKCS7 verifySignature(java.lang.String name,
java.lang.String provider)
KeyStore kall = PdfPKCS7.loadCacertsKeyStore();
PdfReader reader = new PdfReader("my_signed_doc.pdf");
AcroFields af = reader.getAcroFields();
ArrayList names = af.getSignatureNames();
for (int k = 0; k < names.size(); ++k) {
String name = (String)names.get(k);
System.out.println("Signature name: " + name);
System.out.println("Signature covers whole document: " + af.signatureCoversWholeDocument(name));
PdfPKCS7 pk = af.verifySignature(name);
Calendar cal = pk.getSignDate();
Certificate pkc[] = pk.getCertificates();
System.out.println("Subject: " + PdfPKCS7.getSubjectFields(pk.getSigningCertificate()));
System.out.println("Document modified: " + !pk.verify());
Object fails[] = PdfPKCS7.verifyCertificates(pkc, kall, null, cal);
if (fails == null)
System.out.println("Certificates verified against the KeyStore");
else
System.out.println("Certificate failed: " + fails[1]);
}
name - the signature field nameprovider - the provider or null for the default provider
PdfPKCS7 class to continue the verification
private void updateByteRange(PdfPKCS7 pkcs7,
PdfDictionary v)
private void markUsed(PdfObject obj)
public int getTotalRevisions()
public int getRevision(java.lang.String field)
field revision.
field - the signature field name
public java.io.InputStream extractRevision(java.lang.String field)
throws java.io.IOException
field - the signature field name
InputStream covering the revision. Returns null if
it's not a signature field
java.io.IOException - on errorpublic java.util.HashMap getFieldCache()
public void setFieldCache(java.util.HashMap fieldCache)
String pdfFile = ...;// the pdf file used as template
ArrayList xfdfFiles = ...;// the xfdf file names
ArrayList pdfOutFiles = ...;// the output file names, one for each element in xpdfFiles
HashMap cache = new HashMap();// the appearances cache
PdfReader originalReader = new PdfReader(pdfFile);
for (int k = 0; k < xfdfFiles.size(); ++k) {
PdfReader reader = new PdfReader(originalReader);
XfdfReader xfdf = new XfdfReader((String)xfdfFiles.get(k));
PdfStamper stp = new PdfStamper(reader, new FileOutputStream((String)pdfOutFiles.get(k)));
AcroFields af = stp.getAcroFields();
af.setFieldCache(cache);
af.setFields(xfdf);
stp.close();
}
fieldCache - an HasMap that will carry the cached appearances
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||