public boolean renameField ( String oldName , String newName ) { int idx1 = oldName . lastIndexOf ( ' ' ) + 1 ; int idx2 = newName . lastIndexOf ( ' ' ) + 1 ; if ( idx1 != idx2 ) return false ; if ( ! oldName . substring ( 0 , idx1 ) . equals ( newName . substring ( 0 , idx2 ) ) ) return false ; if ( fields . containsKey ( newName ) ) return false ; Item item = ( Item ) fields . get ( oldName ) ; if ( item == null ) return false ; newName = newName . substring ( idx2 ) ; PdfString ss = new PdfString ( newName , PdfObject . TEXT_UNICODE ) ; item . writeToAll ( PdfName . T , ss , Item . WRITE_VALUE | Item . WRITE_MERGED ) ; item . markUsed ( this , Item . WRITE_VALUE ) ; fields . remove ( oldName ) ; fields . put ( newName , item ) ; return true ; }
Renames a field . Only the last part of the name can be renamed . For example if the original field is ab . cd . ef only the ef part can be renamed .