List of usage examples for com.itextpdf.text Utilities readFileToString
public static String readFileToString(final File file) throws IOException
From source file:com.mycompany.mavenproject1.SubmitForm.java
public void extractFromPdf(String src, String dest) throws DocumentException, IOException { PdfReader reader = new PdfReader(src); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest)); PushbuttonField button = new PushbuttonField(stamper.getWriter(), new Rectangle(36, 700, 112, 730), "get"); //stamper.getWriter().addJavaScript(Utilities.readFileToString(RESOURCE)); button.setText("SAVE My INFO"); button.setBackgroundColor(new GrayColor(0.7f)); button.setVisibility(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT); PdfFormField submit = button.getField(); /*//w ww . jav a2 s.com button.setBackgroundColor(new GrayColor(0.7f)); button.setVisibility(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT); */ //PdfFormField pull_data = upload_info.getField(); // pull_data.setAction(PdfAction.javaScript(Utilities.readFileToString(submit_button_script), stamper.getWriter())); stamper.getWriter().addJavaScript(Utilities.readFileToString(checkbox)); stamper.getWriter().addJavaScript(Utilities.readFileToString(upload_info)); //PushbuttonField submitButton=stamper.getAcroFields().getNewPushbuttonFromField("UseSavedInfo"); //PdfFormField field=submitButton.getField(); //field.setAction(PdfAction.javaScript("app.alert('hello')" ,stamper.getWriter())); /* PushbuttonField useMySavedInfo = new PushbuttonField( stamper.getWriter(), new Rectangle(36, 1000, 559, 806), "MySavedInfo" ); useMySavedInfo.setText("Upload info"); useMySavedInfo.setBackgroundColor(new GrayColor(0.7f)); useMySavedInfo.setVisibility(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT); PdfFormField extractInfo=useMySavedInfo.getField(); */ // extractInfo.setAction(PdfAction.javaScript("alert('hello')", stamper.getWriter())); // extractInfo.setAction(PdfAction.); //stamper. /* AcroFields fields = stamper.getAcroFields(); PushbuttonField submitButton=fields.getNewPushbuttonFromField("SubmitForm"); */ //System.out.println(submitButton.getAppearance().getHeight()); //System.out.println(submitButton.getAppearance().getWidth()); //System.out.println(submitButton.getAppearance()); //submitButton //submitButton.getField().get //submitButton.getWriter().setAdditionalAction(, PdfAction.javaScript("app.alert('os')",stamper.getWriter())); //submitButton.getWriter().setAdditionalAction(PdfName., action); //PdfFormField sb=submitButton.getField(); //sb.setAction(PdfAction.javaScript("app.alert('test')", stamper.getWriter())); // sumbitInfo.setAction(PdfAction.javaScript("app.alert('test')", stamper.getWriter())); //submit.setAction(PdfAction.javaScript("app.alert('test')", stamper.getWriter())); //PushbuttonField useInfo = fields.getNewPushbuttonFromField("UseSavedInfo"); //PdfAnnotation getInfo=useInfo.getField(); //getInfo.setAction(PdfAction.javaScript("app.alert('action!')", stamper.getWriter())); // ffield.SetAdditionalActions(PdfName.E, PdfAction("app.alert('action!')")); AcroFields fields = stamper.getAcroFields(); // PushbuttonField saveInfo = fields.getNewPushbuttonFromField("SaveInfo"); // PdfFormField fd=saveInfo.getField(); //fd.setAction(PdfAction.createSubmitForm("http://127.0.0.1/index.php",null,PdfAction.SUBMIT_HTML_FORMAT)); //PdfAppearance pa =saveInfo.getAppearance(); // pa.setAction(PdfAction.createSubmitForm("http://127.0.0.1/index.php",null,PdfAction.SUBMIT_HTML_FORMAT), 0, 0, 0, 0); Set<String> fldNames = fields.getFields().keySet(); //AcroFields fields = stamper.getAcroFields(); for (String fldName : fldNames) { System.out.println(fldName + ": " + fields.getField(fldName)); } //submit.setAdditionalAction(PdfAction.javaScript(Utilities.readFileToString(submit_button_script), stamper.getWriter())); //http://www.mycrewid.com/Alexander/index.php //submit.setAction(PdfAction.createSubmitForm( // "http://127.0.0.1/index.php", null, // PdfAction.SUBMIT_HTML_FORMAT)); submit.setAction( PdfAction.javaScript(Utilities.readFileToString(submit_button_script), stamper.getWriter())); stamper.addAnnotation(submit, 1); stamper.close(); //PdfAction.javaScript("this.getField('FirstName').value=util.printd(\"dd mmmm yyyy\",new Date())",stamper.getWriter()); //stamper.addAnnotation(submitButton, 1); //stamper.addAnnotation(sb,1); // submit.setAdditionalActions(PdfName.E, PdfAction.javaScript(Utilities.readFileToString(submit_button_script),stamper.getWriter())); }