HiraokaHyperTools.iTextSharp-LGPL  0.2.5
iTextSharp.text.pdf.AcroFields Class Reference

Classes

class  Item
 
class  RevisionStream
 

Public Member Functions

String[] GetAppearanceStates (String fieldName)
 
String[] GetListOptionExport (String fieldName)
 
String[] GetListOptionDisplay (String fieldName)
 
bool SetListOption (String fieldName, String[] exportValues, String[] displayValues)
 
int GetFieldType (String fieldName)
 
void ExportAsFdf (FdfWriter writer)
 
bool RenameField (String oldName, String newName)
 
void DecodeGenericDictionary (PdfDictionary merged, BaseField tx)
 
String GetField (String name)
 
String[] GetListSelection (String name)
 
bool SetFieldProperty (String field, String name, Object value, int[] inst)
 
bool SetFieldProperty (String field, String name, int value, int[] inst)
 
void MergeXfaData (XmlNode n)
 
void SetFields (FdfReader fdf)
 
void SetFields (XfdfReader xfdf)
 
bool RegenerateField (String name)
 
bool SetField (String name, String value)
 
bool SetField (String name, String value, String display)
 
bool SetListSelection (String name, String[] value)
 
Item GetFieldItem (String name)
 
String GetTranslatedFieldName (String name)
 
float[] GetFieldPositions (String name)
 
bool RemoveFieldsFromPage (int page)
 
bool RemoveField (String name, int page)
 
bool RemoveField (String name)
 
ArrayList GetSignatureNames ()
 
ArrayList GetBlankSignatureNames ()
 
PdfDictionary GetSignatureDictionary (String name)
 
bool SignatureCoversWholeDocument (String name)
 
PdfPKCS7 VerifySignature (String name)
 
int GetRevision (String field)
 
Stream ExtractRevision (String field)
 
void SetExtraMargin (float extraMarginLeft, float extraMarginTop)
 
void AddSubstitutionFont (BaseFont font)
 
PushbuttonField GetNewPushbuttonFromField (String field)
 
PushbuttonField GetNewPushbuttonFromField (String field, int order)
 
bool ReplacePushbuttonField (String field, PdfFormField button)
 
bool ReplacePushbuttonField (String field, PdfFormField button, int order)
 

Static Public Member Functions

static Object[] SplitDAelements (String da)
 

Static Public Attributes

const int DA_FONT = 0
 
const int DA_SIZE = 1
 
const int DA_COLOR = 2
 
const int FIELD_TYPE_NONE = 0
 
const int FIELD_TYPE_PUSHBUTTON = 1
 
const int FIELD_TYPE_CHECKBOX = 2
 
const int FIELD_TYPE_RADIOBUTTON = 3
 
const int FIELD_TYPE_TEXT = 4
 
const int FIELD_TYPE_LIST = 5
 
const int FIELD_TYPE_COMBO = 6
 
const int FIELD_TYPE_SIGNATURE = 7
 

Properties

Hashtable Fields [get]
 
bool GenerateAppearances [get, set]
 
int TotalRevisions [get]
 
Hashtable FieldCache [get, set]
 
ArrayList SubstitutionFonts [get, set]
 
XfaForm Xfa [get]
 

Detailed Description

Query and change fields in existing documents either by method calls or by FDF merging.

Author
Paulo Soares (psoar.nosp@m.es@c.nosp@m.onsis.nosp@m.te.p.nosp@m.t)

Member Function Documentation

◆ AddSubstitutionFont()

void iTextSharp.text.pdf.AcroFields.AddSubstitutionFont ( BaseFont  font)

Adds a substitution font to the list. The fonts in this list will be used if the original font doesn't contain the needed glyphs.

Parameters
fontthe font

◆ DecodeGenericDictionary()

void iTextSharp.text.pdf.AcroFields.DecodeGenericDictionary ( PdfDictionary  merged,
BaseField  tx 
)

◆ ExportAsFdf()

void iTextSharp.text.pdf.AcroFields.ExportAsFdf ( FdfWriter  writer)

Export the fields as a FDF.

Parameters
writerthe FDF writer

◆ ExtractRevision()

Stream iTextSharp.text.pdf.AcroFields.ExtractRevision ( String  field)

Extracts a revision from the document.

Parameters
fieldthe signature field name
Returns
an Stream covering the revision. Returns null if it's not a signature field
Exceptions
IOExceptionon error

◆ GetAppearanceStates()

String [] iTextSharp.text.pdf.AcroFields.GetAppearanceStates ( String  fieldName)

Gets the list of appearance names. Use it to get the names allowed with radio and checkbox fields. If the /Opt key exists the values will also be included. The name 'Off' may also be valid even if not returned in the list.

Parameters
fieldNamethe fully qualified field name
Returns
the list of names or null if the field does not exist

◆ GetBlankSignatureNames()

ArrayList iTextSharp.text.pdf.AcroFields.GetBlankSignatureNames ( )

Gets the field names that have blank signatures.

Returns
the field names that have blank signatures

◆ GetField()

String iTextSharp.text.pdf.AcroFields.GetField ( String  name)

Gets the field value.

Parameters
namethe fully qualified field name
Returns
the field value

◆ GetFieldItem()

Item iTextSharp.text.pdf.AcroFields.GetFieldItem ( String  name)

Gets the field structure.

Parameters
namethe name of the field
Returns
the field structure or null if the field does not exist

◆ GetFieldPositions()

float [] iTextSharp.text.pdf.AcroFields.GetFieldPositions ( String  name)

Gets the field box positions in the document. The return is an array of 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
namethe field name
Returns
the positions or null if field does not exist

◆ GetFieldType()

int iTextSharp.text.pdf.AcroFields.GetFieldType ( String  fieldName)

Gets the field type. The type can be one of: 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
fieldNamethe field name
Returns
the field type

◆ GetListOptionDisplay()

String [] iTextSharp.text.pdf.AcroFields.GetListOptionDisplay ( String  fieldName)

Gets the list of display option values from fields of type list or combo. If the field doesn't exist or the field type is not list or combo it will return null.

Parameters
fieldNamethe field name
Returns
the list of export option values from fields of type list or combo

◆ GetListOptionExport()

String [] iTextSharp.text.pdf.AcroFields.GetListOptionExport ( String  fieldName)

Gets the list of export option values from fields of type list or combo. If the field doesn't exist or the field type is not list or combo it will return null.

Parameters
fieldNamethe field name
Returns
the list of export option values from fields of type list or combo

◆ GetListSelection()

String [] iTextSharp.text.pdf.AcroFields.GetListSelection ( String  name)

Gets the field values of a Choice field.

Parameters
namethe fully qualified field name
Returns
the field value
Since
2.1.3

◆ GetNewPushbuttonFromField() [1/2]

PushbuttonField iTextSharp.text.pdf.AcroFields.GetNewPushbuttonFromField ( String  field)

Creates a new pushbutton from an existing field. If there are several pushbuttons with the same name only the first one is used. This pushbutton can be changed and be used to replace an existing one, with the same name or other name, as long is it is in the same document. To replace an existing pushbutton call replacePushbuttonField(String,PdfFormField).

Parameters
fieldthe field name that should be a pushbutton
Returns
a new pushbutton or null if the field is not a pushbutton

◆ GetNewPushbuttonFromField() [2/2]

PushbuttonField iTextSharp.text.pdf.AcroFields.GetNewPushbuttonFromField ( String  field,
int  order 
)

Creates a new pushbutton from an existing field. This pushbutton can be changed and be used to replace an existing one, with the same name or other name, as long is it is in the same document. To replace an existing pushbutton call replacePushbuttonField(String,PdfFormField,int).

Parameters
fieldthe field name that should be a pushbutton
orderthe field order in fields with same name
Returns
a new pushbutton or null if the field is not a pushbutton

◆ GetRevision()

int iTextSharp.text.pdf.AcroFields.GetRevision ( String  field)

Gets this field revision.

Parameters
fieldthe signature field name
Returns
the revision or zero if it's not a signature field

◆ GetSignatureDictionary()

