Acount=AfieldCount[page];
Fforms = new FormObject[FfieldCount];
FormObject[] xfaFormList = null;
Aforms = new FormObject[Acount];
FormObject formObject;
String objRef;
int i, count;
//scan list for all relevant values and add to array if valid
//0 = xfa, 1 = forms, 2 = annots
int decodeToForm = 2;
for(int forms=0;forms<decodeToForm;forms++){
i=0;
if(forms==0){
count=0;
if(fieldList!=null){
fieldList.resetToStart();
count=fieldList.getTokenCount()-1;
}
}else{
if(annotList!=null && annotList.length>page && annotList[page]!=null){
annotList[page].resetToStart();
//create lookup and array for values to set order correctly in HTML
if(formFactory.getType()==FormFactory.HTML){
Map annotOrder=new HashMap();
int count2=annotList[page].getTokenCount();
String val;
for(int ii=0;ii<count2;ii++){
val=annotList[page].getNextValueAsString(true);
annotOrder.put(val,String.valueOf(ii+1));
}
formFactory.setAnnotOrder(annotOrder);
}
annotList[page].resetToStart();
}
count=Acount-1;
}
for (int fieldNum =count; fieldNum >-1; fieldNum--) {
objRef=null;
if(forms==0){
if(fieldList!=null)
objRef=fieldList.getNextValueAsString(true);
}else{
if(annotList.length>page && annotList[page]!=null)
objRef=annotList[page].getNextValueAsString(true);
}
if(objRef==null || (objRef!=null && (formsProcessed.get(objRef)!=null || objRef.length()==0)))
continue;
formObject= (FormObject) cachedObjs.get(objRef);
if(formObject==null){
formObject = new FormObject(objRef,formsActionHandler,pageData.getRotation(page-1));
//formObject.setPDFRef((String)objRef);
if(objRef.charAt(objRef.length()-1)=='R'){
currentPdfFile.readObject(formObject);
}else{
//changed by Mark as cover <<>> as well as 1 0 R
formObject.setStatus(PdfObject.UNDECODED_REF);
formObject.setUnresolvedData(StringUtils.toBytes(objRef),id);
currentPdfFile.checkResolved(formObject);
}
cachedObjs.put(objRef,formObject);
}
byte[][] kids=formObject.getKeyArray(PdfDictionary.Kids);
if(kids!=null) //not 'proper' kids so process here
i = flattenKids(page, debugNew, formsProcessed, formObject, i, forms);
else
i = processFormObject(page, debugNew, formsProcessed, formObject, objRef, i, forms);
}
}
/**
* process XFA FORMS and add in values
*/
if (hasXFA && fDecoder.hasXFADataSet()) {
currentItems.clear();
//needs reversing
///Users/markee/Downloads/write_test16_pdfform.pdf
int size=Fforms.length;
FormObject[] tmp=new FormObject[size];
for(int ii=0;ii<size;ii++)
tmp[ii]=Fforms[size-ii-1];
xfaFormList = ((XFAFormStream) fDecoder).createAppearanceString(tmp);
compData.storeXFARefToForm(((XFAFormStream)fDecoder).getRefToFormArray());
}
List unsortedForms= new ArrayList();
compData.setUnsortedListForPage(page,unsortedForms);
//XFA, FDF FORMS then ANNOTS
int readToForm = 3;
for(int forms=0;forms<readToForm;forms++){
count=0;
if(forms==0){
if(xfaFormList!=null)
count=xfaFormList.length;
}else if(forms==1){
//store current order of forms for printing
for (FormObject Fform : Fforms) {
if (Fform != null)
unsortedForms.add(Fform.getObjectRefAsString());
}
//sort forms into size order for display
Fforms = FormUtils.sortGroupLargestFirst(Fforms);
count=Fforms.length;
}else{
//store current order of forms for printing
for (FormObject Aform : Aforms) {
if (Aform != null)
unsortedForms.add(Aform.getObjectRefAsString());
}
//sort forms into size order for display
Aforms = FormUtils.sortGroupLargestFirst(Aforms);
count=Aforms.length;
}
for (int k = 0; k <count; k++) {
if(forms==0)
formObject = xfaFormList[k];
else if(forms==1)
formObject = Fforms[k];
else
formObject =Aforms[k];
if (formObject != null && (formsCreated.get(formObject.getObjectRefAsString())==null) && page==formObject.getPageNumber()){// && !formObject.getObjectRefAsString().equals("216 0 R")){
//String OEPROPval=formObject.getTextStreamValue(PdfDictionary.EOPROPtype);
//NOTE: if this custom form needs redrawing more change ReadOnlyTextIcon.MAXSCALEFACTOR to 1;
if(formsRasterizedForDisplay() && current!=null){// || OEPROPval!=null){
//rasterize any flattened PDF forms here
try {
current.drawFlattenedForm(formObject);
}catch( PdfException e ){
e.printStackTrace();
}
}else {
createField(formObject, compData.getNextFreeField()); //now we turn the data into a Swing component
//set the raw data here so that the field names are the fully qualified names
compData.storeRawData(formObject); //store data so user can access
formsCreated.put(formObject.getObjectRefAsString(), "x");
}
}
}
}