List of usage examples for com.itextpdf.text.pdf PdfPCell setCellEvent
public void setCellEvent(PdfPCellEvent cellEvent)
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/* ww w. jav a2s . co m*/ 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:be.kcbj.placemat.Placemat.java
License:Open Source License
private PdfPCell generateCell(Sponsor sponsor, float cellHeight) throws IOException, BadElementException { int numLines = 0; Paragraph p = new Paragraph(); if (sponsor.image != null) { Image image = Image.getInstance(SponsorManager.getImageUrl(sponsor.image)); if (sponsor.imageWidth != 0) { image.scaleToFit(sponsor.imageWidth, 1000); } else if (sponsor.imageHeight != 0) { image.scaleToFit(1000, sponsor.imageHeight); }//w ww. j a va2 s . c o m Chunk imageChunk = new Chunk(image, 0, 0, true); p.add(imageChunk); } if (sponsor.twoColumns) { StringBuilder sb = new StringBuilder(); if (sponsor.name != null) { sb.append(sponsor.name); } if (sponsor.name2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.name2); } if (sponsor.address != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address); } if (sponsor.address2 != null) { if (sb.length() > 0) { sb.append(" - "); } sb.append(sponsor.address2); } p.add(Chunk.NEWLINE); p.add(new Chunk(sb.toString(), new Font(Font.FontFamily.HELVETICA, 8, Font.NORMAL))); numLines++; } else { if (sponsor.twoRows && sponsor.image != null) { p.add(Chunk.NEWLINE); } if (sponsor.name != null) { p.add(generateFittedChunk(sponsor.name, Font.BOLD)); numLines++; } if (sponsor.name2 != null) { p.add(Chunk.NEWLINE); p.add(generateFittedChunk(sponsor.name2, Font.BOLD)); numLines++; } if (sponsor.address != null) { p.add(new Chunk("\n\n", new Font(Font.FontFamily.HELVETICA, 2, Font.NORMAL))); p.add(new Chunk(sponsor.address, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } if (sponsor.address2 != null) { p.add(Chunk.NEWLINE); p.add(new Chunk(sponsor.address2, new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); numLines++; } } p.setPaddingTop(0); p.setSpacingBefore(0); p.setAlignment(Element.ALIGN_CENTER); p.setMultipliedLeading(numLines <= 3 ? 1.3f : 1.1f); PdfPCell cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setFixedHeight(cellHeight); if (sponsor.twoColumns) { cell.setColspan(2); } if (sponsor.twoRows) { cell.setRowspan(2); if (sponsor.image == null) { p.setMultipliedLeading(p.getMultipliedLeading() * 1.5f); } } cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(CELL_EVENT); cell.setPaddingBottom(4); cell.addElement(p); if (sponsor.isTodo()) { cell.setBackgroundColor(BaseColor.ORANGE); } return cell; }
From source file:com.softwaremagico.tm.pdf.complete.elements.CustomPdfTable.java
License:Open Source License
protected PdfPCell createRectangle() { PdfPCell box = new PdfPCell(); box.setMinimumHeight(15);/*from www .jav a2 s. c o m*/ box.setBorder(0); box.setCellEvent( new CellCompleteBoxEvent(new Border[] { Border.TOP, Border.BOTTOM, Border.LEFT, Border.RIGHT })); return box; }
From source file:com.softwaremagico.tm.pdf.complete.elements.CustomPdfTable.java
License:Open Source License
protected PdfPCell createRectangle(String value) { if (value == null) { return createRectangle(); }//ww w . ja v a 2s .c om PdfPCell box = new PdfPCell(new Paragraph(value, new Font(FadingSunsTheme.getHandwrittingFont(), FadingSunsTheme.HANDWRITTING_DEFAULT_FONT_SIZE))); box.setVerticalAlignment(Element.ALIGN_MIDDLE); box.setHorizontalAlignment(Element.ALIGN_CENTER); box.setMinimumHeight(15); box.setBorder(0); box.setCellEvent( new CellCompleteBoxEvent(new Border[] { Border.TOP, Border.BOTTOM, Border.LEFT, Border.RIGHT })); return box; }
From source file:com.softwaremagico.tm.pdf.complete.skills.CounterTable.java
License:Open Source License
protected PdfPCell getCircle(CharacterPlayer characterPlayer) { if (characterPlayer == null) { return createCircle(); }//from w w w . j av a 2s . c o m if (CIRCLES - addedCircle == getSelectedValue(characterPlayer)) { PdfPCell cell = createCircle(); cell.setCellEvent(new CellCompleteBoxEvent(2, new Border[] { Border.TOP, Border.LEFT, Border.RIGHT })); return cell; } else if (CIRCLES - addedCircle == 1) { PdfPCell cell = createCircle(); cell.setCellEvent( new CellCompleteBoxEvent(2, new Border[] { Border.BOTTOM, Border.LEFT, Border.RIGHT })); return cell; } else if (CIRCLES - addedCircle < getSelectedValue(characterPlayer)) { PdfPCell cell = createCircle(); cell.setCellEvent(new CellCompleteBoxEvent(2, new Border[] { Border.LEFT, Border.RIGHT })); return cell; } else { return createCircle(); } }
From source file:com.softwaremagico.tm.pdf.small.counters.CounterTable.java
License:Open Source License
protected PdfPCell getCircle() { if (characterPlayer == null) { return createCircle(); }//from w ww .j a va 2s. co m if (addedCircle == getSelectedValue() - 1) { PdfPCell cell = createCircle(); cell.setCellEvent( new CellCompleteBoxEvent(1, new Border[] { Border.TOP, Border.BOTTOM, Border.RIGHT })); return cell; } else if (addedCircle == 0 && getSelectedValue() > 0) { PdfPCell cell = createCircle(); cell.setCellEvent(new CellCompleteBoxEvent(1, new Border[] { Border.TOP, Border.BOTTOM, Border.LEFT })); return cell; } else if (addedCircle < getSelectedValue() - 1) { PdfPCell cell = createCircle(); cell.setCellEvent(new CellCompleteBoxEvent(1, new Border[] { Border.TOP, Border.BOTTOM })); return cell; } else { return createCircle(); } }
From source file:gov.utah.dts.det.ccl.actions.trackingrecordscreening.letters.reports.LivescanAuthorization.java
private static PdfPTable getPage1WriteInLine2() throws BadElementException, DocumentException, Exception { PdfPTable table = new PdfPTable(2); PdfPTable dtl = null;/*from ww w. j a v a 2 s .co m*/ PdfPCell cell = null; int headerwidths[] = { 4, 96 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100); table.setSpacingBefore(page1ListSpace); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); dtl = new PdfPTable(12); headerwidths = new int[] { 11, 5, 11, 5, 11, 5, 11, 5, 11, 5, 11, 9 }; // percentage dtl.setWidths(headerwidths); // percentage dtl.setWidthPercentage(100); dtl.getDefaultCell().setLeading(fixedLeadingSmall, 0); dtl.getDefaultCell().setPadding(0); dtl.getDefaultCell().setBorder(Rectangle.NO_BORDER); dtl.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM); dtl.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingLinedPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingLinedPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingLinedPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingLinedPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingLinedPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingLinedPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); table.addCell(SMALL_BLANK); // Leave first cell blank table.addCell(dtl); dtl = new PdfPTable(12); headerwidths = new int[] { 11, 5, 11, 5, 11, 5, 11, 5, 11, 5, 11, 9 }; // percentage dtl.setWidths(headerwidths); // percentage dtl.setWidthPercentage(100); dtl.getDefaultCell().setLeading(fixedLeadingSmall, 0); dtl.getDefaultCell().setPadding(0); dtl.getDefaultCell().setBorder(Rectangle.NO_BORDER); dtl.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP); dtl.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); dtl.getDefaultCell().setCellEvent(new FloatingPdfPCell()); dtl.addCell(new Phrase("DOB", smallfont)); dtl.addCell(SMALL_BLANK); dtl.addCell(new Phrase("Eye Color", smallfont)); dtl.addCell(SMALL_BLANK); dtl.addCell(new Phrase("Hair Color", smallfont)); dtl.addCell(SMALL_BLANK); dtl.addCell(new Phrase("Weight", smallfont)); dtl.addCell(SMALL_BLANK); dtl.addCell(new Phrase("Height", smallfont)); dtl.addCell(SMALL_BLANK); dtl.addCell(new Phrase("Gender", smallfont)); dtl.addCell(SMALL_BLANK); table.addCell(SMALL_BLANK); // Leave first cell blank table.addCell(dtl); return table; }
From source file:gov.utah.dts.det.ccl.actions.trackingrecordscreening.letters.reports.LivescanAuthorization.java
private static PdfPTable getPage1WriteInLine3() throws BadElementException, DocumentException, Exception { PdfPTable table = new PdfPTable(2); PdfPTable dtl = null;/* w w w .j av a2s. c o m*/ PdfPCell cell = null; int headerwidths[] = { 4, 96 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100); table.setSpacingBefore(page1ListSpace); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); dtl = new PdfPTable(7); headerwidths = new int[] { 24, 5, 21, 5, 16, 5, 24 }; // percentage dtl.setWidths(headerwidths); // percentage dtl.setWidthPercentage(100); dtl.getDefaultCell().setLeading(fixedLeadingSmall, 0); dtl.getDefaultCell().setPadding(0); dtl.getDefaultCell().setBorder(Rectangle.NO_BORDER); dtl.getDefaultCell().setVerticalAlignment(Element.ALIGN_BOTTOM); dtl.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingLinedPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingLinedPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingLinedPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); cell = new PdfPCell(dtl.getDefaultCell()); cell.setCellEvent(new FloatingLinedPdfPCell()); cell.setPhrase(SMALL_BLANK); dtl.addCell(cell); table.addCell(SMALL_BLANK); // Leave first cell blank table.addCell(dtl); dtl = new PdfPTable(7); headerwidths = new int[] { 24, 5, 21, 5, 16, 5, 24 }; // percentage dtl.setWidths(headerwidths); // percentage dtl.setWidthPercentage(100); dtl.getDefaultCell().setLeading(fixedLeadingSmall, 0); dtl.getDefaultCell().setPadding(0); dtl.getDefaultCell().setBorder(Rectangle.NO_BORDER); dtl.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP); dtl.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); dtl.getDefaultCell().setCellEvent(new FloatingPdfPCell()); dtl.addCell(new Phrase("Social Security Number", smallfont)); dtl.addCell(SMALL_BLANK); dtl.addCell(new Phrase("Place of Birth", smallfont)); dtl.addCell(SMALL_BLANK); dtl.addCell(new Phrase("Race", smallfont)); dtl.addCell(SMALL_BLANK); dtl.addCell(new Phrase("Country of Citizenship", smallfont)); table.addCell(SMALL_BLANK); // Leave first cell blank table.addCell(dtl); return table; }
From source file:ihm.panneaux.GenererPdf.java
private void initComponement() throws FileNotFoundException, DocumentException, IOException { String DEST = "devis/devis-" + devis.getNumero() + ".pdf"; OutputStream file = new FileOutputStream(new File(DEST)); com.itextpdf.text.Document document = new com.itextpdf.text.Document(); PdfWriter.getInstance((com.itextpdf.text.Document) document, file); // PAS TOUCHE PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(DEST)); Rectangle rect = new Rectangle(30, 30, 550, 800); writer.setBoxSize("art", rect); HeaderFooterPageEvent event = new HeaderFooterPageEvent(); writer.setPageEvent(event);/*from w w w . j a v a 2s . co m*/ document.open(); PdfContentByte canvas = writer.getDirectContent(); Image logo = Image.getInstance("images/logo.png"); logo.scaleAbsolute(200, 57); // INFO DEVIS Image devisImg = Image.getInstance("images/imgDevis.png"); devisImg.scaleAbsolute(110, 34); devisImg.setAbsolutePosition((PageSize.POSTCARD.getWidth() + 150), (PageSize.POSTCARD.getHeight() - devisImg.getScaledHeight()) * 2); Font fontImgDevis = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); Phrase numeroInfo = new Phrase("Numro " + devis.getNumero(), fontImgDevis); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, numeroInfo, devisImg.getScaledWidth() + 413, devisImg.getScaledHeight() + 710, 0); Phrase dateInfo = new Phrase("Le " + devis.getDate(), fontImgDevis); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, dateInfo, devisImg.getScaledWidth() + 420, devisImg.getScaledHeight() + 695, 0); Image devisImgBordure = Image.getInstance("images/bordureDevis.png"); devisImgBordure.setAbsolutePosition((devisImg.getScaledWidth() + 318), devisImg.getScaledHeight() + 660); devisImgBordure.scaleAbsolute(120, 122); // INFO ENTREPRISE Font fontEntreprise = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.BOLD); Phrase coGerants = new Phrase("Co-grants : " + devis.getEntreprise().getCoGerant(), fontEntreprise); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, coGerants, devisImg.getScaledWidth() + 210, devisImg.getScaledHeight() + 660, 0); Phrase siege = new Phrase("Sige : " + devis.getEntreprise().getSiege(), fontEntreprise); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, siege, devisImg.getScaledWidth() + 149, devisImg.getScaledHeight() + 640, 0); Phrase tel = new Phrase("TEL : " + devis.getEntreprise().getTel(), fontEntreprise); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, tel, devisImg.getScaledWidth() + 113, devisImg.getScaledHeight() + 625, 0); Image bordureEntreprise = Image.getInstance("images/bordureEntreprise.png"); bordureEntreprise.setAbsolutePosition(devisImg.getScaledWidth() - 80, devisImg.getScaledHeight() + 610); // INFO CLIENT Font fontClient = new Font(Font.FontFamily.TIMES_ROMAN, 11, Font.NORMAL); Phrase nomPrenom = new Phrase(devis.getClient().getNom() + " " + devis.getClient().getPrenom(), fontClient); Phrase commune = new Phrase(devis.getClient().getAdresse(), fontClient); Phrase adresse = new Phrase(devis.getClient().getCodePostale() + " " + devis.getClient().getCommune(), fontClient); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, nomPrenom, PageSize.A4.getWidth() - 280, devisImg.getScaledHeight() + 595, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, commune, PageSize.A4.getWidth() - 280, devisImg.getScaledHeight() + 580, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, adresse, PageSize.A4.getWidth() - 280, devisImg.getScaledHeight() + 565, 0); document.add(logo); document.add(devisImg); document.add(devisImgBordure); document.add(bordureEntreprise); // AJOUT DES DONNEES DU TABLEAUX float[] columnWidths = { 14, 3, 4, 3, 4 }; Font fontCategorie = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); fontCategorie.setColor(BaseColor.GREEN); PdfPTable table = new PdfPTable(columnWidths); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.setTotalWidth(PageSize.A4.getWidth() - 15); table.setSpacingBefore(150); table.setLockedWidth(true); Font Categorie = new Font(FontFamily.HELVETICA, 13, Font.BOLD); Font Chantier = new Font(FontFamily.HELVETICA, 11, Font.UNDERLINE); PdfPCell cellChantier = new PdfPCell(new Phrase("CHANTIER : " + chantier, Chantier)); cellChantier.setColspan(3); cellChantier.setBorder(Rectangle.NO_BORDER); table.addCell(cellChantier); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(new Phrase("Dsignation", Categorie)); PdfPCell unite = new PdfPCell(new Phrase("Unite", Categorie)); PdfPCell quantite = new PdfPCell(new Phrase("Quantite", Categorie)); PdfPCell prixht = new PdfPCell(new Phrase("Prix HT", Categorie)); PdfPCell pvtht = new PdfPCell(new Phrase("Pvt HT", Categorie)); unite.setHorizontalAlignment(Element.ALIGN_CENTER); quantite.setHorizontalAlignment(Element.ALIGN_CENTER); prixht.setHorizontalAlignment(Element.ALIGN_CENTER); pvtht.setHorizontalAlignment(Element.ALIGN_CENTER); unite.setBorder(Rectangle.NO_BORDER); quantite.setBorder(Rectangle.NO_BORDER); prixht.setBorder(Rectangle.NO_BORDER); pvtht.setBorder(Rectangle.NO_BORDER); table.addCell(unite); table.addCell(quantite); table.addCell(prixht); table.addCell(pvtht); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); double htTotalParcour = 0; double ttcTotalParcour = 0; if (this.EquipementDeChantier.isEmpty() == false) { table.addCell(new Phrase("Equipement De Chantier", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : EquipementDeChantier) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); /* BACKUP table.addCell(listeMaterielDevi.getMateriel().getNom()); table.addCell(listeMaterielDevi.getMateriel().getUnite()); table.addCell(Double.toString(listeMaterielDevi.getQuantite())); table.addCell(Double.toString(listeMaterielDevi.getMateriel().getPrix())+""); table.addCell(Double.toString(listeMaterielDevi.getPvtHT())+""); */ ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (Couverture.isEmpty() == false) { table.addCell(new Phrase("Couverture", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Couverture) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (CouvertureArdoise.isEmpty() == false) { table.addCell(new Phrase("Couverture Ardoise", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : CouvertureArdoise) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (CouvertureTuile.isEmpty() == false) { table.addCell(new Phrase("Couverture Tuile", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : CouvertureTuile) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (this.Demoussage.isEmpty() == false) { table.addCell(new Phrase("Demoussage", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Demoussage) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (this.Velux.isEmpty() == false) { table.addCell(new Phrase("Velux", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Velux) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (this.Zinguerie.isEmpty() == false) { table.addCell(new Phrase("Zinguerie", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Zinguerie) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } if (Plancher.isEmpty() == false) { table.addCell(new Phrase("Plancher", fontCategorie)); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); for (DevisContenu listeMaterielDevi : Plancher) { table.addCell(listeMaterielDevi.getMateriel().getNom()); PdfPCell cellunite = new PdfPCell(new Phrase(listeMaterielDevi.getMateriel().getUnite())); PdfPCell cellQuantite = new PdfPCell(new Phrase(Double.toString(listeMaterielDevi.getQuantite()))); PdfPCell cellprix = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getMateriel().getPrix()) + "")); PdfPCell cellpvtHT = new PdfPCell( new Phrase(Double.toString(listeMaterielDevi.getPvtHT()) + "")); cellunite.setHorizontalAlignment(Element.ALIGN_CENTER); cellQuantite.setHorizontalAlignment(Element.ALIGN_CENTER); cellprix.setHorizontalAlignment(Element.ALIGN_CENTER); cellpvtHT.setHorizontalAlignment(Element.ALIGN_CENTER); cellunite.setBorder(Rectangle.NO_BORDER); cellQuantite.setBorder(Rectangle.NO_BORDER); cellprix.setBorder(Rectangle.NO_BORDER); cellpvtHT.setBorder(Rectangle.NO_BORDER); table.addCell(cellunite); table.addCell(cellQuantite); table.addCell(cellprix); table.addCell(cellpvtHT); ttcTotalParcour += listeMaterielDevi.getPvtHT(); htTotalParcour += listeMaterielDevi.getPvtHT(); } table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); table.addCell(" "); } ttcTotalParcour = (ttcTotalParcour * devis.getTva() / 100) + ttcTotalParcour; LineDash solid = new SolidLine(); PdfPCell cell, cell2, cellSOUSTOTAL, cellhttotal, tva, getTva, totalttc, gettotalttc; table.addCell(new Phrase(" ")); table.addCell(new Phrase(" ")); table.addCell(new Phrase(" ")); table.addCell(new Phrase(" ")); cell = new PdfPCell(new Phrase("")); cell.setBorder(PdfPCell.NO_BORDER); cell.setCellEvent(new CustomBorder(null, null, null, solid)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.addCell(new Phrase("")); table.addCell(new Phrase("")); cellSOUSTOTAL = new PdfPCell(new Phrase("SOUS-TOTAL")); cellSOUSTOTAL.setHorizontalAlignment(Element.ALIGN_MIDDLE); cellSOUSTOTAL.setBorder(Rectangle.NO_BORDER); table.addCell(cellSOUSTOTAL); table.addCell(new Phrase("")); double prixHT_2Chiffre = Math.round((htTotalParcour) * Math.pow(10, 2)) / Math.pow(10, 2); String httotal = String.valueOf(prixHT_2Chiffre); cellhttotal = new PdfPCell(new Phrase(httotal + "")); cellhttotal.setBorder(Rectangle.NO_BORDER); cellhttotal.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(cellhttotal); table.addCell(new Phrase("")); table.addCell(new Phrase("")); tva = new PdfPCell(new Phrase("TVA")); tva.setBorder(Rectangle.NO_BORDER); tva.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(tva); getTva = new PdfPCell(new Phrase(devis.getTva() + "%")); getTva.setBorder(Rectangle.NO_BORDER); getTva.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(getTva); String tvaprix = String.valueOf(htTotalParcour * devis.getTva() / 100); double prixTVA_2Chiffre = Math.round(Double.parseDouble(tvaprix) * Math.pow(10, 2)) / Math.pow(10, 2); cell2 = new PdfPCell(new Phrase(Double.toString(prixTVA_2Chiffre) + "")); cell2.setBorder(PdfPCell.NO_BORDER); cell2.setCellEvent(new CustomBorder(null, null, null, solid)); cell2.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell2); table.addCell(""); table.addCell(""); totalttc = new PdfPCell(new Phrase("Total TTC")); totalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE); totalttc.setBorder(PdfPCell.NO_BORDER); table.addCell(totalttc); table.addCell(""); double prixTTC_2Chiffre = Math.round(ttcTotalParcour * Math.pow(10, 2)) / Math.pow(10, 2); String ttctotal = String.valueOf(Double.toString(prixTTC_2Chiffre)); gettotalttc = new PdfPCell(new Phrase(ttctotal + "")); gettotalttc.setBorder(PdfPCell.NO_BORDER); gettotalttc.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.addCell(gettotalttc); table.setSpacingAfter(10); document.add(table); Pattern p = Pattern.compile("[.^\\.]+"); String texte = devis.getInformationComplementaire(); Font infoComptBlue = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL); infoComptBlue.setColor(BaseColor.BLUE); Font infoComptRed = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL); infoComptRed.setColor(BaseColor.RED); Font infoComptBlack = new Font(Font.getFamily("TIMES_ROMAN"), 8, Font.NORMAL); infoComptBlack.setColor(BaseColor.BLACK); Paragraph infoComp = new Paragraph(); Image BonPourAccord = null; BonPourAccord = Image.getInstance("images/BonPourAccord.png"); infoComp.setAlignment(Element.ALIGN_LEFT); BonPourAccord.setAlignment(Image.TEXTWRAP | Image.ALIGN_RIGHT); String[] phrase = p.split(texte); for (int i = 0; i < phrase.length; i++) { if (i == 0 || i == 1) { infoComp.add(new Paragraph(phrase[i], infoComptBlue)); } if (i == 2 || i == 3 || i == 4 || i == 5) { infoComp.add(new Paragraph(phrase[i], infoComptRed)); } if (i > 5 && i <= 11) infoComp.add(new Paragraph(phrase[i], infoComptBlack)); if (i > 11) infoComp.add(new Paragraph(phrase[i], infoComptRed)); } /* A OPTIMISER */ float taille_tableau = table.calculateHeights() + table.getRowHeight(table.getLastCompletedRowIndex()); if (taille_tableau > 386) { document.newPage(); } document.add(BonPourAccord); document.add(infoComp); document.close(); EnvoieDevis envoie = new EnvoieDevis(null, true, session, devis); this.CouvertureArdoise.clear(); this.CouvertureTuile.clear(); this.Demoussage.clear(); this.EquipementDeChantier.clear(); this.Velux.clear(); this.Zinguerie.clear(); this.Couverture.clear(); this.Plancher.clear(); }
From source file:org.openmrs.module.maternalsummary.pdf.impl.ITextRenderer.java
License:Open Source License
@Override public void tableAddInputField() throws PDFRendererException { PdfPCell cell = new PdfPCell(); cell.setCellEvent(new ReferralCommentEvent()); cell.setFixedHeight(120);/*ww w.j a va2s . c o m*/ _table.addCell(cell); }