PdfDictionary iTextSharp.text.pdf.AcroFields.GetSignatureDictionary ( String  name)

Gets the signature dictionary, the one keyed by /V.

Parameters
namethe field name
Returns
the signature dictionary keyed by /V or null if the field is not a signature

◆ GetSignatureNames()

ArrayList iTextSharp.text.pdf.AcroFields.GetSignatureNames ( )

Gets the field names that have signatures and are signed.

Returns
the field names that have signatures and are signed

◆ GetTranslatedFieldName()

String iTextSharp.text.pdf.AcroFields.GetTranslatedFieldName ( String  name)

Gets the long XFA translated name.

Parameters
namethe name of the field
Returns
the long field name

◆ MergeXfaData()

void iTextSharp.text.pdf.AcroFields.MergeXfaData ( XmlNode  n)

Merges an XML data structure into this form.

Parameters
nthe top node of the data structure
Exceptions
java.io.IOExceptionon error
com.lowagie.text.DocumentExceptiono error

◆ RegenerateField()

bool iTextSharp.text.pdf.AcroFields.RegenerateField ( String  name)

Regenerates the field appearance. This is usefull when you change a field property, but not its value, for instance form.SetFieldProperty("f", "bgcolor", Color.BLUE, null); This won't have any effect, unless you use RegenerateField("f") after changing the property.

Parameters
namethe fully qualified field name or the partial name in the case of XFA forms
Exceptions
IOExceptionon error
DocumentExceptionon error
Returns
true if the field was found and changed, false otherwise

◆ RemoveField() [1/2]

bool iTextSharp.text.pdf.AcroFields.RemoveField ( String  name)

Removes a field from the document.

Parameters
namethe field name
Returns
true if the field exists, false otherwise

◆ RemoveField() [2/2]

bool iTextSharp.text.pdf.AcroFields.RemoveField ( String  name,
int  page 
)

Removes a field from the document. If page equals -1 all the fields with this name are removed from the document otherwise only the fields in that particular page are removed.

Parameters
namethe field name
pagethe page to remove the field from or -1 to remove it from all the pages
Returns
true if the field exists, false otherwise

◆ RemoveFieldsFromPage()

bool iTextSharp.text.pdf.AcroFields.RemoveFieldsFromPage ( int  page)

Removes all the fields from page.

Parameters
pagethe page to remove the fields from
Returns
true if any field was removed, false otherwise

◆ RenameField()

bool iTextSharp.text.pdf.AcroFields.RenameField ( String  oldName,
String  newName 
)

Renames a field. Only the last part of the name can be renamed. For example, if the original field is "ab.cd.ef" only the "ef" part can be renamed.

Parameters
oldNamethe old field name
newNamethe new field name
Returns
true if the renaming was successful, false otherwise

◆ ReplacePushbuttonField() [1/2]

bool iTextSharp.text.pdf.AcroFields.ReplacePushbuttonField ( String  field,
PdfFormField  button 
)

Replaces the first field with a new pushbutton. The pushbutton can be created with getNewPushbuttonFromField(String) from the same document or it can be a generic PdfFormField of the type pushbutton.

Parameters
fieldthe field name
buttonthe PdfFormField representing the pushbutton
Returns
true if the field was replaced, false if the field was not a pushbutton

◆ ReplacePushbuttonField() [2/2]

bool iTextSharp.text.pdf.AcroFields.ReplacePushbuttonField ( String  field,
PdfFormField  button,
int  order 
)

Replaces the designated field with a new pushbutton. The pushbutton can be created with getNewPushbuttonFromField(String,int) from the same document or it can be a generic PdfFormField of the type pushbutton.

Parameters
fieldthe field name
buttonthe PdfFormField representing the pushbutton
orderthe field order in fields with same name
Returns
true if the field was replaced, false if the field was not a pushbutton

◆ SetExtraMargin()

void iTextSharp.text.pdf.AcroFields.SetExtraMargin ( float  extraMarginLeft,
float  extraMarginTop 
)

Sets extra margins in text fields to better mimic the Acrobat layout.

