|
![]() |
||||||||
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 PdfName[] |
buttonRemove
|
static int |
DA_COLOR
|
static int |
DA_FONT
|
static int |
DA_SIZE
|
private HashMap |
extensionFonts
|
private float |
extraMarginLeft
|
private float |
extraMarginTop
|
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 Map |
fieldCache
Holds value of property fieldCache. |
(package private) HashMap |
fields
|
private boolean |
generateAppearances
Holds value of property generateAppearances. |
private boolean |
lastWasString
|
private HashMap |
localFonts
|
(package private) PdfReader |
reader
|
private HashMap |
sigNames
|
private static HashMap |
stdFieldFontNames
|
private ArrayList |
substitutionFonts
|
private int |
topFirst
|
private int |
totalRevisions
Holds value of property totalRevisions. |
(package private) PdfWriter |
writer
|
private 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. |
(package private) void |
fill()
|
(package private) PdfAppearance |
getAppearance(PdfDictionary merged,
String[] values,
String fieldName)
|
(package private) 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. |
Map |
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. |
private 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. |
String[] |
getListSelection(String name)
Gets the field values of a Choice field. |
(package private) Color |
getMKColor(PdfArray ar)
|
PushbuttonField |
getNewPushbuttonFromField(String field)
Creates a new pushbutton from an existing field. |
PushbuttonField |
getNewPushbuttonFromField(String field,
int order)
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. |
(package private) boolean |
isInAP(PdfDictionary dic,
PdfName check)
|
private 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)
Removes a field from the document. |
boolean |
removeField(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(String oldName,
String newName)
Renames a field. |
boolean |
replacePushbuttonField(String field,
PdfFormField button)
Replaces the first field with a new pushbutton. |
boolean |
replacePushbuttonField(String field,
PdfFormField button,
int order)
Replaces the designated 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(Map fieldCache)
Sets a cache for field appearances. |
boolean |
setFieldProperty(String field,
String name,
int value,
int[] inst)
Sets a field property. |
boolean |
setFieldProperty(String field,
String name,
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 |
setListOption(String fieldName,
String[] exportValues,
String[] displayValues)
Sets the option list for fields of type list or combo. |
boolean |
setListSelection(String name,
String[] value)
Sets different values in a list selection. |
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)
|
private void |
updateByteRange(PdfPKCS7 pkcs7,
PdfDictionary v)
|
PdfPKCS7 |
verifySignature(String name)
Verifies a signature. |
PdfPKCS7 |
verifySignature(String name,
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
HashMap fields
private int topFirst
private HashMap sigNames
private boolean append
public static final int DA_FONT
public static final int DA_SIZE
public static final int DA_COLOR
private HashMap extensionFonts
private XfaForm xfa
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 HashMap localFonts
private float extraMarginLeft
private float extraMarginTop
private ArrayList substitutionFonts
private static final HashMap stdFieldFontNames
private int totalRevisions
private Map fieldCache
private static final PdfName[] buttonRemove
Constructor Detail |
---|
AcroFields(PdfReader reader, PdfWriter writer)
Method Detail |
---|
void fill()
public String[] getAppearanceStates(String fieldName)
fieldName
- the fully qualified field name
null
if the field does not existprivate String[] getListOption(String fieldName, int idx)
public String[] getListOptionExport(String fieldName)
null
.
fieldName
- the field name
public String[] getListOptionDisplay(String fieldName)
null
.
fieldName
- the field name
public boolean setListOption(String fieldName, String[] exportValues, String[] displayValues)
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();
fieldName
- the field nameexportValues
- the export valuesdisplayValues
- the display values
true
if the operation succeeded, false
otherwisepublic int getFieldType(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 writerpublic boolean renameField(String oldName, String newName)
oldName
- the old field namenewName
- the new field name
true
if the renaming was successful, false
otherwisepublic static Object[] splitDAelements(String da)
public void decodeGenericDictionary(PdfDictionary merged, BaseField tx) throws IOException, DocumentException
IOException
DocumentException
PdfAppearance getAppearance(PdfDictionary merged, String[] values, String fieldName) throws IOException, DocumentException
IOException
DocumentException
PdfAppearance getAppearance(PdfDictionary merged, String text, String fieldName) throws IOException, DocumentException
IOException
DocumentException
Color getMKColor(PdfArray ar)
public String getField(String name)
name
- the fully qualified field name
public String[] getListSelection(String name)
name
- the fully qualified field name
public boolean setFieldProperty(String field, String name, 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
otherwisepublic boolean setFieldProperty(String field, 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
otherwisepublic void mergeXfaData(Node n) throws IOException, DocumentException
n
- the top node of the data structure
IOException
- on error
DocumentException
- o errorpublic void setFields(FdfReader fdf) throws IOException, DocumentException
fdf
- the FDF form
IOException
- on error
DocumentException
- on errorpublic void setFields(XfdfReader xfdf) throws IOException, DocumentException
xfdf
- the XFDF form
IOException
- on error
DocumentException
- on errorpublic boolean regenerateField(String name) throws IOException, DocumentException
name
- the fully qualified field name or the partial name in the case of XFA forms
true
if the field was found and changed,
false
otherwise
IOException
- on error
DocumentException
- on errorpublic boolean setField(String name, String value) throws IOException, DocumentException
name
- the fully qualified field name or the partial name in the case of XFA formsvalue
- the field value
true
if the field was found and changed,
false
otherwise
IOException
- on error
DocumentException
- on errorpublic boolean setField(String name, String value, String display) throws IOException, DocumentException
name
- the fully qualified field name or the partial name in the case of XFA formsvalue
- the field valuedisplay
- the string that is used for the appearance. If null
the value
parameter will be used
true
if the field was found and changed,
false
otherwise
IOException
- on error
DocumentException
- on errorpublic boolean setListSelection(String name, String[] value) throws IOException, DocumentException
name
- the name of the fieldvalue
- an array with values that need to be selected
IOException
DocumentException
boolean isInAP(PdfDictionary dic, PdfName check)
public HashMap getFields()
AcroFields.Item
.
public AcroFields.Item getFieldItem(String name)
name
- the name of the field
null
if the field
does not existpublic String getTranslatedFieldName(String name)
name
- the name of the field
public float[] getFieldPositions(String name)
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.
name
- the field name
null
if field does not existprivate 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(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 otherwise
public boolean removeField(String name)
name
- the field name
true
if the field exists, false otherwise
public boolean isGenerateAppearances()
public void setGenerateAppearances(boolean generateAppearances)
true
.
generateAppearances
- the option to generate appearancespublic ArrayList getSignatureNames()
public ArrayList getBlankSignatureNames()
public PdfDictionary getSignatureDictionary(String name)
name
- the field name
null
if the field is not
a signaturepublic boolean signatureCoversWholeDocument(String name)
name
- the signature field name
true
if the signature covers the entire document,
false
otherwisepublic PdfPKCS7 verifySignature(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 verificationpublic PdfPKCS7 verifySignature(String name, 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 verificationprivate void updateByteRange(PdfPKCS7 pkcs7, PdfDictionary v)
private void markUsed(PdfObject obj)
public int getTotalRevisions()
public int getRevision(String field)
field
revision.
field
- the signature field name
public InputStream extractRevision(String field) throws IOException
field
- the signature field name
InputStream
covering the revision. Returns null
if
it's not a signature field
IOException
- on errorpublic Map getFieldCache()
public void setFieldCache(Map 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
- a Map that will carry the cached appearancespublic void setExtraMargin(float extraMarginLeft, float extraMarginTop)
extraMarginLeft
- the extra margin leftextraMarginTop
- the extra margin toppublic void addSubstitutionFont(BaseFont font)
font
- the fontpublic ArrayList getSubstitutionFonts()
BaseFont
and can be null
. The fonts in this list will be used if the original
font doesn't contain the needed glyphs.
public void setSubstitutionFonts(ArrayList substitutionFonts)
BaseFont
and can also be null
. The fonts in this list will be used if the original
font doesn't contain the needed glyphs.
substitutionFonts
- the listpublic XfaForm getXfa()
public PushbuttonField getNewPushbuttonFromField(String field)
replacePushbuttonField(String,PdfFormField)
.
field
- the field name that should be a pushbutton
null
if the field is not a pushbuttonpublic PushbuttonField getNewPushbuttonFromField(String field, int order)
replacePushbuttonField(String,PdfFormField,int)
.
field
- the field name that should be a pushbuttonorder
- the field order in fields with same name
null
if the field is not a pushbuttonpublic boolean replacePushbuttonField(String field, PdfFormField button)
getNewPushbuttonFromField(String)
from the same document or it can be a
generic PdfFormField of the type pushbutton.
field
- the field namebutton
- the PdfFormField
representing the pushbutton
true
if the field was replaced, false
if the field
was not a pushbuttonpublic boolean replacePushbuttonField(String field, PdfFormField button, int order)
getNewPushbuttonFromField(String,int)
from the same document or it can be a
generic PdfFormField of the type pushbutton.
field
- the field namebutton
- the PdfFormField
representing the pushbuttonorder
- the field order in fields with same name
true
if the field was replaced, false
if the field
was not a pushbutton
|
Hosted by Hostbasket | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |