Nicklas Karlsson wrote: > Hi, > > I found an oldish posting saying that setField was not supported for > multi-select listboxes. Is this still the case? > > Is the workaround to check the field type, typecast correctly and do > some low level selections?
Modified: trunk/src/core/com/lowagie/text/pdf/AcroFields.java =================================================================== --- trunk/src/core/com/lowagie/text/pdf/AcroFields.java 2008-10-10 11:37:58 UTC (rev 3596) +++ trunk/src/core/com/lowagie/text/pdf/AcroFields.java 2008-10-24 13:36:41 UTC (rev 3597) @@ -1340,6 +1340,47 @@ return false; } + /** + * Sets different values in a list selection. + * No appearance is generated yet; nor does the code check if multiple select is allowed. + * @param name the name of the field + * @param value an array with values that need to be selected + * @return true only if the field value was changed + * @since 2.1.4 + */ + public boolean setListSelection(String name, String[] value) throws IOException, DocumentException { + Item item = (Item)fields.get(name); + if (item == null) + return false; + PdfName type = (PdfName)PdfReader.getPdfObject(((PdfDictionary)item.merged.get(0)).get(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)); + } + } + } + for (int idx = 0; idx < item.values.size(); ++idx) { + PdfDictionary valueDic = (PdfDictionary)item.values.get(idx); + valueDic.remove(PdfName.V); + valueDic.put(PdfName.I, array); + markUsed(valueDic); + PdfDictionary merged = (PdfDictionary)item.merged.get(idx); + merged.put(PdfName.I, array); + merged.remove(PdfName.V); + PdfDictionary widget = (PdfDictionary)item.widgets.get(idx); + widget.remove(PdfName.AP); + merged.remove(PdfName.AP); + markUsed(widget); + } + return true; + } + -- This answer is provided by 1T3XT BVBA http://www.1t3xt.com/ - http://www.1t3xt.info ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ iText-questions mailing list iText-questions@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://www.1t3xt.com/docs/book.php