Parameters
extraMarginLeftthe extra marging left
extraMarginTopthe extra margin top

◆ SetField() [1/2]

bool iTextSharp.text.pdf.AcroFields.SetField ( String  name,
String  value 
)

Sets the field value.

Parameters
namethe fully qualified field name or the partial name in the case of XFA forms
valuethe field value
Exceptions
IOExceptionon error
DocumentExceptionon error
Returns
true if the field was found and changed, false otherwise

◆ SetField() [2/2]

bool iTextSharp.text.pdf.AcroFields.SetField ( String  name,
String  value,
String  display 
)

Sets the field value and the display string. The display string is used to build the appearance in the cases where the value is modified by Acrobat with JavaScript and the algorithm is known.

Parameters
namethe fully qualified field name or the partial name in the case of XFA forms
valuethe field value
displaythe 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
Exceptions
IOExceptionon error
DocumentExceptionon error

◆ SetFieldProperty() [1/2]

bool iTextSharp.text.pdf.AcroFields.SetFieldProperty ( String  field,
String  name,
int  value,
int[]  inst 
)

Sets a field property. Valid property names are:

  • flags - a set of flags specifying various characteristics of the field’s widget annotation. The value of this entry replaces that of the F entry in the form’s corresponding annotation dictionary.
  • setflags - a set of flags to be set (turned on) in the F entry of the form’s corresponding widget annotation dictionary. Bits equal to 1 cause the corresponding bits in F to be set to 1.
  • clrflags - a set of flags to be cleared (turned off) in the F entry of the form’s corresponding widget annotation dictionary. Bits equal to 1 cause the corresponding bits in F to be set to 0.
  • fflags - a set of flags specifying various characteristics of the field. The value of this entry replaces that of the Ff entry in the form’s corresponding field dictionary.
  • setfflags - a set of flags to be set (turned on) in the Ff entry of the form’s corresponding field dictionary. Bits equal to 1 cause the corresponding bits in Ff to be set to 1.
  • clrfflags - a set of flags to be cleared (turned off) in the Ff entry of the form’s corresponding field dictionary. Bits equal to 1 cause the corresponding bits in Ff to be set to 0.
Parameters
fieldthe field name
namethe property name
valuethe property value
instan 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

◆ SetFieldProperty() [2/2]

bool iTextSharp.text.pdf.AcroFields.SetFieldProperty ( String  field,
String  name,
Object  value,
int[]  inst 
)

Sets a field property. Valid property names are:

  • textfont - sets the text font. The value for this entry is a BaseFont.
  • textcolor - sets the text color. The value for this entry is a java.awt.Color.
  • textsize - sets the text size. The value for this entry is a Float.
  • bgcolor - sets the background color. The value for this entry is a java.awt.Color. If null removes the background.
  • bordercolor - sets the border color. The value for this entry is a java.awt.Color. If null removes the border.
Parameters
fieldthe field name
namethe property name
valuethe property value
instan 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

◆ SetFields() [1/2]

void iTextSharp.text.pdf.AcroFields.SetFields ( FdfReader  fdf)

Sets the fields by FDF merging.

Parameters
fdfthe FDF form
Exceptions
IOExceptionon error
DocumentExceptionon error

◆ SetFields() [2/2]

void iTextSharp.text.pdf.AcroFields.SetFields ( XfdfReader  xfdf)

Sets the fields by XFDF merging.

Parameters
xfdfthe XFDF form
Exceptions
IOExceptionon error
DocumentExceptionon error

◆ SetListOption()

bool iTextSharp.text.pdf.AcroFields.SetListOption ( String  fieldName,
String[]  exportValues,
String[]  displayValues 
)

Sets the option list for fields of type list or combo. One of 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
fieldNamethe field name
exportValuesthe export values
displayValuesthe display values
Returns
true if the operation succeeded, false otherwise

◆ SetListSelection()

bool iTextSharp.text.pdf.AcroFields.SetListSelection ( String  name,
String[]  value 
)

Sets different values in a list selection. No appearance is generated yet; nor does the code check if multiple select is allowed.

