List of usage examples for com.itextpdf.text.pdf PdfPCell setColspan
public void setColspan(int colspan)
From source file:fc.extensions.itext.Writer.java
License:MIT License
public void addCell(PdfPTable table, String content, int fontSize, float borderWidth, int columnSpan) { PdfPCell pCell = new PdfPCell(); if (columnSpan > 1) { pCell.setColspan(columnSpan); }/*from w ww .ja va 2 s .co m*/ pCell.setBorderWidth(borderWidth); pCell.setPhrase(new Phrase(content, getFont(fontSize))); pCell.setNoWrap(false); pCell.setHorizontalAlignment(PdfContentByte.ALIGN_LEFT); pCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(pCell); }
From source file:fc.extensions.itext.Writer.java
License:MIT License
public void addAnsiCell(PdfPTable table, String content, int fontSize, float borderWidth, int columnSpan) { PdfPCell pCell = new PdfPCell(); if (columnSpan > 1) { pCell.setColspan(columnSpan); }//from w ww .j a va 2 s . c o m pCell.setBorderWidth(borderWidth); pCell.setPhrase(new Phrase(content, getAnsiFont(fontSize))); pCell.setNoWrap(false); pCell.setHorizontalAlignment(PdfContentByte.ALIGN_LEFT); pCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(pCell); }
From source file:femr.ui.controllers.PDFController.java
License:Open Source License
/** * Builds the Assessments Table - The assessment fields for the encounter * * @param tabFieldMultiMap multimap of the encounter's tab fields * @param prescriptionItems a list of the encounter's prescriptions * @param problemItems a list of the encounter's problems * @return PdfPTable the itext table to add to the document *///from www .jav a2s . c o m private PdfPTable getAssessments(TabFieldMultiMap tabFieldMultiMap, List<PrescriptionItem> prescriptionItems, List<ProblemItem> problemItems) { PdfPTable table = getDefaultTable(3); //Set table to span 3 columns to counteract tablesize for dispensed prescriptions table.addCell(getDefaultHeaderCell("Assessments", 3)); // Row 1 PdfPCell cellMSH = new PdfPCell(table.getDefaultCell()); TabFieldItem msh = tabFieldMultiMap.getMostRecentOrEmpty("medicalSurgicalHistory", null); cellMSH.addElement(getStyledPhrase("Medical Surgical History: ", outputStringOrNA(msh.getValue()))); cellMSH.setColspan(3); table.addCell(cellMSH); // Row 2 PdfPCell cellCM = new PdfPCell(table.getDefaultCell()); TabFieldItem cm = tabFieldMultiMap.getMostRecentOrEmpty("currentMedication", null); cellCM.addElement(getStyledPhrase("Medication: ", outputStringOrNA(cm.getValue()))); cellCM.setColspan(3); table.addCell(cellCM); // Row 3 PdfPCell cellSH = new PdfPCell(table.getDefaultCell()); TabFieldItem sh = tabFieldMultiMap.getMostRecentOrEmpty("socialHistory", null); cellSH.addElement(getStyledPhrase("Social History: ", outputStringOrNA(sh.getValue()))); cellSH.setColspan(3); table.addCell(cellSH); // Row 4 PdfPCell cellAssesment = new PdfPCell(table.getDefaultCell()); TabFieldItem assessment = tabFieldMultiMap.getMostRecentOrEmpty("assessment", null); cellAssesment.addElement(getStyledPhrase("Assessment: ", outputStringOrNA(assessment.getValue()))); cellAssesment.setColspan(3); table.addCell(cellAssesment); // Row 5 PdfPCell cellFH = new PdfPCell(table.getDefaultCell()); TabFieldItem fh = tabFieldMultiMap.getMostRecentOrEmpty("familyHistory", null); cellFH.addElement(getStyledPhrase("Family History: ", outputStringOrNA(fh.getValue()))); cellFH.setColspan(3); table.addCell(cellFH); // Row 6 PdfPCell cellTreatment = new PdfPCell(table.getDefaultCell()); TabFieldItem treatment = tabFieldMultiMap.getMostRecentOrEmpty("procedure_counseling", null); cellTreatment.addElement(getStyledPhrase("Procedure/Counseling: ", outputStringOrNA(treatment.getValue()))); cellTreatment.setColspan(3); table.addCell(cellTreatment); // Loop through and add any potential Custom Field Names // Row 7+ , set cells to colspan of 2 so they fill the whole page for (String customField : tabFieldMultiMap.getCustomFieldNameList()) { String value = tabFieldMultiMap.getMostRecentOrEmpty(customField, null).getValue(); PdfPCell customCell = new PdfPCell(table.getDefaultCell()); customCell.setColspan(3); customCell.addElement(getStyledPhrase(customField + " :", outputStringOrNA(value))); table.addCell(customCell); } // AJ Saclayan Dispensed Table Paragraph prescriptionsTitle = new Paragraph("Dispensed Prescription(s):", getTitleFont()); PdfPCell prescriptionCell = new PdfPCell(table.getDefaultCell()); prescriptionCell.setPaddingRight(10); prescriptionCell.addElement(prescriptionsTitle); prescriptionCell.setColspan(3); table.addCell(prescriptionCell); table.completeRow(); if (!prescriptionItems.isEmpty()) { //Create Dispensed Table. Paragraph originalMedsTitle = new Paragraph("Original", getTitleFont()); PdfPCell cell = new PdfPCell(originalMedsTitle); table.addCell(cell); Paragraph replacedMedsTitle = new Paragraph("Replacement", getTitleFont()); cell = new PdfPCell(replacedMedsTitle); table.addCell(cell); table.completeRow(); for (PrescriptionItem prescription : prescriptionItems) { String medicationForm = prescription.getMedicationForm(); if (medicationForm == null || medicationForm.equals("")) { medicationForm = "N/A"; } else { medicationForm = medicationForm.trim(); } if (prescription.getReplacementMedicationName() != null) { Paragraph originalMedName = new Paragraph( "Prescription #" + prescription.getId() + " - Replaced \n" + prescription.getAmount() + " " + prescription.getName() + " (" + medicationForm + ")", getValueFont()); cell = new PdfPCell(originalMedName); table.addCell(cell); Paragraph replacedMedName = new Paragraph("Prescription #" + prescription.getReplacementId() + " \n" + prescription.getReplacementAmount() + " " + prescription.getReplacementMedicationName(), getValueFont()); cell = new PdfPCell(replacedMedName); table.addCell(cell); } else { Paragraph medName = new Paragraph("Prescription #" + prescription.getId() + "\n" + prescription.getAmount() + " " + prescription.getName() + " (" + medicationForm + ")", getValueFont()); cell = new PdfPCell(medName); table.addCell(cell); Paragraph blankCell = new Paragraph(" ", getValueFont()); cell = new PdfPCell(blankCell); table.addCell(cell); } table.completeRow(); } } // Get Problems Paragraph problemsTitle = new Paragraph("Problem(s):", getTitleFont()); PdfPCell problemsCell = new PdfPCell(table.getDefaultCell()); problemsCell.addElement(problemsTitle); for (ProblemItem problem : problemItems) { Paragraph probText = new Paragraph(" - " + problem.getName(), getValueFont()); problemsCell.addElement(probText); } table.addCell(problemsCell); table.completeRow(); return table; }
From source file:femr.ui.controllers.PDFController.java
License:Open Source License
/** * Adds the fields for the cheif complaint to the passed in table * * @param table the PdfPTable object to add the rows to * @param chiefComplaint the chief complaint as a string or null * @param tabFieldMultiMap multimap of the encounter's tab fields *//*from www .j a v a2s . c o m*/ private void addChiefComplaintSectionToTable(PdfPTable table, String chiefComplaint, TabFieldMultiMap tabFieldMultiMap) { PdfPCell cellCC = new PdfPCell(table.getDefaultCell()); cellCC.addElement(getStyledPhrase("Chief Complaint: ", outputStringOrNA(chiefComplaint))); cellCC.setColspan(2); table.addCell(cellCC); // Known Field Names // Put styled phrase into a cell, then add it to the table PdfPCell onsetC = new PdfPCell(table.getDefaultCell()); onsetC.addElement(getStyledPhrase("Onset: ", outputStringOrNA(tabFieldMultiMap.getMostRecentOrEmpty("onset", chiefComplaint).getValue()))); table.addCell(onsetC); PdfPCell fieldCell = new PdfPCell(table.getDefaultCell()); fieldCell.setPaddingRight(5); fieldCell.addElement(getStyledPhrase("Quality: ", outputStringOrNA(tabFieldMultiMap.getMostRecentOrEmpty("quality", chiefComplaint).getValue()))); table.addCell(fieldCell); fieldCell = new PdfPCell(table.getDefaultCell()); fieldCell.setPaddingRight(5); fieldCell.addElement(getStyledPhrase("Severity: ", outputStringOrNA(tabFieldMultiMap.getMostRecentOrEmpty("severity", chiefComplaint).getValue()))); table.addCell(fieldCell); fieldCell = new PdfPCell(table.getDefaultCell()); fieldCell.setPaddingRight(5); fieldCell.addElement(getStyledPhrase("Provokes: ", outputStringOrNA(tabFieldMultiMap.getMostRecentOrEmpty("provokes", chiefComplaint).getValue()))); table.addCell(fieldCell); fieldCell = new PdfPCell(table.getDefaultCell()); fieldCell.setPaddingRight(5); fieldCell.addElement(getStyledPhrase("Palliates: ", outputStringOrNA(tabFieldMultiMap.getMostRecentOrEmpty("palliates", chiefComplaint).getValue()))); table.addCell(fieldCell); fieldCell = new PdfPCell(table.getDefaultCell()); fieldCell.setPaddingRight(5); fieldCell.addElement(getStyledPhrase("TimeOfDay: ", outputStringOrNA(tabFieldMultiMap.getMostRecentOrEmpty("timeOfDay", chiefComplaint).getValue()))); table.addCell(fieldCell); fieldCell = new PdfPCell(table.getDefaultCell()); fieldCell.setPaddingRight(5); fieldCell.addElement(getStyledPhrase("Radiation: ", outputStringOrNA(tabFieldMultiMap.getMostRecentOrEmpty("radiation", chiefComplaint).getValue()))); table.addCell(fieldCell); // Physical Examination PdfPCell cellPE = new PdfPCell(table.getDefaultCell()); TabFieldItem fieldItem = tabFieldMultiMap.getMostRecentOrEmpty("physicalExamination", chiefComplaint); cellPE.addElement(getStyledPhrase("Physical Examination: ", outputStringOrNA(fieldItem.getValue()))); cellPE.setColspan(2); table.addCell(cellPE); // Narrative PdfPCell cellNarrative = new PdfPCell(table.getDefaultCell()); fieldItem = tabFieldMultiMap.getMostRecentOrEmpty("narrative", chiefComplaint); cellNarrative.addElement(getStyledPhrase("Narrative: ", outputStringOrNA(fieldItem.getValue()))); cellNarrative.setColspan(2); table.addCell(cellNarrative); // add an empty row to add spacing between chief complaints table.addCell(" "); table.completeRow(); }
From source file:femr.ui.controllers.PDFController.java
License:Open Source License
/** * Builds the Header Cell used for every section of the document * * @param title the title for the cell//from w w w . jav a 2 s.com * @param colspan the number of columns in the table it will be added to * @return a formatted PdfPCell ready to insert into a PdfPTable */ private PdfPCell getDefaultHeaderCell(String title, int colspan) { PdfPCell cell = new PdfPCell(); Paragraph titleParagraph = new Paragraph(title, new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK)); cell.addElement(titleParagraph); cell.setBorder(PdfPCell.NO_BORDER); cell.setColspan(colspan); cell.setBorderColorBottom(BaseColor.DARK_GRAY); cell.setBorderWidthBottom(1); cell.setPaddingBottom(5); return cell; }
From source file:fenix.planner.pdf.PDFGenerator.java
License:Open Source License
private void createAndAddEventTable() throws DocumentException { PdfPTable table = new PdfPTable(new float[] { 1, 7, 1.2f }); table.setWidthPercentage(100f);/*from ww w . j a v a2s . c o m*/ table.getDefaultCell().setUseAscender(true); table.getDefaultCell().setUseDescender(true); table.setSpacingBefore(20); table.setSpacingAfter(20); // Header row table.getDefaultCell().setBorderWidthLeft(0); table.getDefaultCell().setBorderWidthTop(0); table.getDefaultCell().setBorderWidthRight(0); table.getDefaultCell().setPadding(5); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(new Phrase("Datum", headerFont)); table.addCell(new Phrase("mne", headerFont)); table.addCell(new Phrase("Ansvarig", headerFont)); table.setHeaderRows(1); table.getDefaultCell().setBackgroundColor(null); // Events for (Event event : program.getSortedCopyOfEvents()) { if (event.getDate().getMonthOfYear() % 2 == 0) { table.getDefaultCell().setBackgroundColor(new BaseColor(0xdd, 0xdd, 0xdd)); } else { table.getDefaultCell().setBackgroundColor(null); } if (!event.getType().getBackgroundColor().equals(Color.WHITE)) { table.getDefaultCell() .setBackgroundColor(awtColorToBaseColor(event.getType().getBackgroundColor())); } final BaseColor textColor = awtColorToBaseColor(event.getType().getForegroundColor()); PdfPCell dateCell = new PdfPCell(table.getDefaultCell()); dateCell.addElement( new Phrase(event.getDate().toString("dd.MM", locale), changeColor(subjectFont, textColor))); table.addCell(dateCell); PdfPCell subjectCell = new PdfPCell(table.getDefaultCell()); subjectCell.addElement(new Phrase(event.getSubject(), changeColor(subjectFont, textColor))); if (event.getDescription().length() > 0) { subjectCell.addElement(new Phrase(event.getDescription(), changeColor(descriptionFont, textColor))); } if (event.getOrganizer() == null) { subjectCell.setColspan(2); } table.addCell(subjectCell); if (event.getOrganizer() != null) { PdfPCell organizerCell = new PdfPCell(table.getDefaultCell()); organizerCell.addElement( new Phrase(event.getOrganizer().getInitials(), changeColor(subjectFont, textColor))); table.addCell(organizerCell); } } document.add(table); }
From source file:fll.scheduler.TournamentSchedule.java
License:Open Source License
/** * Output the schedule sorted by team number. This schedule looks much like * the input spreadsheet./*from w w w . ja v a 2s . c o m*/ * * @param stream where to write the schedule * @throws DocumentException */ public void outputScheduleByTeam(final OutputStream stream) throws DocumentException { final Document pdf = PdfUtils.createLandscapePdfDoc(stream, new SimpleFooterHandler()); final int numColumns = 5 + subjectiveStations.size() + getNumberOfRounds() * 2; final PdfPTable table = PdfUtils.createTable(numColumns); final float[] columnWidths = new float[numColumns]; int idx = 0; columnWidths[idx] = 2; // team number ++idx; columnWidths[idx] = 3; // team name ++idx; columnWidths[idx] = 3; // organization ++idx; columnWidths[idx] = 2; // judging group ++idx; columnWidths[idx] = 2; // division ++idx; for (int i = 0; i < subjectiveStations.size(); ++i) { columnWidths[idx] = 2; // time ++idx; } for (int i = 0; i < getNumberOfRounds(); ++i) { columnWidths[idx] = 2; // time ++idx; columnWidths[idx] = 2; // table ++idx; } table.setWidths(columnWidths); final PdfPCell tournamentCell = PdfUtils.createHeaderCell("Tournament: " + getName()); tournamentCell.setColspan(numColumns); table.addCell(tournamentCell); table.addCell(PdfUtils.createHeaderCell(TEAM_NUMBER_HEADER)); table.addCell(PdfUtils.createHeaderCell(TEAM_NAME_HEADER)); table.addCell(PdfUtils.createHeaderCell(ORGANIZATION_HEADER)); table.addCell(PdfUtils.createHeaderCell(JUDGE_GROUP_HEADER)); table.addCell(PdfUtils.createHeaderCell(AWARD_GROUP_HEADER)); for (final String subjectiveStation : subjectiveStations) { table.addCell(PdfUtils.createHeaderCell(subjectiveStation)); } for (int round = 0; round < getNumberOfRounds(); ++round) { table.addCell(PdfUtils.createHeaderCell(String.format(PERF_HEADER_FORMAT, round + 1))); table.addCell(PdfUtils.createHeaderCell(String.format(TABLE_HEADER_FORMAT, round + 1))); } table.setHeaderRows(2); Collections.sort(_schedule, ComparatorByTeam.INSTANCE); for (final TeamScheduleInfo si : _schedule) { table.addCell(PdfUtils.createCell(String.valueOf(si.getTeamNumber()))); table.addCell(PdfUtils.createCell(si.getTeamName())); table.addCell(PdfUtils.createCell(si.getOrganization())); table.addCell(PdfUtils.createCell(si.getJudgingGroup())); table.addCell(PdfUtils.createCell(si.getAwardGroup())); for (final String subjectiveStation : subjectiveStations) { table.addCell( PdfUtils.createCell(formatTime(si.getSubjectiveTimeByName(subjectiveStation).getTime()))); } for (int round = 0; round < getNumberOfRounds(); ++round) { final PerformanceTime perf = si.getPerf(round); table.addCell(PdfUtils.createCell(formatTime(perf.getTime()))); table.addCell(PdfUtils.createCell(String.format("%s %s", perf.getTable(), perf.getSide()))); } } pdf.add(table); pdf.close(); }
From source file:fll.scheduler.TournamentSchedule.java
License:Open Source License
private void outputPerformanceSchedule(final Document detailedSchedules) throws DocumentException { final SortedMap<PerformanceTime, TeamScheduleInfo> performanceTimes = new TreeMap<PerformanceTime, TeamScheduleInfo>(); for (int round = 0; round < getNumberOfRounds(); ++round) { for (final TeamScheduleInfo si : _schedule) { performanceTimes.put(si.getPerf(round), si); }//from www. ja v a2 s . c o m } // list of teams staying around to even up the teams final List<TeamScheduleInfo> teamsStaying = new LinkedList<TeamScheduleInfo>(); final PdfPTable table = PdfUtils.createTable(7); table.setWidths(new float[] { 2, 1, 3, 3, 2, 2, 2 }); final PdfPCell tournamentCell = PdfUtils.createHeaderCell("Tournament: " + getName() + " Performance"); tournamentCell.setColspan(7); table.addCell(tournamentCell); table.addCell(PdfUtils.createHeaderCell(TEAM_NUMBER_HEADER)); table.addCell(PdfUtils.createHeaderCell(DIVISION_HEADER)); table.addCell(PdfUtils.createHeaderCell(ORGANIZATION_HEADER)); table.addCell(PdfUtils.createHeaderCell(TEAM_NAME_HEADER)); table.addCell(PdfUtils.createHeaderCell("Time")); table.addCell(PdfUtils.createHeaderCell("Table")); table.addCell(PdfUtils.createHeaderCell("Round")); table.setHeaderRows(1); for (final Map.Entry<PerformanceTime, TeamScheduleInfo> entry : performanceTimes.entrySet()) { final PerformanceTime performance = entry.getKey(); final TeamScheduleInfo si = entry.getValue(); final int round = si.computeRound(performance); // check if team needs to stay and color the cell magenta if they do final BaseColor backgroundColor; if (null != checkIfTeamNeedsToStay(si, round)) { teamsStaying.add(si); backgroundColor = BaseColor.MAGENTA; } else { backgroundColor = null; } table.addCell(PdfUtils.createCell(String.valueOf(si.getTeamNumber()))); table.addCell(PdfUtils.createCell(si.getAwardGroup())); table.addCell(PdfUtils.createCell(si.getOrganization())); table.addCell(PdfUtils.createCell(si.getTeamName())); table.addCell(PdfUtils.createCell(formatTime(si.getPerfTime(round)), backgroundColor)); table.addCell(PdfUtils.createCell(si.getPerfTableColor(round) + " " + si.getPerfTableSide(round), backgroundColor)); table.addCell(PdfUtils.createCell(String.valueOf(round + 1))); } detailedSchedules.add(table); // output teams staying if (!teamsStaying.isEmpty()) { final String formatString = "Team %d will please stay at the table and compete again - score will not count."; final PdfPTable stayingTable = PdfUtils.createTable(1); for (final TeamScheduleInfo si : teamsStaying) { stayingTable.addCell(PdfUtils.createCell( new Formatter().format(formatString, si.getTeamNumber()).toString(), BaseColor.MAGENTA)); } detailedSchedules.add(stayingTable); } detailedSchedules.add(Chunk.NEXTPAGE); }
From source file:fll.scheduler.TournamentSchedule.java
License:Open Source License
private void outputSubjectiveScheduleByDivision(final Document detailedSchedules, final String subjectiveStation) throws DocumentException { final PdfPTable table = PdfUtils.createTable(6); table.setWidths(new float[] { 2, 1, 3, 3, 2, 2 }); final PdfPCell tournamentCell = PdfUtils .createHeaderCell("Tournament: " + getName() + " - " + subjectiveStation); tournamentCell.setColspan(6); table.addCell(tournamentCell);//from w w w . j av a 2 s. c om table.addCell(PdfUtils.createHeaderCell(TEAM_NUMBER_HEADER)); table.addCell(PdfUtils.createHeaderCell(AWARD_GROUP_HEADER)); table.addCell(PdfUtils.createHeaderCell(ORGANIZATION_HEADER)); table.addCell(PdfUtils.createHeaderCell(TEAM_NAME_HEADER)); table.addCell(PdfUtils.createHeaderCell(subjectiveStation)); table.addCell(PdfUtils.createHeaderCell(JUDGE_GROUP_HEADER)); table.setHeaderRows(2); Collections.sort(_schedule, getComparatorForSubjectiveByDivision(subjectiveStation)); for (final TeamScheduleInfo si : _schedule) { table.addCell(PdfUtils.createCell(String.valueOf(si.getTeamNumber()))); table.addCell(PdfUtils.createCell(si.getAwardGroup())); table.addCell(PdfUtils.createCell(si.getOrganization())); table.addCell(PdfUtils.createCell(si.getTeamName())); table.addCell(PdfUtils.createCell(formatTime(si.getSubjectiveTimeByName(subjectiveStation).getTime()))); table.addCell(PdfUtils.createCell(si.getJudgingGroup())); } detailedSchedules.add(table); }
From source file:fll.scheduler.TournamentSchedule.java
License:Open Source License
private void outputSubjectiveScheduleByTime(final Document detailedSchedules, final String subjectiveStation) throws DocumentException { final PdfPTable table = PdfUtils.createTable(6); table.setWidths(new float[] { 2, 1, 3, 3, 2, 2 }); final PdfPCell tournamentCell = PdfUtils .createHeaderCell("Tournament: " + getName() + " - " + subjectiveStation); tournamentCell.setColspan(6); table.addCell(tournamentCell);//from w w w . j a v a 2 s.co m table.addCell(PdfUtils.createHeaderCell(TEAM_NUMBER_HEADER)); table.addCell(PdfUtils.createHeaderCell(AWARD_GROUP_HEADER)); table.addCell(PdfUtils.createHeaderCell(ORGANIZATION_HEADER)); table.addCell(PdfUtils.createHeaderCell(TEAM_NAME_HEADER)); table.addCell(PdfUtils.createHeaderCell(subjectiveStation)); table.addCell(PdfUtils.createHeaderCell(JUDGE_GROUP_HEADER)); table.setHeaderRows(2); Collections.sort(_schedule, getComparatorForSubjectiveByTime(subjectiveStation)); for (final TeamScheduleInfo si : _schedule) { table.addCell(PdfUtils.createCell(String.valueOf(si.getTeamNumber()))); table.addCell(PdfUtils.createCell(si.getAwardGroup())); table.addCell(PdfUtils.createCell(si.getOrganization())); table.addCell(PdfUtils.createCell(si.getTeamName())); table.addCell(PdfUtils.createCell(formatTime(si.getSubjectiveTimeByName(subjectiveStation).getTime()))); table.addCell(PdfUtils.createCell(si.getJudgingGroup())); } detailedSchedules.add(table); }