public boolean setListSelection ( String name , String [ ] value ) throws IOException , DocumentException { Item item = getFieldItem ( name ) ; if ( item == null ) return false ; PdfName type = item . getMerged ( 0 ) . getAsName ( PdfName . FT ) ; if ( ! PdfName . CH . equals ( type ) ) { return false ; } String [ ] options = getListOptionExport ( name ) ; PdfArray array = new PdfArray ( ) ; for ( int i = 0 ; i < value . length ; i ++ ) { for ( int j = 0 ; j < options . length ; j ++ ) { if ( options [ j ] . equals ( value [ i ] ) ) { array . add ( new PdfNumber ( j ) ) ; } } } item . writeToAll ( PdfName . I , array , Item . WRITE_MERGED | Item . WRITE_VALUE ) ; item . writeToAll ( PdfName . V , null , Item . WRITE_MERGED | Item . WRITE_VALUE ) ; item . writeToAll ( PdfName . AP , null , Item . WRITE_MERGED | Item . WRITE_WIDGET ) ; item . markUsed ( this , Item . WRITE_VALUE | Item . WRITE_WIDGET ) ; return true ; }
Sets different values in a list selection . No appearance is generated yet ; nor does the code check if multiple select is allowed .