List of usage examples for com.itextpdf.text.pdf PdfPTable getDefaultCell
public PdfPCell getDefaultCell()
PdfPCell
that will be used as reference for all the addCell
methods except addCell(PdfPCell)
. From source file:fxml.test.PDFService.java
public PdfPTable createTableHeader(int start) { PdfPTable table = null;/*from w w w . java 2s . co m*/ try { int colCount = 1; List<Float> columnsList = new ArrayList<>(); columnsList.add(57.5f); columnsList.add(159.4f); for (int i = start; i < list.size(); i++) { if (list.get(i) instanceof Course) { columnsList.add(44f); } else if (list.get(i).equals("Total Credit")) { columnsList.add(30f); } else if (list.get(i).equals("Total GPA")) { columnsList.add(30f); } else if (list.get(i).equals("Letter Grade")) { columnsList.add(30f); } else if (list.get(i).equals("Cumulative")) { columnsList.add(88f); } else { columnsList.add(66f); } if (colCount == 12) { break; } colCount++; } float[] columns = new float[columnsList.size()]; for (int i = 0; i < columnsList.size(); i++) { columns[i] = columnsList.get(i); } table = new PdfPTable(columns.length); System.err.println("table size :" + table.getNumberOfColumns()); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setTotalWidth(columns); table.setLockedWidth(true); } catch (DocumentException ex) { Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex); } PdfPCell regCell = getCellForString("Reg No.", 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, false); regCell.setPaddingTop(0f); table.addCell(regCell); PdfPCell nameCell = getNameCell(); nameCell.setPaddingBottom(2f); table.addCell(nameCell); int colCount = 1; for (int i = start; i < list.size(); i++) { if (list.get(i) instanceof Course) { Course course = (Course) list.get(i); PdfPCell cell3 = new PdfPCell(createCourseInfo(course)); cell3.setPaddingTop(1f); cell3.setPaddingBottom(2f); //cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell3); } else if (list.get(i).equals("Total Credit") || list.get(i).equals("Total GPA") || list.get(i).equals("Letter Grade")) { String str = (String) list.get(i); String s[] = str.split(" "); PdfPTable totalCredit = new PdfPTable(1); totalCredit.setSpacingBefore(12.5f); totalCredit.setWidthPercentage(100); totalCredit.getDefaultCell().setBorder(Rectangle.NO_BORDER); PdfPCell cell1 = getCellForString(s[0], 0, false, 0, Element.ALIGN_CENTER, new Font(Font.FontFamily.TIMES_ROMAN, 10f), false); PdfPCell cell2 = getCellForString(s[1], 0, false, 0, Element.ALIGN_CENTER, new Font(Font.FontFamily.TIMES_ROMAN, 10f), false); totalCredit.addCell(cell1); totalCredit.addCell(cell2); PdfPCell grade = new PdfPCell(totalCredit); table.addCell(grade); } else if (list.get(i).equals("Cumulative")) { PdfPTable cumulative = new PdfPTable(1); // cumulative.setPaddingTop(count); cumulative.addCell(getCellForString("Cumulative", 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font10, true)); PdfPTable creditGpaGrade = new PdfPTable(3); creditGpaGrade.setTotalWidth(88f); creditGpaGrade.setLockedWidth(true); creditGpaGrade.addCell(getCellForString("Credit", 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font10, true)); creditGpaGrade.addCell(getCellForString("GPA", 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font10, true)); creditGpaGrade.addCell(getCellForString("Grade", 0, false, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font10, true)); PdfPTable p = new PdfPTable(1); PdfPCell cell1 = new PdfPCell(cumulative); cell1.setPaddingBottom(3f); cell1.setBorder(Rectangle.NO_BORDER); PdfPCell cell2 = new PdfPCell(creditGpaGrade); cell2.setBorder(Rectangle.NO_BORDER); p.addCell(cell1); p.addCell(cell2); table.addCell(p); } else { table.addCell(getCellForString((String) list.get(i), 0, true, Element.ALIGN_MIDDLE, Element.ALIGN_CENTER, font9, true)); } if (colCount == 12) { break; } colCount++; } return table; }
From source file:generators.InvoiceEventListener.java
@Override public void onEndPage(PdfWriter writer, Document document) { Font defaultFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); try {/*from w w w. ja v a2 s. c o m*/ PdfPTable footerTable = new PdfPTable(3); footerTable.setTotalWidth(document.right(document.leftMargin())); footerTable.getDefaultCell().setBorder(Rectangle.TOP); footerTable.addCell(new Paragraph("Lionsclub Oegstgeest/Warmond", defaultFont)); footerTable.completeRow(); footerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); footerTable.addCell(new Paragraph("Betaalrekening", defaultFont)); footerTable.addCell(new Paragraph(": ************", defaultFont)); footerTable.completeRow(); footerTable.addCell(new Paragraph("Inschrijvnummer KvK Rijnland", defaultFont)); footerTable.addCell(new Paragraph(": ************ ", defaultFont)); footerTable.completeRow(); footerTable.writeSelectedRows(0, -1, document.leftMargin(), document.bottom(footerTable.getTotalHeight()) - document.bottomMargin() + 15, writer.getDirectContent()); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_RIGHT, new Phrase(String.format("%d", writer.getPageNumber()), defaultFont), document.right(), document.bottom() - document.bottomMargin() + 18, 0); } catch (Exception e) { e.printStackTrace(); } }
From source file:generators.InvoiceGenerator.java
/** * Generate Invoice pdf file/*from w w w .j a v a2 s . c o m*/ * * @param order the order * @throws DocumentException the document exception * @throws IOException the io exception */ public void generate(Order order) throws DocumentException, IOException { Date invoiceDate = order.getDate(); SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM YYYY"); // User guest = order.getGuest(); User guest = new UserDAO().get(order.getUserId()); guest.setOrder(order); System.out.println("invoice generator orderID: " + order.getId()); Document document = new Document(); Font defaultFont = new Font(Font.FontFamily.TIMES_ROMAN, 12); System.out.println(System.getProperty("user.dir")); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(System.getProperty("user.dir") + "/src/main/java/nl/ipsen3/invoice/" + new SimpleDateFormat("dd-MM-yyyy").format(invoiceDate) + " - " + order.getId() + ".pdf")); document.setMargins(30, 30, 30, 65); writer.setPageEvent(new InvoiceEventListener()); document.open(); Paragraph header = new Paragraph("Lionsclub Oegstgeest/Warmond", new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD)); header.setAlignment(Element.ALIGN_CENTER); document.add(header); AddressDAO addressDAO = new AddressDAO(); Address userAddress = addressDAO.get(guest.getAddressId()); Paragraph address = new Paragraph(guest.getFirstName() + " " + guest.getPrefixLastName() + " " + guest.getLastName() + "\n" + userAddress.getStreet() + " " + userAddress.getHouseNumber() + "\n" + userAddress.getZipCode() + " " + userAddress.getCity(), defaultFont); address.setSpacingBefore(35); address.setSpacingAfter(25); address.setLeading(15); document.add(address); Paragraph invoiceDetails = new Paragraph("Factuurdatum: " + sdf.format(invoiceDate) + "\n" + "FactuurNummer: " + order.getId() + " \n" + "Debiteurennummer: " + guest.getId(), defaultFont); invoiceDetails.setSpacingAfter(15); invoiceDetails.setLeading(15); document.add(invoiceDetails); Paragraph subject = new Paragraph("Betreft: Onderwerp factuur", defaultFont); subject.setSpacingAfter(30); document.add(subject); PdfPTable orderTable = new PdfPTable(10); PdfPCell wineCell = new PdfPCell(new Paragraph("Wijn", defaultFont)); wineCell.setColspan(5); wineCell.setBorder(Rectangle.BOTTOM); orderTable.getDefaultCell().setPaddingBottom(10); orderTable.getDefaultCell().setBorder(Rectangle.BOTTOM); ; orderTable.addCell(new Paragraph("Code", defaultFont)); orderTable.addCell(new Paragraph("Aantal", defaultFont)); orderTable.addCell(wineCell); orderTable.addCell(new Paragraph("Jaar", defaultFont)); orderTable.addCell(new Paragraph("Per Fles", defaultFont)); orderTable.addCell(new Paragraph("Bedrag", defaultFont)); orderTable.getDefaultCell().setPaddingBottom(0); orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); wineCell.setBorder(Rectangle.NO_BORDER); NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.GERMANY); for (WineOrder wineOrder : order.getWineOrders()) { orderTable.addCell(new Paragraph("" + wineOrder.getWine().getId(), defaultFont)); orderTable.addCell(new Paragraph("" + wineOrder.getAmount(), defaultFont)); wineCell.setPhrase(new Phrase(wineOrder.getWine().getName(), defaultFont)); orderTable.addCell(wineCell); orderTable.addCell(new Paragraph("" + wineOrder.getWine().getYear(), defaultFont)); orderTable.addCell(new Paragraph( " " + numberFormat.format(wineOrder.getWine().getPrice()).replace(" ", ""), defaultFont)); orderTable.addCell(new Paragraph(" " + numberFormat .format(wineOrder.getAmount() * wineOrder.getWine().getPrice()).replace(" ", ""), defaultFont)); orderTable.completeRow(); } orderTable.addCell(" "); orderTable.completeRow(); Font totalFont = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD); PdfPCell totalAmount = new PdfPCell( new Paragraph(" " + numberFormat.format(order.getTotalAmount()).replace(" ", ""), totalFont)); totalAmount.setBorder(Rectangle.TOP); totalAmount.setPaddingTop(10); PdfPCell totalCell = new PdfPCell(new Paragraph("Totaal", totalFont)); totalCell.setPaddingTop(10); totalCell.setBorder(Rectangle.NO_BORDER); orderTable.addCell(totalCell); PdfPCell fillerCell = new PdfPCell(new Paragraph("")); fillerCell.setColspan(8); fillerCell.setBorder(Rectangle.NO_BORDER); orderTable.addCell(fillerCell); orderTable.addCell(totalAmount); orderTable.setSpacingBefore(15); orderTable.setSpacingAfter(30); orderTable.setWidthPercentage(95); orderTable.setHorizontalAlignment(Element.ALIGN_CENTER); document.add(orderTable); Paragraph retrievalDetails = new Paragraph( "Wij verzoeken u vriendelijk het totaalbedrag binnen 7 dagen na factuurdatum over te maken op bankrekening <bankAccountNr> t.n.v <bankAccountName> onder vermelding van het factuurnummer", defaultFont); retrievalDetails.setLeading(15); retrievalDetails.setSpacingAfter(20); document.add(retrievalDetails); // document.add(new Paragraph("U kunt uw wijnen ophalen op " + sdf.format(invoiceDate) , defaultFont)); // document.add(new Paragraph("Adres:", defaultFont)); // // PdfPTable addressTable = new PdfPTable(1); // addressTable.setSpacingBefore(5); // addressTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // addressTable.getDefaultCell().setPaddingLeft(35); // MerchantService merchantService = new MerchantService(); // Merchant merchant = merchantService.find(merchantService.all().get(0).getId()); // addressTable.addCell(new Paragraph(merchant.getName(), defaultFont)); // addressTable.addCell(new Paragraph(merchant.getAddress().getStreet() // + " " + merchant.getAddress().getHouseNumber(), defaultFont)); // addressTable.addCell(new Paragraph(merchant.getAddress().getZipCode() + " " + // merchant.getAddress().getCity(), defaultFont)); // addressTable.setHorizontalAlignment(Element.ALIGN_LEFT); // document.add(addressTable); document.close(); System.out.println( "Succesfully generated IPSEN2.invoice: " + order.getId() + " on Date: " + sdf.format(invoiceDate)); }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.ExpiredLicensesReport.java
private static void writePdf(Person specialist, List<FacilityLicenseView> licenses, OutputStream ba) throws DocumentException, BadElementException { Document document = null;/*from ww w. j a v a 2s . co m*/ PdfPTable doctable; PdfPTable datatable; PdfPTable factable; Paragraph paragraph; Facility facility; document = new Document(PageSize.A4); @SuppressWarnings("unused") PdfWriter writer = PdfWriter.getInstance(document, ba); document.open(); doctable = getDocumentTable(specialist); if (licenses != null && licenses.size() > 0) { doctable.getDefaultCell().setPaddingBottom(4); doctable.getDefaultCell().setBorderWidthBottom(.5f); for (FacilityLicenseView license : licenses) { facility = license.getFacility(); datatable = getDetailTable(); datatable.getDefaultCell().setPaddingLeft(4); datatable.getDefaultCell().setPaddingRight(2); datatable.getDefaultCell().setColspan(1); // Add Facility Name information if (StringUtils.isNotBlank(license.getFacilityName())) { datatable.addCell(new Phrase(license.getFacilityName().toUpperCase(), smallfont)); } else { datatable.addCell(BLANK); } // Add License Number information datatable.getDefaultCell().setPaddingLeft(2); if (license.getLicenseNumber() != null) { datatable.addCell(new Phrase(license.getLicenseNumber().toString(), smallfont)); } else { datatable.addCell(BLANK); } // Add Service Code information if (StringUtils.isNotBlank(license.getServiceCodeCode())) { datatable.addCell(new Phrase(license.getServiceCodeCode(), smallfont)); } else { datatable.addCell(BLANK); } // Add License Type information if (StringUtils.isNotBlank(license.getSubtype())) { datatable.addCell(new Phrase(license.getSubtype(), smallfont)); } else { datatable.addCell(BLANK); } // Add License Expiration date information datatable.getDefaultCell().setPaddingRight(4); if (StringUtils.isNotBlank(license.getExpirationDateFormatted())) { datatable.addCell(new Phrase(license.getExpirationDateFormatted(), smallfont)); } else { datatable.addCell(BLANK); } // Add Mailing Location information sb = new StringBuilder(); if (facility != null && facility.getMailingAddress() != null && StringUtils.isNotBlank(facility.getMailingAddress().getAddressOne())) { sb.append(facility.getMailingAddress().getAddressOne()); // add address two if (StringUtils.isNotBlank(facility.getMailingAddress().getAddressTwo())) { if (sb.length() > 0) { sb.append(" "); } sb.append(facility.getMailingAddress().getAddressTwo()); } // Add city, state, zip if (StringUtils.isNotBlank(facility.getMailingAddress().getCityStateZip())) { if (sb.length() > 0) { sb.append(", "); } sb.append(facility.getMailingAddress().getCityStateZip()); } } datatable.getDefaultCell().setColspan(5); datatable.getDefaultCell().setPaddingLeft(4); datatable.getDefaultCell().setPaddingRight(4); if (sb.length() > 0) { datatable.addCell(new Phrase(sb.toString().toUpperCase(), smallfont)); } else { datatable.addCell(BLANK); } // // Add Facility details information // factable = getFacilityDetailsTable(); // Add primary phone information paragraph = new Paragraph(fixedLeading); paragraph.add(new Phrase("Primary Phone: ", smallfontB)); if (facility != null && facility.getPrimaryPhone() != null && StringUtils.isNotBlank(facility.getPrimaryPhone().getFormattedPhoneNumber())) { paragraph.add(new Phrase(facility.getPrimaryPhone().getFormattedPhoneNumber(), smallfont)); } factable.getDefaultCell().setPaddingLeft(4); factable.getDefaultCell().setPaddingRight(2); factable.addCell(paragraph); // Add SAFE Provider ID number paragraph = new Paragraph(fixedLeading); paragraph.add(new Phrase("SAFE: ", smallfontB)); if (facility != null && facility.getSafeProviderId() != null) { paragraph.add(new Phrase(facility.getSafeProviderId().toString(), smallfontB)); } factable.getDefaultCell().setColspan(2); factable.addCell(paragraph); // Add the facility information table to the details table datatable.getDefaultCell().setPadding(0); datatable.addCell(factable); // Add the detail to the document table doctable.addCell(datatable); } } else { // No open applications datatable = getDetailTable(); datatable.getDefaultCell().setPaddingTop(10); datatable.getDefaultCell().setColspan(3); datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_CENTER); datatable.addCell(new Phrase("No expired licenses found to display.", smallfont)); doctable.getDefaultCell().setPaddingBottom(0); doctable.getDefaultCell().setBorderWidthBottom(0); doctable.addCell(datatable); } // Add the document table to the document document.add(doctable); document.close(); }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.ExpiredLicensesReport.java
private static PdfPTable getDocumentTable(Person specialist) throws DocumentException { PdfPTable table = new PdfPTable(1); // format the tables int headerwidths[] = { 100 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);/*w ww. j a va2 s . c o m*/ table.getDefaultCell().setLeading(0, 0); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorderWidthLeft(0); table.getDefaultCell().setBorderWidthRight(0); table.getDefaultCell().setBorderWidthTop(0); table.getDefaultCell().setPaddingBottom(4); table.getDefaultCell().setBorderWidthBottom(1.0f); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_CENTER); table.addCell(getHeaderTable(specialist)); table.setHeaderRows(1); return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.ExpiredLicensesReport.java
private static PdfPTable getHeaderTable(Person specialist) throws DocumentException { Date today = new Date(); PdfPTable table = getDetailTable(); // Add Page header information table.getDefaultCell().setLeading(largeFixedLeading, 0); table.getDefaultCell().setPaddingLeft(4); table.getDefaultCell().setPaddingRight(2); table.getDefaultCell().setPaddingBottom(20); table.getDefaultCell().setBorderWidthLeft(0); table.getDefaultCell().setBorderWidthRight(0); table.getDefaultCell().setBorderWidthTop(1.0f); table.getDefaultCell().setBorderWidthBottom(0); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_TOP); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); table.getDefaultCell().setColspan(3); sb = new StringBuilder(); sb.append("Expired Licenses for "); if (StringUtils.isNotBlank(specialist.getFirstAndLastName())) { sb.append(specialist.getFirstAndLastName()); }/*from w w w .j a v a2 s . c o m*/ table.addCell(new Phrase(sb.toString(), largefontB)); // Add report date table.getDefaultCell().setPaddingLeft(2); table.getDefaultCell().setPaddingRight(4); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT); table.getDefaultCell().setColspan(2); table.addCell(new Phrase(df.format(today), mediumfontB)); // Add Facility Name column header table.getDefaultCell().setLeading(fixedLeading, 0); table.getDefaultCell().setPaddingLeft(4); table.getDefaultCell().setPaddingRight(2); table.getDefaultCell().setPaddingBottom(0); table.getDefaultCell().setBorderWidthTop(0.5f); table.getDefaultCell().setBorderWidthBottom(0); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_BOTTOM); table.getDefaultCell().setColspan(1); table.addCell(new Phrase("Facility Name", smallfontB)); // Add License Number column header table.getDefaultCell().setPaddingLeft(2); table.addCell(new Phrase("License Number", smallfontB)); // Add Service Code column header table.addCell(new Phrase("Service", smallfontB)); // Add License Type column header table.addCell(new Phrase("License Type", smallfontB)); // Add End Date column header table.getDefaultCell().setPaddingRight(4); table.addCell(new Phrase("End Date", smallfontB)); return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.ExpiredLicensesReport.java
private static PdfPTable getDetailTable() throws DocumentException { PdfPTable table = new PdfPTable(5); // format the table int headerwidths[] = { 41, 17, 8, 24, 10 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);//from w ww.j ava 2s.co m table.getDefaultCell().setLeading(fixedLeading, 0); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_BOTTOM); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.ExpiredLicensesReport.java
private static PdfPTable getFacilityDetailsTable() throws DocumentException { PdfPTable table = new PdfPTable(3); // format the table int headerwidths[] = { 33, 33, 33 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);// w ww . j ava 2 s .c om table.getDefaultCell().setLeading(fixedLeading, 0); table.getDefaultCell().setPadding(0); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setVerticalAlignment(PdfPTable.ALIGN_BOTTOM); table.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseDetailReport.java
private static void writePdf(Person specialist, Date endDate, List<FacilityLicenseView> licenses, OutputStream ba) throws DocumentException, BadElementException { Document document = null;// w w w .j ava 2s .c o m PdfPTable doctable; Paragraph paragraph; Facility facility; document = new Document(PageSize.LETTER, 40, 40, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, ba); PageNumberEventLeft pageNumber = new PageNumberEventLeft(); writer.setPageEvent(pageNumber); document.open(); doctable = getDocumentTable(specialist, endDate); if (licenses != null && licenses.size() > 0) { boolean moreLicenses = true; boolean facilityIsChanging = true; int idx = 0; FacilityLicenseView license = licenses.get(idx); while (moreLicenses) { facility = license.getFacility(); doctable.getDefaultCell().setPaddingBottom(4); doctable.getDefaultCell().setBorderWidthBottom(.5f); if (facilityIsChanging) { doctable.addCell(populateFacilityInformation(facility)); facilityIsChanging = false; } // Check to see if the next record will change the facility so we can put the // proper bottom border. idx++; if (idx >= licenses.size()) { // this is the last license moreLicenses = false; } else { FacilityLicenseView next = licenses.get(idx); if (!next.getFacilityId().equals(license.getFacilityId())) { facilityIsChanging = true; } } // Set the bottom border based on the previous check findings if (facilityIsChanging || !moreLicenses) { // Add a large bottom border doctable.getDefaultCell().setBorderWidthBottom(1.0f); } doctable.addCell(populateLicenseInformation(license)); // Get the next license if (moreLicenses) { license = licenses.get(idx); } } } else { // No open applications paragraph = new Paragraph(fixedLeading); paragraph.setSpacingBefore(10); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.add(new Phrase("No active facility licenses found to display.", smallfont)); doctable.addCell(paragraph); } // Add the document table to the document document.add(doctable); document.close(); }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseDetailReport.java
private static PdfPTable populateFacilityInformation(Facility facility) throws DocumentException { Paragraph paragraph;//w w w . j a v a 2s . c om PdfPTable datatable = getFacilityDetailTable(); // Add Facility Name information datatable.getDefaultCell().setColspan(4); datatable.getDefaultCell().setPaddingLeft(4); datatable.getDefaultCell().setPaddingRight(4); if (StringUtils.isNotBlank(facility.getName())) { datatable.addCell(new Phrase(facility.getName().toUpperCase(), smallfont)); } else { datatable.addCell(BLANK); } // Add First Director(s) information datatable.getDefaultCell().setColspan(1); datatable.getDefaultCell().setPaddingLeft(4); datatable.getDefaultCell().setPaddingRight(2); datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT); datatable.addCell(new Phrase("Director(s):", smallfontB)); datatable.getDefaultCell().setPaddingLeft(2); datatable.getDefaultCell().setPaddingRight(4); datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); datatable.getDefaultCell().setColspan(3); sb = new StringBuilder(); List<FacilityPerson> directors = facility.getPeopleOfType(FIRST_DIRECTOR, true); if (directors != null && directors.size() > 0) { for (FacilityPerson fp : directors) { if (fp.getPerson() != null && StringUtils.isNotBlank(fp.getPerson().getFirstAndLastName())) { if (sb.length() > 0) { sb.append(", "); } sb.append(fp.getPerson().getFirstAndLastName().toUpperCase()); } } } if (sb.length() > 0) { datatable.addCell(new Phrase(sb.toString(), mediumfont)); } else { datatable.addCell(BLANK); } // Add Site information datatable.getDefaultCell().setColspan(1); datatable.getDefaultCell().setPaddingLeft(4); datatable.getDefaultCell().setPaddingRight(2); datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT); datatable.addCell(new Phrase("Site:", smallfontB)); datatable.getDefaultCell().setPaddingLeft(2); datatable.getDefaultCell().setPaddingRight(4); datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); datatable.getDefaultCell().setColspan(3); if (StringUtils.isNotBlank(facility.getSiteName())) { datatable.addCell(new Phrase(facility.getSiteName())); } else { datatable.addCell(BLANK); } // Add Mailing address information datatable.getDefaultCell().setColspan(1); datatable.getDefaultCell().setPaddingLeft(4); datatable.getDefaultCell().setPaddingRight(2); datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT); datatable.addCell(new Phrase("Mailing:", smallfontB)); datatable.getDefaultCell().setPaddingLeft(2); datatable.getDefaultCell().setPaddingRight(4); datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); datatable.getDefaultCell().setColspan(3); if (facility.getMailingAddress() != null && StringUtils.isNotBlank(facility.getMailingAddress().getAddressOne())) { sb = new StringBuilder(); sb.append(facility.getMailingAddress().getAddressOne()); if (StringUtils.isNotBlank(facility.getMailingAddress().getAddressTwo())) { sb.append(" " + facility.getMailingAddress().getAddressTwo()); } if (StringUtils.isNotBlank(facility.getMailingAddress().getCityStateZip())) { sb.append(", " + facility.getMailingAddress().getCityStateZip()); } paragraph = new Paragraph(fixedLeading); paragraph.add(new Phrase(sb.toString().toUpperCase(), smallfont)); datatable.addCell(paragraph); } else { datatable.addCell(BLANK); } // Add Location address information datatable.getDefaultCell().setColspan(1); datatable.getDefaultCell().setPaddingLeft(4); datatable.getDefaultCell().setPaddingRight(2); datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT); datatable.addCell(new Phrase("Location:", smallfontB)); datatable.getDefaultCell().setPaddingLeft(2); datatable.getDefaultCell().setPaddingRight(4); datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); datatable.getDefaultCell().setColspan(3); if (facility.getLocationAddress() != null && StringUtils.isNotBlank(facility.getLocationAddress().getAddressOne())) { sb = new StringBuilder(); sb.append(facility.getLocationAddress().getAddressOne()); if (StringUtils.isNotBlank(facility.getLocationAddress().getAddressTwo())) { sb.append(" " + facility.getLocationAddress().getAddressTwo()); } if (StringUtils.isNotBlank(facility.getLocationAddress().getCityStateZip())) { sb.append(", " + facility.getLocationAddress().getCityStateZip()); } paragraph = new Paragraph(fixedLeading); paragraph.add(new Phrase(sb.toString().toUpperCase(), smallfont)); datatable.addCell(paragraph); } else { datatable.addCell(BLANK); } // Add Phone information // Primary Phone datatable.getDefaultCell().setColspan(1); datatable.getDefaultCell().setPaddingLeft(4); datatable.getDefaultCell().setPaddingRight(2); datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_RIGHT); datatable.addCell(new Phrase("Phone:", smallfontB)); datatable.getDefaultCell().setPaddingLeft(2); datatable.getDefaultCell().setPaddingRight(2); datatable.getDefaultCell().setHorizontalAlignment(PdfPTable.ALIGN_LEFT); if (facility.getPrimaryPhone() != null && StringUtils.isNotBlank(facility.getPrimaryPhone().getFormattedPhoneNumber())) { datatable.addCell(new Phrase(facility.getPrimaryPhone().getFormattedPhoneNumber(), smallfont)); } else { datatable.addCell(BLANK); } // Site Phone paragraph = new Paragraph(fixedLeading); paragraph.add(new Phrase("Site Phone: ", smallfontB)); if (facility.getAlternatePhone() != null && StringUtils.isNotBlank(facility.getAlternatePhone().getFormattedPhoneNumber())) { paragraph.add(new Phrase(facility.getAlternatePhone().getFormattedPhoneNumber(), smallfont)); } datatable.getDefaultCell().setPaddingLeft(2); datatable.getDefaultCell().setPaddingRight(2); datatable.addCell(paragraph); // Fax paragraph = new Paragraph(fixedLeading); paragraph.add(new Phrase("Fax: ", smallfontB)); if (facility.getFax() != null && StringUtils.isNotBlank(facility.getFax().getFormattedPhoneNumber())) { paragraph.add(new Phrase(facility.getFax().getFormattedPhoneNumber(), smallfont)); } datatable.getDefaultCell().setPaddingRight(4); datatable.addCell(paragraph); return datatable; }