0
我正在嘗試將javascript驗證添加到現有的Acroform字段通過iText in java。到目前爲止,我已經編寫了下面的代碼,但沒有將操作分配給表單字段。有什麼我失蹤?向iText的pdf中現有的acroform字段添加javascript驗證
PdfReader reader = new PdfReader(uri);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
PdfWriter writer = stamper.getWriter();
AcroFields acroFields = reader.getAcroFields();
AcroFields.Item dateField = acroFields.getFieldItem("SignDateField");
PdfAction pdfAction = PdfAction.javaScript("app.alert('hello');", writer);
PdfDictionary widgetRefDict = (PdfDictionary) PdfReader.getPdfObject(dateField.getWidgetRef(0));
PdfDictionary actionDict = widgetRefDict.getAsDict(PdfName.AA);
if (actionDict == null) {
actionDict = new PdfDictionary();
}
actionDict.put(PdfName.V, pdfAction);
stamper.close();
reader.close();
這就是我所錯過的,它現在的作品。當action添加到actionDict後,這需要添加。謝謝! – dchar