Вот фрагмент кода:
Код: Выделить всё
PDAcroForm pdAcroForm = pdfDocument.getDocumentCatalog().getAcroForm();
JSONObject jsonData = new JSONObject(pdfdata);
String[] specialChars = {" ", "-", ".", "(", ")", "/", "*"};
String[] specialCharsReplaceWith = {"_", "_1_", "_2_", "_3_", "_4_", "_5_", "_6_"};
for (PDField pdField : pdAcroForm.getFields()) {
String fieldName = pdField.getFullyQualifiedName();
System.out.println("fieldName:" + fieldName);
for(int i = 0; i < specialChars.length; i++) {
fieldName = fieldName.trim().replace(specialChars[i], specialCharsReplaceWith[i]);
}
if(StringUtils.isNotEmpty(fieldName)) {
fieldName = fieldName.substring(0, 1).toLowerCase().concat(fieldName.substring(1));
}
if (jsonData.has(fieldName)) {
String value = jsonData.getString(fieldName);
pdField.setValue(value);
pdField.setReadOnly(true);
}
}
Источник: https://stackoverflow.com/questions/781 ... ava-7-code