List of usage examples for com.itextpdf.text.pdf PdfPTable addCell
public void addCell(final Phrase phrase)
From source file:be.kcbj.placemat.Placemat.java
License:Open Source License
private void createPdf(File file, List<Sponsor> sponsors) throws IOException, DocumentException { System.out.println("Generating PDF file " + file.getAbsolutePath()); Layout layout = new Layout(sponsors); System.out.println("Layout = " + layout); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.setPageSize(PageSize.A4.rotate()); document.setMargins(PADDING_DOC, PADDING_DOC, PADDING_DOC, PADDING_DOC); document.open();//from ww w .jav a 2 s .c om PdfPTable table = new PdfPTable(layout.getColumnCount()); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.setSpacingAfter(0f); for (int i = 0; i < sponsors.size(); i++) { table.addCell(generateCell(sponsors.get(i), layout.getCellHeight())); } for (int i = 0; i < layout.getEmptyCellCount(); i++) { table.addCell(generateCell(new Sponsor(), layout.getCellHeight())); } document.add(table); document.close(); }
From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java
protected void printMedication(SessionContainerWO sessionContainerWO) { try {/*from w ww . ja va2 s . co m*/ doc.add(new Paragraph(" ")); table = new PdfPTable(2); table.setWidthPercentage(100); // main title cell = new PdfPCell(new Paragraph(getTran("curative", "medication.status.title").toUpperCase(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(2); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell); Vector chronicMedications = ChronicMedication.find(patient.personid, "", "", "", "OC_CHRONICMED_BEGIN", "ASC"), activePrescriptions = Prescription.getActivePrescriptions(patient.personid); //*** CHRONIC MEDICATION ****************************************** if (chronicMedications.size() > 0) { PdfPTable medicationTable = new PdfPTable(2); // sub title cell = new PdfPCell(new Paragraph(getTran("curative", "medication.chronic"), FontFactory.getFont( FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(2); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_LEFT); cell.setBackgroundColor(BGCOLOR_LIGHT); medicationTable.addCell(cell); // run thru medications String sPrescrRule, sProductUnit, timeUnitTran; ChronicMedication medication; for (int n = 0; n < chronicMedications.size(); n++) { medication = (ChronicMedication) chronicMedications.elementAt(n); sPrescrRule = getTran("web.prescriptions", "prescriptionrule"); sPrescrRule = sPrescrRule.replaceAll("#unitspertimeunit#", medication.getUnitsPerTimeUnit() + ""); // productunits if (medication.getUnitsPerTimeUnit() == 1) { sProductUnit = getTran("product.unit", medication.getProduct().getUnit()); } else { sProductUnit = getTran("product.units", medication.getProduct().getUnit()); } sPrescrRule = sPrescrRule.replaceAll("#productunit#", sProductUnit.toLowerCase()); // timeunits if (medication.getTimeUnitCount() == 1) { sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#", ""); timeUnitTran = getTran("prescription.timeunit", medication.getTimeUnit()); } else { sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#", medication.getTimeUnitCount() + ""); timeUnitTran = getTran("prescription.timeunits", medication.getTimeUnit()); } sPrescrRule = sPrescrRule.replaceAll("#timeunit#", timeUnitTran.replaceAll(" ", " ").toLowerCase()); // product name cell = new PdfPCell(new Paragraph(medication.getProduct().getName(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); cell.setColspan(1); cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP + PdfPCell.BOTTOM); // no right border cell.setBorderColor(BaseColor.LIGHT_GRAY); medicationTable.addCell(cell); // prescription rule cell = new PdfPCell(new Paragraph(sPrescrRule, FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(1); cell.setBorder(PdfPCell.RIGHT + PdfPCell.TOP + PdfPCell.BOTTOM); // no left border cell.setBorderColor(BaseColor.LIGHT_GRAY); medicationTable.addCell(cell); } // add cells to make up with the chronic medications if (chronicMedications.size() < activePrescriptions.size()) { int missingCellCount = activePrescriptions.size() - chronicMedications.size(); for (int i = 0; i < missingCellCount; i++) { cell = new PdfPCell(); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); medicationTable.addCell(cell); } } // add chronicmedicationtables to medicationtable cell = new PdfPCell(medicationTable); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setPadding(3); table.addCell(cell); } //*** PRESCRIPTIONS *********************************************** if (activePrescriptions.size() > 0) { PdfPTable medicationTable = new PdfPTable(2); // sub title cell = new PdfPCell(new Paragraph(getTran("curative", "medication.prescription"), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(2); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_LEFT); cell.setBackgroundColor(BGCOLOR_LIGHT); medicationTable.addCell(cell); // run thru medications String sPrescrRule, sProductUnit, timeUnitTran; Prescription prescription; int n; for (n = 0; n < activePrescriptions.size(); n++) { prescription = (Prescription) activePrescriptions.elementAt(n); sPrescrRule = getTran("web.prescriptions", "prescriptionrule"); sPrescrRule = sPrescrRule.replaceAll("#unitspertimeunit#", prescription.getUnitsPerTimeUnit() + ""); // productunits if (prescription.getUnitsPerTimeUnit() == 1) { sProductUnit = getTran("product.unit", prescription.getProduct().getUnit()); } else { sProductUnit = getTran("product.units", prescription.getProduct().getUnit()); } sPrescrRule = sPrescrRule.replaceAll("#productunit#", sProductUnit.toLowerCase()); // timeunits if (prescription.getTimeUnitCount() == 1) { sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#", ""); timeUnitTran = getTran("prescription.timeunit", prescription.getTimeUnit()); } else { sPrescrRule = sPrescrRule.replaceAll("#timeunitcount#", prescription.getTimeUnitCount() + ""); timeUnitTran = getTran("prescription.timeunits", prescription.getTimeUnit()); } sPrescrRule = sPrescrRule.replaceAll("#timeunit#", timeUnitTran.toLowerCase()); // product name cell = new PdfPCell(new Paragraph(prescription.getProduct().getName(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); cell.setColspan(1); cell.setBorder(PdfPCell.LEFT + PdfPCell.TOP + PdfPCell.BOTTOM); // no right border cell.setBorderColor(BaseColor.LIGHT_GRAY); medicationTable.addCell(cell); // prescription rule cell = new PdfPCell(new Paragraph(sPrescrRule, FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(1); cell.setBorder(PdfPCell.RIGHT + PdfPCell.TOP + PdfPCell.BOTTOM); // no left border cell.setBorderColor(BaseColor.LIGHT_GRAY); medicationTable.addCell(cell); } // add cells to make up with the active prescriptions if (activePrescriptions.size() < chronicMedications.size()) { int missingCellCount = chronicMedications.size() - activePrescriptions.size(); for (int i = 0; i < missingCellCount; i++) { cell = new PdfPCell(); cell.setColspan(2); cell.setBorder(PdfPCell.NO_BORDER); medicationTable.addCell(cell); } } // add presciptionssstable to medicationtable cell = new PdfPCell(medicationTable); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setPadding(3); table.addCell(cell); doc.add(table); } } catch (Exception e) { e.printStackTrace(); } }
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
private void addDisciplinaryRecordDetails(PdfPTable table, DisciplinaryRecord disRec) { if (disRec.followUp.length() > 0) { PdfPTable detailsTable = new PdfPTable(10); detailsTable.setWidthPercentage(100); // follow-up in grey and italic //detailsTable.addCell(createValueCell(disRec.followUp.replaceAll("\r\n"," "),10)); Font font = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.ITALIC); font.setColor(BaseColor.GRAY);/*w w w . j a v a 2 s. c om*/ cell = new PdfPCell(new Paragraph(disRec.followUp.replaceAll("\r\n", " "), font)); cell.setColspan(10); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(innerBorderColor); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); detailsTable.addCell(cell); table.addCell(createCell(new PdfPCell(detailsTable), table.getNumberOfColumns(), PdfPCell.ALIGN_CENTER, PdfPCell.BOX)); } }
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
private void addLeaveDetails(PdfPTable table, Leave leave) { if (leave.comment.length() > 0) { PdfPTable detailsTable = new PdfPTable(10); detailsTable.setWidthPercentage(100); // follow-up in grey and italic //detailsTable.addCell(createValueCell(leave.comment.replaceAll("\r\n"," "),10)); Font font = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.ITALIC); font.setColor(BaseColor.GRAY);/*from www .j a v a 2 s . c om*/ cell = new PdfPCell(new Paragraph(leave.comment.replaceAll("\r\n", " "), font)); cell.setColspan(10); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(innerBorderColor); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); detailsTable.addCell(cell); table.addCell(createCell(new PdfPCell(detailsTable), table.getNumberOfColumns(), PdfPCell.ALIGN_CENTER, PdfPCell.BOX)); } }
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
private void addContractDetails(PdfPTable table, Contract contract) { PdfPTable detailsTable = new PdfPTable(10); detailsTable.setWidthPercentage(100); if (contract.getLegalReferenceCode(1).length() > 0 || contract.getLegalReferenceCode(2).length() > 0 || contract.getLegalReferenceCode(3).length() > 0 || contract.getLegalReferenceCode(4).length() > 0 || contract.getLegalReferenceCode(5).length() > 0) { //detailsTable.addCell(createSubtitleCell(getTran("web.hr","legalReferenceCodes"),10)); // one LRC for (int i = 0; i < 4; i++) { if (contract.getLegalReferenceCode(i + 1).length() > 0) { detailsTable .addCell(createValueCell(getTran("web.hr", "legalReferenceCode") + " " + (i + 1), 4)); detailsTable.addCell(createValueCell(contract.getLegalReferenceCode(i + 1), 6)); }// w ww .ja v a2 s . co m } } if (detailsTable.size() > 0) { table.addCell(emptyCell(2)); cell = createCell(new PdfPCell(detailsTable), table.getNumberOfColumns() - 2, PdfPCell.ALIGN_CENTER, PdfPCell.BOX); cell.setPadding(2); table.addCell(cell); } }
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
private void addCareerDetails(PdfPTable table, Career career) { if (career.comment.length() > 0) { PdfPTable detailsTable = new PdfPTable(10); detailsTable.setWidthPercentage(100); // comment in grey and italic //detailsTable.addCell(createValueCell(career.comment.replaceAll("\r\n"," "),10)); Font font = FontFactory.getFont(FontFactory.HELVETICA, 7, Font.ITALIC); font.setColor(BaseColor.GRAY);//from ww w . java 2s. c o m cell = new PdfPCell(new Paragraph(career.comment.replaceAll("\r\n", " "), font)); cell.setColspan(10); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(innerBorderColor); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT); detailsTable.addCell(cell); table.addCell(createCell(new PdfPCell(detailsTable), table.getNumberOfColumns(), PdfPCell.ALIGN_CENTER, PdfPCell.BOX)); } }
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
private void addSalaryDetails(PdfPTable table, Salary salary) { PdfPTable detailsTable = new PdfPTable(10); detailsTable.setWidthPercentage(100); //*** XML 1 - benefits (multi-add) ************************** if (salary.benefits.length() > 0) { detailsTable.addCell(createSubtitleCell(getTran("web.hr", "benefits"), 10)); // header detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3)); try {/* w ww.j a va 2 s.c om*/ // parse benefits from xml SAXReader reader = new SAXReader(false); org.dom4j.Document document = reader.read(new StringReader(salary.benefits)); org.dom4j.Element benefitsElem = document.getRootElement(); if (benefitsElem != null) { String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount; org.dom4j.Element benefitElem; Iterator benefitsIter = benefitsElem.elementIterator("Benefit"); while (benefitsIter.hasNext()) { benefitElem = (org.dom4j.Element) benefitsIter.next(); sTmpBegin = checkString(benefitElem.elementText("Begin")); sTmpEnd = checkString(benefitElem.elementText("End")); sTmpPeriod = checkString(benefitElem.elementText("Period")); sTmpType = checkString(benefitElem.elementText("Type")); sTmpAmount = checkString(benefitElem.elementText("Amount")); // one benefit detailsTable.addCell(createValueCell(sTmpBegin, 1)); detailsTable.addCell(createValueCell(sTmpEnd, 1)); detailsTable.addCell(createValueCell(getTran("hr.salary.period", sTmpPeriod), 2)); detailsTable.addCell(createValueCell(getTran("hr.salary.benefit.type", sTmpType), 3)); cell = createValueCell( sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); detailsTable.addCell(cell); } } } catch (Exception e) { Debug.printStackTrace(e); } } //*** XML 2 - bonuses (multi-add) ************************** if (salary.bonuses.length() > 0) { table.addCell(createSubtitleCell(getTran("web.hr", "bonuses"), 10)); // header detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 2)); detailsTable.addCell(createHeaderCell(getTran("web", "percentage"), 2)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 2)); try { // parse bonuses from xml SAXReader reader = new SAXReader(false); org.dom4j.Document document = reader.read(new StringReader(salary.bonuses)); org.dom4j.Element bonusesElem = document.getRootElement(); if (bonusesElem != null) { String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpPercentage, sTmpAmount; org.dom4j.Element bonusElem; Iterator bonusesIter = bonusesElem.elementIterator("Bonus"); while (bonusesIter.hasNext()) { bonusElem = (org.dom4j.Element) bonusesIter.next(); sTmpBegin = checkString(bonusElem.elementText("Begin")); sTmpEnd = checkString(bonusElem.elementText("End")); sTmpPeriod = checkString(bonusElem.elementText("Period")); sTmpType = checkString(bonusElem.elementText("Type")); sTmpPercentage = checkString(bonusElem.elementText("Percentage")); sTmpAmount = checkString(bonusElem.elementText("Amount")); // one record detailsTable.addCell(createValueCell(sTmpBegin, 1)); detailsTable.addCell(createValueCell(sTmpEnd, 1)); detailsTable.addCell(createValueCell(sTmpPeriod, 2)); detailsTable.addCell(createValueCell(sTmpType, 2)); detailsTable.addCell(createValueCell(sTmpPercentage + "%", 2)); cell = createValueCell( sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 2); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); detailsTable.addCell(cell); } } } catch (Exception e) { Debug.printStackTrace(e); } } //*** XML 3 - otherIncome (multi-add) *********************** if (salary.otherIncome.length() > 0) { table.addCell(createSubtitleCell(getTran("web.hr", "otherIncome"), 10)); // header detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3)); try { // parse otherIncome from xml SAXReader reader = new SAXReader(false); org.dom4j.Document document = reader.read(new StringReader(salary.otherIncome)); org.dom4j.Element benefitsElem = document.getRootElement(); if (benefitsElem != null) { String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount; org.dom4j.Element otherIncomeElem; Iterator otherIncomesIter = benefitsElem.elementIterator("OtherIncome"); while (otherIncomesIter.hasNext()) { otherIncomeElem = (org.dom4j.Element) otherIncomesIter.next(); sTmpBegin = checkString(otherIncomeElem.elementText("Begin")); sTmpEnd = checkString(otherIncomeElem.elementText("End")); sTmpPeriod = checkString(otherIncomeElem.elementText("Period")); sTmpType = checkString(otherIncomeElem.elementText("Type")); sTmpAmount = checkString(otherIncomeElem.elementText("Amount")); // one record detailsTable.addCell(createValueCell(sTmpBegin, 1)); detailsTable.addCell(createValueCell(sTmpEnd, 1)); detailsTable.addCell(createValueCell(sTmpPeriod, 2)); detailsTable.addCell(createValueCell(sTmpType, 3)); cell = createValueCell( sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); detailsTable.addCell(cell); } } } catch (Exception e) { Debug.printStackTrace(e); } } //*** XML 4 - deductions (multi-add) ************************ if (salary.deductions.length() > 0) { detailsTable.addCell(createSubtitleCell(getTran("web.hr", "deductions"), 10)); // header detailsTable.addCell(createHeaderCell(getTran("web.hr", "beginDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "endDate"), 1)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "period"), 2)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "type"), 3)); detailsTable.addCell(createHeaderCell(getTran("web.hr", "amount"), 3)); try { // parse deductions from xml SAXReader reader = new SAXReader(false); org.dom4j.Document document = reader.read(new StringReader(salary.deductions)); org.dom4j.Element deductionsElem = document.getRootElement(); if (deductionsElem != null) { String sTmpBegin, sTmpEnd, sTmpPeriod, sTmpType, sTmpAmount; org.dom4j.Element deductionElem; Iterator deductionsIter = deductionsElem.elementIterator("Deduction"); while (deductionsIter.hasNext()) { deductionElem = (org.dom4j.Element) deductionsIter.next(); sTmpBegin = checkString(deductionElem.elementText("Begin")); sTmpEnd = checkString(deductionElem.elementText("End")); sTmpPeriod = checkString(deductionElem.elementText("Period")); sTmpType = checkString(deductionElem.elementText("Type")); sTmpAmount = checkString(deductionElem.elementText("Amount")); // one record detailsTable.addCell(createValueCell(sTmpBegin, 1)); detailsTable.addCell(createValueCell(sTmpEnd, 1)); detailsTable.addCell(createValueCell(sTmpPeriod, 2)); detailsTable.addCell(createValueCell(sTmpType, 3)); cell = createValueCell( sTmpAmount + " " + MedwanQuery.getInstance().getConfigParam("currency", ""), 3); cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); detailsTable.addCell(cell); } } } catch (Exception e) { Debug.printStackTrace(e); } } if (detailsTable.size() > 0) { table.addCell(emptyCell(3)); cell = createCell(new PdfPCell(detailsTable), table.getNumberOfColumns() - 3, PdfPCell.ALIGN_CENTER, PdfPCell.BOX); cell.setPadding(2); table.addCell(cell); } }
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
private void addWorkscheduleDetails(PdfPTable table, Workschedule schedule) throws Exception { PdfPTable detailsTable = new PdfPTable(10); detailsTable.setWidthPercentage(100); if (schedule.type.equals("day")) displayDaySchedule(detailsTable, schedule); else if (schedule.type.equals("week")) displayWeekSchedule(detailsTable, schedule); else if (schedule.type.equals("month")) displayMonthSchedule(detailsTable, schedule); if (detailsTable.size() > 0) { cell = createCell(new PdfPCell(detailsTable), table.getNumberOfColumns(), PdfPCell.ALIGN_CENTER, PdfPCell.BOX);/*from w ww .j ava 2 s .com*/ cell.setPadding(2); table.addCell(cell); } }
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
private void displayDaySchedule(PdfPTable table, Workschedule schedule) { table.addCell(createValueCell(getDayScheduleDetails(schedule), 10)); }
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
private void displayMonthSchedule(PdfPTable table, Workschedule schedule) { table.addCell(createValueCell(getMonthScheduleDetails(schedule), 10)); }