I'm trying to batch rename fields in PDFs created with Designer 7 but I get garbled field names. The fields are named like this by default: FormName[0].PageName[0].User_entered_field_name[0]. I'm trying to remove the last indexing construct ([0]) but I end up with field names having some asian characters: FormName[0].PageName[0].aLotOfAsianCharacters. This seems like a character set problem. Acrobat 7 shows me the asian characters but the Eclipse debugger shows correct names if I open the newly saved form again using iText. Any helpful ideas?
I do this by first removing the XFA data and then using the AcroFields object:
PdfReader reader = new PdfReader("my.pdf");
final PdfDictionary acro =
(PdfDictionary) PdfReader.getPdfObject
(reader.getCatalog().get(PdfName.ACROFORM));
acro.remove(new PdfName("XFA"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfStamper stamp = new PdfStamper(reader, baos);
AcroFields form =
stamp.getAcroFields();
List fnames = new ArrayList(form.getFields().keySet());
Collections.sort(fnames);
Iterator nIter = fnames.iterator();
while (nIter.hasNext()) {
String fname = (String)nIter.next();
String newName = null;
newName = fname.substring(0, fname.lastIndexOf('['));
form.renameField(fname, newName);
}
FileOutputStream fos = new FileOutputStream("my_fixed.pdf");
stamp.close();
fos.write(baos.toByteArray());
fos.close();
Should I even be doing this? Working on a form that is originally XFA by removing the XFA data and accessing the acroform? The plan is to have people fill out these modified forms and submit the FDF to a servlet for archival after which the form fields will be repopulated on demand using iText to setFields using the FDF.
Thanks!
- [iText-questions] Field renaming trouble with a form create... Mika Majakorpi
- RE: [iText-questions] Field renaming trouble with a fo... Paulo Soares
- Re: [iText-questions] Field renaming trouble with ... Mika Majakorpi
