I've tried different things, I've searched the book, but I still don't
know how to add javascript to a field (accessed by its name) from an
existing pdf. I've tried the following code and it works ok, but I
need to access a field by its name, and not by its number:

/***********************************************************/

PdfDictionary aa = new PdfDictionary();
PdfReader reader = new PdfReader("autoconsumo_new.pdf");

PdfDictionary js3 = new PdfDictionary();
js3.put(PdfName.S, PdfName.JAVASCRIPT);
js3.put(PdfName.JS, new PdfString("if ( event.fieldFull ||
event.willCommit ) " +
                  "this.getField(\"F02VNIF_____\").setFocus();"));
aa.put(PdfName.K, js3);


PdfDictionary catalog = reader.getCatalog();
PdfDictionary form =
(PdfDictionary)PdfReader.getPdfObject(catalog.get(PdfName.ACROFORM));
PdfArray fields = (PdfArray)form.get(PdfName.FIELDS);
PdfDictionary field =
(PdfDictionary)PdfReader.getPdfObject((PdfObject)fields.getArrayList().get(0));
/*I want to change that get(0) for something like get(name) */
field.put(PdfName.AA, aa);                      
/******************************************************************/


Which change do I need to do?
It's very important.
Lots of thanks,
Jesús.

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://itext.ugent.be/itext-in-action/

Reply via email to