/** * Use this method to adds a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param name The name of the JS Action in the name tree * @param code the JavaScript code */ public void addJavaScript(String name, String code) { addJavaScript(name, code, false); }
/** * Use this method to adds a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param code the JavaScript code */ public void addJavaScript(String code) { addJavaScript(code, false); } /**
/** * Use this method to adds a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param code the JavaScript code */ public void addJavaScript(String code) { addJavaScript(code, false); } /**
/** * Use this method to adds a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param name The name of the JS Action in the name tree * @param code the JavaScript code */ public void addJavaScript(String name, String code) { addJavaScript(name, code, false); }
/** * Use this method to adds a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param code the JavaScript code */ public void addJavaScript(String code) { addJavaScript(code, false); } /**
/** * Use this method to adds a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param name The name of the JS Action in the name tree * @param code the JavaScript code */ public void addJavaScript(String name, String code) { addJavaScript(name, code, false); }
/** * Use this method to add a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param code the JavaScript code * @param unicode select JavaScript unicode. Note that the internal * Acrobat JavaScript engine does not support unicode, * so this may or may not work for you */ public void addJavaScript(String code, boolean unicode) { addJavaScript(PdfAction.javaScript(code, this, unicode)); }
/** * Use this method to add a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param name The name of the JS Action in the name tree * @param code the JavaScript code * @param unicode select JavaScript unicode. Note that the internal * Acrobat JavaScript engine does not support unicode, * so this may or may not work for you */ public void addJavaScript(String name, String code, boolean unicode) { addJavaScript(name, PdfAction.javaScript(code, this, unicode)); }
/** * Use this method to add a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param code the JavaScript code * @param unicode select JavaScript unicode. Note that the internal * Acrobat JavaScript engine does not support unicode, * so this may or may not work for you */ public void addJavaScript(String code, boolean unicode) { addJavaScript(PdfAction.javaScript(code, this, unicode)); }
/** * Use this method to add a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param code the JavaScript code * @param unicode select JavaScript unicode. Note that the internal * Acrobat JavaScript engine does not support unicode, * so this may or may not work for you */ public void addJavaScript(String code, boolean unicode) { addJavaScript(PdfAction.javaScript(code, this, unicode)); }
/** * Use this method to add a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param name The name of the JS Action in the name tree * @param code the JavaScript code * @param unicode select JavaScript unicode. Note that the internal * Acrobat JavaScript engine does not support unicode, * so this may or may not work for you */ public void addJavaScript(String name, String code, boolean unicode) { addJavaScript(name, PdfAction.javaScript(code, this, unicode)); }
/** * Use this method to add a JavaScript action at the document level. * When the document opens, all this JavaScript runs. * @param name The name of the JS Action in the name tree * @param code the JavaScript code * @param unicode select JavaScript unicode. Note that the internal * Acrobat JavaScript engine does not support unicode, * so this may or may not work for you */ public void addJavaScript(String name, String code, boolean unicode) { addJavaScript(name, PdfAction.javaScript(code, this, unicode)); }
public static void main(String[] args) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("js.pdf")); document.open(); writer.addJavaScript("function makeNegative() { this.getField('value2').value = -(this.getField('value1').value); } "); Rectangle rect1 = new Rectangle(40, 740, 200, 756); TextField value = new TextField(writer, rect1, "value1"); value.setBorderColor(GrayColor.GRAYBLACK); value.setBorderWidth(0.5f); PdfFormField field = value.getTextField(); field.setAdditionalActions(PdfName.BL, PdfAction.javaScript("makeNegative();", writer)); writer.addAnnotation(field); Rectangle rect2 = new Rectangle(40, 710, 200, 726); TextField neg = new TextField(writer, rect2, "value2"); neg.setBorderColor(GrayColor.GRAYBLACK); neg.setBorderWidth(0.5f); writer.addAnnotation(neg.getTextField()); document.close(); }
pdfWriter.addJavaScript(pdfJavaScript);