List of usage examples for com.itextpdf.text.pdf PdfAction SUBMIT_HTML_FORMAT
int SUBMIT_HTML_FORMAT
To view the source code for com.itextpdf.text.pdf PdfAction SUBMIT_HTML_FORMAT.
Click Source Link
From source file:bd.gov.forms.web.FormBuilder.java
License:Open Source License
@RequestMapping(value = "/pdfExport", method = RequestMethod.GET) public String pdfExport(@RequestParam(value = "formId", required = true) String formId, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "colName", required = false) String colName, @RequestParam(value = "colVal", required = false) String colVal, @RequestParam(value = "sortCol", required = false) String sortCol, @RequestParam(value = "sortDir", required = false) String sortDir, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws IOException { Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); // step 2/*from www .j a v a 2 s.c om*/ try { response.reset(); response.setContentType("application/pdf"); response.setHeader("Content-disposition", "inline; filename=test.pdf"); response.setHeader("Cache-Control", "no-cache"); response.setDateHeader("Expires", 0); response.setHeader("Pragma", "No-cache"); PdfWriter writer = PdfWriter.getInstance(document, baos); // step 3 document.open(); Form form = null; //System.out.println("The form id is 1:"+formId); if (formId != null) { form = formDao.getFormWithFields(formId); } if (form != null) { if (form.getStatus() != 2) {//2-active, 3-deactive model.put("doneMessage", "msg.access.denied"); model.put("doneMsgType", "failed"); return "redirect:done.htm"; } initForm(form); } List<Field> fieldList = form.getFields(); if (fieldList.isEmpty()) { System.out.println("The list size is zero"); } PdfPCell space; space = new PdfPCell(); space.setBorder(Rectangle.NO_BORDER); space.setColspan(2); space.setFixedHeight(8); PdfPTable table = new PdfPTable(2); PdfPCell cell; //PdfPCell cell; table.setWidths(new int[] { 1, 2 }); int i = 0; for (Field f : fieldList) { if ("text".equals(f.getType())) { table.addCell(f.getLabel()); cell = new PdfPCell(); cell.setCellEvent(new TextFields(1, i)); table.addCell(cell); } else if ("textarea".equals(f.getType())) { table.addCell(f.getLabel()); cell = new PdfPCell(); cell.setCellEvent(new TextFields(1, i)); cell.setFixedHeight(60); table.addCell(cell); } else if ("select".equals(f.getType())) { table.addCell(f.getType()); cell = new PdfPCell(); cell.setCellEvent(new ChoiceFields(3, f.getList().toArray())); table.addCell(cell); //table.addCell(space); System.out.println("ajsdhd"); } i++; } /* for(Field f : fieldList) { if( "radio".equals(f.getType()) ) { System.out.println("List "+f.getList()+" Oppt"+f.getOptions()+ " df"+f.getColName()); writer = PdfWriter.getInstance(document, new FileOutputStream("TextFieldForm.pdf")); //writer.addJavaScript(Utilities.readFileToString("")); // add the radio buttons PdfContentByte canvas = writer.getDirectContent(); Font font = new Font(FontFamily.HELVETICA, 14); Rectangle rect; PdfFormField field; PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true); radiogroup.setFieldName("language"); RadioCheckField radio; for (int i = 0; i < 2; i++) { rect = new Rectangle(40, 806 - i * 40, 60, 788 - i * 40); radio = new RadioCheckField(writer, rect, null, f.getLabel()); radio.setBorderColor(GrayColor.GRAYBLACK); radio.setBackgroundColor(GrayColor.GRAYWHITE); radio.setCheckType(RadioCheckField.TYPE_CIRCLE); field = radio.getRadioField(); radiogroup.addKid(field); writer.addAnnotation(field); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(f.getLabel(), font), 70, 790 - i * 40, 0); } //table.addCell(f.getLabel()); //cell = new PdfPCell(); //document.add(radiogroup); //writer.addAnnotation(radiogroup); } } */ // Add submit button PushbuttonField submitBtn = new PushbuttonField(writer, new Rectangle(400, 700, 370, 670), "submitPOST"); //submitBtn.setBackgroundColor(Color.GRAY); submitBtn.setBorderStyle(PdfBorderDictionary.STYLE_BEVELED); submitBtn.setText("Submit"); submitBtn.setOptions(PushbuttonField.VISIBLE_BUT_DOES_NOT_PRINT); PdfFormField submitField = submitBtn.getField(); submitField.setAction( PdfAction.createSubmitForm("http://localhost:8084/GovForm-07-02/formBuilder/pdfresponse.htm", null, PdfAction.SUBMIT_HTML_FORMAT)); writer.addAnnotation(submitField); document.add(table); System.out.println("Pdf creation successful"); document.close(); ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); } catch (Exception ex) { System.out.println("Could not print reasone::" + ex.toString()); } //////////////////////////////////////// email part//////////////////////////// //email functionalities // Recipient's email ID needs to be mentioned. String to = "tanviranik@gmail.com"; // Sender's email ID needs to be mentioned String from = "tanvir_cse@yahoo.com"; // Assuming you are sending email from localhost String host = "localhost"; // Get system properties Properties properties = System.getProperties(); // Setup mail server properties.setProperty("mail.smtp.host", host); // Get the default Session object. Session session = Session.getDefaultInstance(properties); try { // Create a default MimeMessage object. MimeMessage message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(from)); // Set To: header field of the header. message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); // Set Subject: header field message.setSubject("This is the Subject Line!"); // Now set the actual message message.setText("This is actual message"); // Send message Transport.send(message); System.out.println("Sent message successfully...."); } catch (MessagingException mex) { mex.printStackTrace(); } //////////////////////////////////////// email part//////////////////////////// return null; }
From source file:com.vectorprint.report.itext.style.stylers.AbstractFieldStyler.java
License:Open Source License
@Override protected void draw(PdfContentByte canvas, float x, float y, float width, float height, String genericTag) throws VectorPrintException { Rectangle box = new Rectangle(x, y, x + width, y - height); PdfFormField pff = null;// w ww .j a v a2s . c om if (getValue(DocumentSettings.WIDTH, Float.class) > 0) { box.setRight(box.getLeft() + getValue(DocumentSettings.WIDTH, Float.class)); } if (getValue(DocumentSettings.HEIGHT, Float.class) > 0) { float diff = box.getHeight() - getValue(DocumentSettings.HEIGHT, Float.class); box.setBottom(box.getBottom() + diff / 2); box.setTop(box.getTop() - diff / 2); } bf.setBox(box); try { List<BaseStyler> stylers = stylerFactory.getStylers(getStyleClass()); List<FormFieldStyler> ffStylers = StyleHelper.getStylers(stylers, FormFieldStyler.class); pff = makeField(); if (FormFieldStyler.FIELDTYPE.BUTTON.equals(getFieldtype())) { for (FormFieldStyler f : ffStylers) { if (f.isParameterSet(Image.URLPARAM)) { pff.setAction(PdfAction.createSubmitForm(f.getValue(Image.URLPARAM, URL.class).toString(), null, PdfAction.SUBMIT_HTML_FORMAT)); break; } } } } catch (IOException | DocumentException | VectorPrintException ex) { throw new VectorPrintRuntimeException(ex); } getWriter().addAnnotation(pff); if (stylerFactory.getSettings().getBooleanProperty(false, DEBUG)) { DebugHelper.debugRect(canvas, box, new float[] { 2, 2 }, 0.7f, stylerFactory.getSettings(), elementProducer); DebugHelper.styleLink(canvas, getStyleClass(), "", box.getLeft(), box.getTop(), stylerFactory.getSettings(), elementProducer); } }