public class PdfAcroForm extends PdfObjectWrapper<PdfDictionary>
Modifier and Type | Field and Description |
---|---|
static int |
APPEND_ONLY
To be used with setSignatureFlags(int) .
|
protected PdfDocument |
document
The PdfDocument to which the PdfAcroForm belongs.
|
protected Map<String,PdfFormField> |
fields
A map of field names and their associated form field objects.
|
protected boolean |
generateAppearance
Keeps track of whether or not appearances must be generated by the form fields themselves, or by the PDF viewer application.
|
static int |
SIGNATURE_EXIST
To be used with setSignatureFlags(int) .
|
Modifier and Type | Method and Description |
---|---|
void |
addField(PdfFormField field)
This method adds the field to the last page in the document.
|
void |
addField(PdfFormField field, PdfPage page)
This method adds the field to a specific page.
|
void |
addFieldAppearanceToPage(PdfFormField field, PdfPage page)
This method merges field with its annotation and place it on the given page.
|
PdfFormField |
copyField(String name)
Creates an in-memory copy of a PdfFormField .
|
void |
flattenFields()
Flattens interactive form field s in the document.
|
static PdfAcroForm |
getAcroForm(PdfDocument document, boolean createIfNotExist)
Retrieves AcroForm from the document.
|
PdfArray |
getCalculationOrder()
Gets the CO array property on the AcroForm.
|
PdfString |
getDefaultAppearance()
Gets the DA String property on the AcroForm.
|
PdfNumber |
getDefaultJustification()
Gets the Q integer property on the AcroForm.
|
PdfDictionary |
getDefaultResources()
Gets the DR dictionary property on the AcroForm.
|
PdfFormField |
getField(String fieldName)
Gets a form field by its name.
|
protected PdfArray |
getFields()
Gets all AcroForm fields in the document.
|
Map<String,PdfFormField> |
getFormFields()
Gets the form field s as a Map .
|
PdfBoolean |
getNeedAppearances()
Gets the NeedAppearances boolean property on the AcroForm.
|
PdfDocument |
getPdfDocument()
Gets the PdfDocument this PdfAcroForm belongs to.
|
int |
getSignatureFlags()
Gets the SigFlags integer property on the AcroForm.
|
XfaForm |
getXfaForm()
Gets the XfaForm atribute.
|
PdfObject |
getXFAResource()
Gets the XFA property on the AcroForm.
|
boolean |
hasXfaForm()
Determines whether the AcroForm contains XFA data.
|
boolean |
isGenerateAppearance()
Gets the attribute generateAppearance, which tells flattenFields() to generate an appearance Stream for all form field s that don't have one.
|
protected boolean |
isWrappedObjectMustBeIndirect()
Defines if the object behind this wrapper must be an indirect object in the resultant document.
|
void |
partialFormFlattening(String fieldName)
Adds a form field , identified by name, to the list of fields to be flattened.
|
PdfAcroForm |
put(PdfName key, PdfObject value) |
void |
release()
Releases underlying pdf object and other pdf entities used by wrapper.
|
boolean |
removeField(String fieldName)
Tries to remove the form field with the specified name from the document.
|
void |
removeXfaForm()
Removes the XFA stream from the document.
|
void |
renameField(String oldName, String newName)
Changes the identifier of a form field .
|
void |
replaceField(String name, PdfFormField field)
Replaces the PdfFormField of a certain name with another PdfFormField .
|
PdfAcroForm |
setCalculationOrder(PdfArray calculationOrder)
Sets the CO array property on the AcroForm.
|
PdfAcroForm |
setDefaultAppearance(String appearance)
Sets the DA String property on the AcroForm.
|
PdfAcroForm |
setDefaultJustification(int justification)
Sets the Q integer property on the AcroForm.
|
PdfAcroForm |
setDefaultResources(PdfDictionary defaultResources)
Sets the DR dictionary property on the AcroForm.
|
void |
setGenerateAppearance(boolean generateAppearance)
Sets the attribute generateAppearance, which tells flattenFields() to generate an appearance Stream for all form field s that don't have one.
|
PdfAcroForm |
setNeedAppearances(boolean needAppearances)
Sets the NeedAppearances boolean property on the AcroForm.
|
PdfAcroForm |
setSignatureFlag(int sigFlag)
Changes the SigFlags integer property on the AcroForm.
|
PdfAcroForm |
setSignatureFlags(int sigFlags)
Sets the SigFlags integer property on the AcroForm.
|
PdfAcroForm |
setXFAResource(PdfArray xfaResource)
Sets the XFA property on the AcroForm.
|
PdfAcroForm |
setXFAResource(PdfStream xfaResource)
Sets the XFA property on the AcroForm.
|
ensureObjectIsAddedToDocument, ensureUnderlyingObjectHasIndirectReference, flush, getPdfObject, isFlushed, makeIndirect, makeIndirect, markObjectAsIndirect, setForbidRelease, setModified, setPdfObject, unsetForbidRelease
public static final int SIGNATURE_EXIST
setSignatureFlags(int)
.
If set, the document contains at least one signature field. This flag allows a conforming reader to enable user interface items (such as menu items or pushbuttons) related to signature processing without having to scan the entire document for the presence of signature fields. (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
public static final int APPEND_ONLY
setSignatureFlags(int)
.
If set, the document contains signatures that may be invalidated if the file is saved (written) in a way that alters its previous contents, as opposed to an incremental update. Merely updating the file by appending new information to the end of the previous version is safe. Conforming readers may use this flag to inform a user requesting a full save that signatures will be invalidated and require explicit confirmation before continuing with the operation. (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
protected boolean generateAppearance
true
.
protected Map<String,PdfFormField> fields
form field
objects.
protected PdfDocument document
public static PdfAcroForm getAcroForm(PdfDocument document, boolean createIfNotExist)
document
- the document to retrieve the PdfAcroForm
from
createIfNotExist
- when true
, this method will create a PdfAcroForm
if none exists for this document
document
's AcroForm, or a new one
public void addField(PdfFormField field)
field
- the PdfFormField
to be added to the form
public void addField(PdfFormField field, PdfPage page)
field
- the PdfFormField
to be added to the form
page
- the PdfPage
on which to add the field
public void addFieldAppearanceToPage(PdfFormField field, PdfPage page)
field
- the PdfFormField
to be added to the form
page
- the PdfPage
on which to add the field
public Map<String,PdfFormField> getFormFields()
form field
s as a Map
.
form field
objects
public PdfDocument getPdfDocument()
PdfDocument
this PdfAcroForm
belongs to.
public PdfAcroForm setNeedAppearances(boolean needAppearances)
NeedAppearances
boolean property on the AcroForm. NeedAppearances has been deprecated in PDF 2.0.
NeedAppearances is a flag specifying whether to construct appearance streams and appearance dictionaries for all widget annotations in the document. (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
needAppearances
- a boolean. Default value is false
public PdfBoolean getNeedAppearances()
NeedAppearances
boolean property on the AcroForm. NeedAppearances has been deprecated in PDF 2.0.
NeedAppearances is a flag specifying whether to construct appearance streams and appearance dictionaries for all widget annotations in the document. (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
NeedAppearances
property as a PdfBoolean
. Default value is false
public PdfAcroForm setSignatureFlags(int sigFlags)
SigFlags
integer property on the AcroForm.
SigFlags is a set of flags specifying various document-level characteristics related to signature fields. (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
sigFlags
- an integer. Use SIGNATURE_EXIST
and/or APPEND_ONLY
. Use bitwise OR operator to combine these values. Default value is 0
public PdfAcroForm setSignatureFlag(int sigFlag)
SigFlags
integer property on the AcroForm. This method allows only to add flags, not to remove them.
SigFlags is a set of flags specifying various document-level characteristics related to signature fields. (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
sigFlag
- an integer. Use SIGNATURE_EXIST
and/or APPEND_ONLY
. Use bitwise OR operator to combine these values. Default is 0
public int getSignatureFlags()
SigFlags
integer property on the AcroForm.
SigFlags is a set of flags specifying various document-level characteristics related to signature fields (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
SigFlags
.
public PdfAcroForm setCalculationOrder(PdfArray calculationOrder)
CO
array property on the AcroForm.
CO
, Calculation Order, is an array of indirect references to field dictionaries with calculation actions, defining the calculation order in which their values will be recalculated when the value of any field changes (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
calculationOrder
- an array of indirect references
public PdfArray getCalculationOrder()
CO
array property on the AcroForm.
CO
, Calculation Order, is an array of indirect references to field dictionaries with calculation actions, defining the calculation order in which their values will be recalculated when the value of any field changes (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
public PdfAcroForm setDefaultResources(PdfDictionary defaultResources)
DR
dictionary property on the AcroForm.
DR
is a resource dictionary containing default resources (such as fonts, patterns, or colour spaces) that shall be used by form field appearance streams. At a minimum, this dictionary shall contain a Font entry specifying the resource name and font dictionary of the default font for displaying text. (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
defaultResources
- a resource dictionary
public PdfDictionary getDefaultResources()
DR
dictionary property on the AcroForm.
DR
is a resource dictionary containing default resources (such as fonts, patterns, or colour spaces) that shall be used by form field appearance streams. At a minimum, this dictionary shall contain a Font entry specifying the resource name and font dictionary of the default font for displaying text. (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
public PdfAcroForm setDefaultAppearance(String appearance)
DA
String property on the AcroForm.
DA
attribute of variable text form field
s.
appearance
- a String containing a sequence of valid PDF syntax
PdfFormField.setDefaultAppearance(java.lang.String)
public PdfString getDefaultAppearance()
DA
String property on the AcroForm.
DA
attribute of variable text form field
s.
String
public PdfAcroForm setDefaultJustification(int justification)
Q
integer property on the AcroForm.
Q
attribute of variable text form field
s.
justification
- an integer representing a justification value
PdfFormField.setJustification(int)
public PdfNumber getDefaultJustification()
Q
integer property on the AcroForm.
Q
attribute of variable text form field
s.
PdfFormField.getJustification()
public PdfAcroForm setXFAResource(PdfStream xfaResource)
XFA
property on the AcroForm.
XFA
can either be a PdfStream
or a PdfArray
. Its contents must be valid XFA.
xfaResource
- a stream containing the XDP
public PdfAcroForm setXFAResource(PdfArray xfaResource)
XFA
property on the AcroForm.
XFA
can either be a PdfStream
or a PdfArray
. Its contents must be valid XFA.
xfaResource
- an array of text string and stream pairs representing the individual packets comprising the XML Data Package. (ISO 32000-1, section 12.7.2 "Interactive Form Dictionary")
public PdfObject getXFAResource()
XFA
property on the AcroForm.
public PdfFormField getField(String fieldName)
form field
by its name.
fieldName
- the name of the form field
to retrieve
form field
, or null
if it isn't present
public boolean isGenerateAppearance()
flattenFields()
to generate an appearance Stream for all form field
s that don't have one.
public void setGenerateAppearance(boolean generateAppearance)
flattenFields()
to generate an appearance Stream for all form field
s that don't have one.
Not generating appearances will speed up form flattening but the results can be unexpected in Acrobat. Don't use it unless your environment is well controlled. The default is true
.
If generateAppearance is set to true
, then NeedAppearances
is set to false
. This does not apply vice versa.
generateAppearance
- a boolean
public void flattenFields()
form field
s in the document. If no fields have been explicitly included via {#link #partialFormFlattening}, then all fields are flattened. Otherwise only the included fields are flattened.
public boolean removeField(String fieldName)
form field
with the specified name from the document.
fieldName
- the name of the form field
to remove
public void partialFormFlattening(String fieldName)
form field
, identified by name, to the list of fields to be flattened. Does not perform a flattening operation in itself.
fieldName
- the name of the form field
to be flattened
public void renameField(String oldName, String newName)
form field
.
oldName
- the current name of the field
newName
- the new name of the field. Must not be used currently.
public PdfFormField copyField(String name)
PdfFormField
. This new field is not added to the document.
name
- the name of the form field
to be copied
PdfFormField
public void replaceField(String name, PdfFormField field)
PdfFormField
of a certain name with another PdfFormField
.
name
- the name of the form field
to be replaced
field
- the new PdfFormField
protected PdfArray getFields()
PdfArray
of field dictionaries
protected boolean isWrappedObjectMustBeIndirect()
PdfObjectWrapper
isWrappedObjectMustBeIndirect
in class PdfObjectWrapper<PdfDictionary>
public boolean hasXfaForm()
public void removeXfaForm()
public PdfAcroForm put(PdfName key, PdfObject value)
public void release()
PdfObject.release()
if the wrapper is used.
Copyright © 1998–2018 iText Group NV. All rights reserved.