Parameters
namethe name of the field
valuean array with values that need to be selected
Returns
true only if the field value was changed
Since
2.1.4

◆ SignatureCoversWholeDocument()

bool iTextSharp.text.pdf.AcroFields.SignatureCoversWholeDocument ( String  name)

Checks is the signature covers the entire document or just part of it.

Parameters
namethe signature field name
Returns
true if the signature covers the entire document, false otherwise

◆ SplitDAelements()

static Object [] iTextSharp.text.pdf.AcroFields.SplitDAelements ( String  da)
static

◆ VerifySignature()

PdfPKCS7 iTextSharp.text.pdf.AcroFields.VerifySignature ( String  name)

Verifies a signature. An example usage is:

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
namethe signature field name
Returns
a PdfPKCS7 class to continue the verification

Member Data Documentation

◆ DA_COLOR

const int iTextSharp.text.pdf.AcroFields.DA_COLOR = 2
static

◆ DA_FONT

const int iTextSharp.text.pdf.AcroFields.DA_FONT = 0
static

◆ DA_SIZE

const int iTextSharp.text.pdf.AcroFields.DA_SIZE = 1
static

◆ FIELD_TYPE_CHECKBOX

const int iTextSharp.text.pdf.AcroFields.FIELD_TYPE_CHECKBOX = 2
static

A field type.

◆ FIELD_TYPE_COMBO

const int iTextSharp.text.pdf.AcroFields.FIELD_TYPE_COMBO = 6
static

A field type.

◆ FIELD_TYPE_LIST

const int iTextSharp.text.pdf.AcroFields.FIELD_TYPE_LIST = 5
static

A field type.

◆ FIELD_TYPE_NONE

const int iTextSharp.text.pdf.AcroFields.FIELD_TYPE_NONE = 0
static

A field type invalid or not found.

◆ FIELD_TYPE_PUSHBUTTON

const int iTextSharp.text.pdf.AcroFields.FIELD_TYPE_PUSHBUTTON = 1
static

A field type.

◆ FIELD_TYPE_RADIOBUTTON

const int iTextSharp.text.pdf.AcroFields.FIELD_TYPE_RADIOBUTTON = 3
static

A field type.

◆ FIELD_TYPE_SIGNATURE

const int iTextSharp.text.pdf.AcroFields.FIELD_TYPE_SIGNATURE = 7
static

A field type.

◆ FIELD_TYPE_TEXT

const int iTextSharp.text.pdf.AcroFields.FIELD_TYPE_TEXT = 4
static

A field type.

Property Documentation

◆ FieldCache

Hashtable iTextSharp.text.pdf.AcroFields.FieldCache
getset

Sets a cache for field appearances. Parsing the existing PDF to create a new TextField is time expensive. For those tasks that repeatedly fill the same PDF with different field values the use of the cache has dramatic speed advantages. An example usage:

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
Hashtable cache = new Hashtable();// 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
fieldCachean HasMap that will carry the cached appearances

◆ Fields

Hashtable iTextSharp.text.pdf.AcroFields.Fields
get

Gets all the fields. The fields are keyed by the fully qualified field name and the value is an instance of AcroFields.Item.

Returns
all the fields

◆ GenerateAppearances

bool iTextSharp.text.pdf.AcroFields.GenerateAppearances
getset

Sets the option to generate appearances. Not generating apperances will speed-up form filling but the results can be unexpected in Acrobat. Don't use it unless your environment is well controlled. The default is true.

Parameters
generateAppearancesthe option to generate appearances

◆ SubstitutionFonts

ArrayList iTextSharp.text.pdf.AcroFields.SubstitutionFonts
getset

Sets a list of substitution fonts. The list is composed of 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
substitutionFontsthe list

◆ TotalRevisions

int iTextSharp.text.pdf.AcroFields.TotalRevisions
get

Gets the total number of revisions this document has.

Returns
the total number of revisions

◆ Xfa

XfaForm iTextSharp.text.pdf.AcroFields.Xfa
get

Gets the XFA form processor.

Returns
the XFA form processor

The documentation for this class was generated from the following file: