com.lowagie.text.pdf
public class AcroFields extends Object
Nested Class Summary | |
---|---|
static class | AcroFields.InstHit |
static class | AcroFields.Item The field representations for retrieval and modification. |
static class | AcroFields.RevisionStream |
static class | AcroFields.SorterComparator |
Field Summary | |
---|---|
boolean | append |
static PdfName[] | buttonRemove |
static int | DA_COLOR |
static int | DA_FONT |
static int | DA_SIZE |
HashMap | extensionFonts |
float | extraMarginLeft |
float | extraMarginTop |
HashMap | fieldCache
Holds value of property fieldCache. |
HashMap | fields |
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. |
boolean | generateAppearances Holds value of property generateAppearances. |
boolean | lastWasString |
HashMap | localFonts |
PdfReader | reader |
HashMap | sigNames |
static HashMap | stdFieldFontNames |
ArrayList | substitutionFonts |
int | topFirst |
int | totalRevisions
Holds value of property totalRevisions. |
PdfWriter | writer |
XfaForm | xfa |
Constructor Summary | |
---|---|
AcroFields(PdfReader reader, PdfWriter writer) |
Method Summary | |
---|---|
void | addSubstitutionFont(BaseFont font)
Adds a substitution font to the list. |
void | decodeGenericDictionary(PdfDictionary merged, BaseField tx) |
void | exportAsFdf(FdfWriter writer)
Export the fields as a FDF. |
InputStream | extractRevision(String field)
Extracts a revision from the document. |
void | fill() |
PdfAppearance | getAppearance(PdfDictionary merged, String text, String fieldName) |
String[] | getAppearanceStates(String fieldName) Gets the list of appearance names. |
ArrayList | getBlankSignatureNames()
Gets the field names that have blank signatures. |
String | getField(String name) Gets the field value. |
HashMap | getFieldCache()
Gets the appearances cache. |
AcroFields.Item | getFieldItem(String name)
Gets the field structure. |
float[] | getFieldPositions(String name)
Gets the field box positions in the document. |
HashMap | getFields() Gets all the fields. |
int | getFieldType(String fieldName)
Gets the field type. |
String[] | getListOption(String fieldName, int idx) |
String[] | getListOptionDisplay(String fieldName)
Gets the list of display option values from fields of type list or combo.
|
String[] | getListOptionExport(String fieldName)
Gets the list of export option values from fields of type list or combo.
|
Color | getMKColor(PdfArray ar) |
PushbuttonField | getNewPushbuttonFromField(String field)
Creates a new pushbutton from an existing field. |
int | getRevision(String field)
Gets this field revision. |
PdfDictionary | getSignatureDictionary(String name)
Gets the signature dictionary, the one keyed by /V. |
ArrayList | getSignatureNames()
Gets the field names that have signatures and are signed. |
ArrayList | getSubstitutionFonts()
Gets the list of substitution fonts. |
int | getTotalRevisions()
Gets the total number of revisions this document has. |
String | getTranslatedFieldName(String name)
Gets the long XFA translated name. |
XfaForm | getXfa()
Gets the XFA form processor. |
boolean | isGenerateAppearances() Gets the property generateAppearances. |
boolean | isInAP(PdfDictionary dic, PdfName check) |
void | markUsed(PdfObject obj) |
void | mergeXfaData(Node n)
Merges an XML data structure into this form. |
boolean | regenerateField(String name)
Regenerates the field appearance.
|
boolean | removeField(String name, int page)
Removes a field from the document. |
boolean | removeField(String name)
Removes a field from the document. |
boolean | removeFieldsFromPage(int page)
Removes all the fields from page . |
int | removeRefFromArray(PdfArray array, PdfObject refo) |
boolean | renameField(String oldName, String newName)
Renames a field. |
boolean | replacePushbuttonField(String field, PdfFormField button)
Replaces the field with a new pushbutton. |
void | setExtraMargin(float extraMarginLeft, float extraMarginTop)
Sets extra margins in text fields to better mimic the Acrobat layout. |
boolean | setField(String name, String value) Sets the field value. |
boolean | setField(String name, String value, String display) Sets the field value and the display string. |
void | setFieldCache(HashMap fieldCache)
Sets a cache for field appearances. |
boolean | setFieldProperty(String field, String name, Object value, int[] inst)
Sets a field property. |
boolean | setFieldProperty(String field, String name, int 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 | setListOption(String fieldName, String[] exportValues, String[] displayValues)
Sets the option list for fields of type list or combo. |
void | setSubstitutionFonts(ArrayList substitutionFonts)
Sets a list of substitution fonts. |
boolean | signatureCoversWholeDocument(String name)
Checks is the signature covers the entire document or just part of it. |
static Object[] | splitDAelements(String da) |
void | updateByteRange(PdfPKCS7 pkcs7, PdfDictionary v) |
PdfPKCS7 | verifySignature(String name)
Verifies a signature. |
PdfPKCS7 | verifySignature(String name, String provider)
Verifies a signature. |
Parameters: font the font
Parameters: writer the FDF writer
Parameters: field the signature field name
Returns: an InputStream
covering the revision. Returns null
if
it's not a signature field
Throws: IOException on error
Parameters: fieldName the fully qualified field name
Returns: the list of names or null
if the field does not exist
Returns: the field names that have blank signatures
Parameters: name the fully qualified field name
Returns: the field value
Returns: the appearances cache
Parameters: name the name of the field
Returns: the field structure or null
if the field
does not exist
float
multiple of 5. For each of this groups the values are: [page, llx, lly, urx,
ury]. The coordinates have the page rotation in consideration.Parameters: name the field name
Returns: the positions or null
if field does not exist
AcroFields.Item
.Returns: all the fields
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
.
Parameters: fieldName the field name
Returns: the field type
null
.Parameters: fieldName the field name
Returns: the list of export option values from fields of type list or combo
null
.Parameters: fieldName the field name
Returns: the list of export option values from fields of type list or combo
Parameters: field the field name that should be a pushbutton
Returns: a new pushbutton or null
if the field is not a pushbutton
field
revision.Parameters: field the signature field name
Returns: the revision or zero if it's not a signature field
Parameters: name the field name
Returns: the signature dictionary keyed by /V or null
if the field is not
a signature
Returns: the field names that have signatures and are signed
BaseFont
and can be null
. The fonts in this list will be used if the original
font doesn't contain the needed glyphs.Returns: the list
Returns: the total number of revisions
Parameters: name the name of the field
Returns: the long field name
Returns: the XFA form processor
Returns: the property generateAppearances
Parameters: n the top node of the data structure
Throws: java.io.IOException on error com.lowagie.text.DocumentException o error
Parameters: name the fully qualified field name or the partial name in the case of XFA forms
Returns: true
if the field was found and changed,
false
otherwise
Throws: IOException on error DocumentException on error
name
are removed from the document otherwise only the fields in
that particular page are removed.Parameters: name the field name page the page to remove the field from or -1 to remove it from all the pages
Returns: true
if the field exists, false otherwise
Parameters: name the field name
Returns: true
if the field exists, false otherwise
page
.Parameters: page the page to remove the fields from
Returns: true
if any field was removed, false otherwise
Parameters: oldName the old field name newName the new field name
Returns: true
if the renaming was successful, false
otherwise
Parameters: field the field name button the PdfFormField
representing the pushbutton
Returns: true
if the field was replaced, false
if the field
was not a pushbutton
Parameters: extraMarginLeft the extra marging left extraMarginTop the extra margin top
Parameters: name the fully qualified field name or the partial name in the case of XFA forms value the field value
Returns: true
if the field was found and changed,
false
otherwise
Throws: IOException on error DocumentException on error
Parameters: name the fully qualified field name or the partial name in the case of XFA forms value the field value display the string that is used for the appearance. If null
the value
parameter will be used
Returns: true
if the field was found and changed,
false
otherwise
Throws: IOException on error DocumentException on error
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(); }
Parameters: fieldCache an HasMap that will carry the cached appearances
BaseFont
.java.awt.Color
.Float
.
java.awt.Color
.
If null
removes the background.java.awt.Color
.
If null
removes the border.Parameters: field the field name name the property name value the property value inst an array of int
indexing into AcroField.Item.merged
elements to process.
Set to null
to process all
Returns: true
if the property exists, false
otherwise
Parameters: field the field name name the property name value the property value inst an array of int
indexing into AcroField.Item.merged
elements to process.
Set to null
to process all
Returns: true
if the property exists, false
otherwise
Parameters: fdf the FDF form
Throws: IOException on error DocumentException on error
Parameters: xfdf the XFDF form
Throws: IOException on error DocumentException on error
true
.Parameters: generateAppearances the option to generate appearances
exportValues
or displayValues
may be null
but not both. This method will only
set the list but will not set the value or appearance. For that, calling setField()
is required.
An example:
PdfReader pdf = new PdfReader("input.pdf"); PdfStamper stp = new PdfStamper(pdf, new FileOutputStream("output.pdf")); AcroFields af = stp.getAcroFields(); af.setListOption("ComboBox", new String[]{"a", "b", "c"}, new String[]{"first", "second", "third"}); af.setField("ComboBox", "b"); stp.close();
Parameters: fieldName the field name exportValues the export values displayValues the display values
Returns: true
if the operation succeeded, false
otherwise
BaseFont
and can also be null
. The fonts in this list will be used if the original
font doesn't contain the needed glyphs.Parameters: substitutionFonts the list
Parameters: name the signature field name
Returns: true
if the signature covers the entire document,
false
otherwise
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]); }
Parameters: name the signature field name
Returns: a PdfPKCS7
class to continue the verification
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]); }
Parameters: name the signature field name provider the provider or null
for the default provider
Returns: a PdfPKCS7
class to continue the verification