Map acroFieldMap = (Map)context.get("acroFieldMap");
ByteBuffer byteBuffer = getInputByteBuffer(context, delegator);
PdfReader r = new PdfReader(byteBuffer.array());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper s = new PdfStamper(r, baos);
AcroFields fs = s.getAcroFields();
Map map = fs.getFields();
s.setFormFlattening(true);
// Debug code to get the values for setting TDP
// String[] sa = fs.getAppearanceStates("TDP");
// for (int i=0;i<sa.length;i++)
// Debug.log("Appearance="+sa[i]);
Iterator iter = map.keySet().iterator();
while (iter.hasNext()) {
String fieldName=(String)iter.next();
String fieldValue = fs.getField(fieldName);
Object obj = acroFieldMap.get(fieldName);
if (obj instanceof Date) {
Date d=(Date)obj;
fieldValue=UtilDateTime.toDateString(d);
} else if (obj instanceof Long) {
Long lg=(Long)obj;
fieldValue=lg.toString();
} else if (obj instanceof Integer) {
Integer ii=(Integer)obj;
fieldValue=ii.toString();
} else {
fieldValue=(String)obj;
}
if (UtilValidate.isNotEmpty(fieldValue))
fs.setField(fieldName, fieldValue);
}
s.close();
baos.close();
ByteBuffer outByteBuffer = ByteBuffer.wrap(baos.toByteArray());