List of usage examples for com.itextpdf.text.pdf PdfPTable setHeaderRows
public void setHeaderRows(int headerRows)
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);//from w w w. j av a 2 s . c om table.addCell(tournamentCell); 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);/* ww w . ja v a 2 s . c om*/ table.addCell(tournamentCell); 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); }
From source file:fll.web.report.CategoryScoresByScoreGroup.java
License:Open Source License
private void createHeader(final PdfPTable table, final String challengeTitle, final String catTitle, final String division, final String judgingGroup, final Tournament tournament) throws BadElementException { final PdfPCell tournamentCell = PdfUtils .createHeaderCell(String.format("%s - %s", challengeTitle, tournament.getName())); tournamentCell.setColspan(4);// w ww .j a va2 s . c o m table.addCell(tournamentCell); final PdfPCell categoryHeader = PdfUtils.createHeaderCell(String .format("Category: %s - Award Group: %s - JudgingGroup: %s", catTitle, division, judgingGroup)); categoryHeader.setColspan(4); table.addCell(categoryHeader); table.addCell(PdfUtils.createHeaderCell(TournamentSchedule.TEAM_NUMBER_HEADER)); table.addCell(PdfUtils.createHeaderCell(TournamentSchedule.TEAM_NAME_HEADER)); table.addCell(PdfUtils.createHeaderCell(TournamentSchedule.ORGANIZATION_HEADER)); table.addCell(PdfUtils.createHeaderCell("Scaled Score")); table.setHeaderRows(3); }
From source file:fll.web.report.FinalComputedScores.java
License:Open Source License
/** * @throws ParseException//from w w w . j av a2s . c o m */ private void writeColumnHeaders(final TournamentSchedule schedule, final double[] weights, final ScoreCategory[] subjectiveCategories, final float[] relativeWidths, final ChallengeDescription challengeDescription, final PdfPTable divTable) throws ParseException { // ///////////////////////////////////////////////////////////////////// // Write the table column headers // ///////////////////////////////////////////////////////////////////// // team information final PdfPCell organizationCell = new PdfPCell(new Phrase("Organization", ARIAL_8PT_BOLD)); organizationCell.setBorder(0); organizationCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(organizationCell); // judging group if (null != schedule) { final Paragraph judgingGroup = new Paragraph("Judging", ARIAL_8PT_BOLD); judgingGroup.add(Chunk.NEWLINE); judgingGroup.add(new Chunk("Group")); final PdfPCell osCell = new PdfPCell(judgingGroup); osCell.setBorder(0); osCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); osCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(osCell); } divTable.addCell(""); // weight/raw&scaled for (int cat = 0; cat < subjectiveCategories.length; cat++) { if (weights[cat] > 0.0) { final String catTitle = subjectiveCategories[cat].getTitle(); final Paragraph catPar = new Paragraph(catTitle, ARIAL_8PT_BOLD); final PdfPCell catCell = new PdfPCell(catPar); catCell.setBorder(0); catCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); catCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(catCell); } } final Paragraph perfPar = new Paragraph("Performance", ARIAL_8PT_BOLD); final PdfPCell perfCell = new PdfPCell(perfPar); perfCell.setBorder(0); perfCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); perfCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(perfCell); final Paragraph overallScore = new Paragraph("Overall", ARIAL_8PT_BOLD); overallScore.add(Chunk.NEWLINE); overallScore.add(new Chunk("Score")); final PdfPCell osCell = new PdfPCell(overallScore); osCell.setBorder(0); osCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); osCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(osCell); // ///////////////////////////////////////////////////////////////////// // Write a table row with the relative weights of the subjective scores // ///////////////////////////////////////////////////////////////////// final PdfPCell teamCell = new PdfPCell(new Phrase("Team # / Team Name", ARIAL_8PT_BOLD)); teamCell.setBorder(0); teamCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(teamCell); final Paragraph wPar = new Paragraph("Weight:", ARIAL_8PT_NORMAL); final PdfPCell wCell = new PdfPCell(wPar); if (null != schedule) { wCell.setColspan(2); } wCell.setBorder(0); wCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT); divTable.addCell(wCell); final PdfPCell[] wCells = new PdfPCell[subjectiveCategories.length]; final Paragraph[] wPars = new Paragraph[subjectiveCategories.length]; for (int cat = 0; cat < subjectiveCategories.length; cat++) { if (weights[cat] > 0.0) { wPars[cat] = new Paragraph(Double.toString(weights[cat]), ARIAL_8PT_NORMAL); wCells[cat] = new PdfPCell(wPars[cat]); wCells[cat].setBorder(0); wCells[cat].setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); divTable.addCell(wCells[cat]); } } final PerformanceScoreCategory performanceElement = challengeDescription.getPerformance(); final double perfWeight = performanceElement.getWeight(); final Paragraph perfWeightPar = new Paragraph(Double.toString(perfWeight), ARIAL_8PT_NORMAL); final PdfPCell perfWeightCell = new PdfPCell(perfWeightPar); perfWeightCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); perfWeightCell.setBorder(0); divTable.addCell(perfWeightCell); divTable.addCell(""); PdfPCell blankCell = new PdfPCell(); blankCell.setBorder(0); blankCell.setBorderWidthBottom(1.0f); blankCell.setColspan(relativeWidths.length); divTable.addCell(blankCell); // Cause the first 4 rows to be repeated on // each page - 1 row for box header, 2 rows text headers and 1 for // the horizontal line. divTable.setHeaderRows(4); }
From source file:generadorPDF.generarPDF.java
private static void createTable(Section subCatPart) throws BadElementException { PdfPTable table = new PdfPTable(3); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);//w w w.j a va 2s. co m c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 3")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); table.addCell("1.0"); table.addCell("1.1"); table.addCell("1.2"); table.addCell("2.1"); table.addCell("2.2"); table.addCell("2.3"); subCatPart.add(table); }
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);//from w w w. ja v a2 s . co 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.FacilityLicenseDetailReport.java
private static PdfPTable getDocumentTable(Person specialist, Date endDate) throws DocumentException { PdfPTable table = new PdfPTable(1); // format the tables int headerwidths[] = { 100 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);/*from w w w .j a va 2s. c om*/ 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, endDate)); table.setHeaderRows(1); return table; }
From source file:gov.utah.dts.det.ccl.actions.reports.generators.FacilityLicenseSummaryReport.java
private static PdfPTable getDocumentTable(Person specialist, Date endDate, FacilityLicenseSummarySortBy sortBy) throws DocumentException { PdfPTable table = new PdfPTable(1); // format the tables int headerwidths[] = { 100 }; // percentage table.setWidths(headerwidths); // percentage table.setWidthPercentage(100);//from w w w . j a v a2 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, endDate, sortBy)); table.setHeaderRows(1); return table; }
From source file:gov.utah.dts.det.ccl.documents.reporting.reports.CaseloadReport.java
@Override public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor descriptor) throws TemplateException { List<Object[]> results = getResults(context); ColumnType columnType = ColumnType.valueOf((String) context.get(COLUMN_TYPE_KEY)); RoleType roleType = RoleType.valueOf((String) context.get(SPECIALIST_TYPE_KEY)); ReportTable<Integer> reportTable = new ReportTable<Integer>(); for (Object[] res : results) { String column = null;/*from www . ja va 2s. c o m*/ switch (columnType) { case LICENSE_TYPE: column = (String) res[3]; break; case CITY: column = (String) res[3]; break; case COUNTY: column = locationService.getCounty((String) res[3], (String) res[4], (String) res[5]); break; case ZIP_CODE: String zip = (String) res[5]; if (zip.length() > 5) { zip = zip.substring(0, 5); } column = zip; break; } if (StringUtils.isBlank(column)) { column = "Unknown"; } reportTable.addColumn(column); String specRow = null; String specFnm = (String) res[1]; String specLnm = (String) res[2]; if (StringUtils.isNotBlank(specFnm) || StringUtils.isNotBlank(specLnm)) { PersonalName name = new PersonalName(specFnm, specLnm); specRow = name.getFirstAndLastName(); } else { specRow = "Unknown"; } reportTable.addRow(specRow); Integer val = reportTable.getTableDataItem(specRow, column); if (val == null) { val = new Integer(1); } else { val = new Integer(val.intValue() + 1); } reportTable.addTableDataItem(specRow, column, val); } setFileName(context, descriptor); Document document = new Document(PAGE_SIZE, MARGIN, MARGIN, MARGIN, MARGIN); try { PdfWriter canvas = PdfWriter.getInstance(document, outputStream); document.open(); ColumnText text = new ColumnText(canvas.getDirectContent()); text.setSimpleColumn(document.getPageSize().getLeft(MARGIN), document.getPageSize().getBottom(MARGIN), document.getPageSize().getRight(MARGIN), document.getPageSize().getTop(MARGIN)); StringBuilder sb = new StringBuilder(roleType.getDisplayName()); sb.append(" Caseloads"); Paragraph heading = new Paragraph(sb.toString(), REPORT_HEADING_FONT); heading.setAlignment(Element.ALIGN_CENTER); text.addElement(heading); text.go(); float yLine = text.getYLine(); yLine -= FONT_SIZE; int columns = reportTable.getColumns().size() + 2; String[][] totTab = new String[reportTable.getRows().size()][columns]; float maxLicWidth = 0f; float maxTotWidth = FONT_SIZE; int rowIdx = 0; for (Iterator<String> rowItr = reportTable.getRows().iterator(); rowItr.hasNext();) { String row = rowItr.next(); totTab[rowIdx][0] = row; float licWidth = getTextWidth(row, FONT); if (licWidth > maxLicWidth) { maxLicWidth = licWidth; } int rowTotal = 0; int colIdx = 1; for (Iterator<String> colItr = reportTable.getColumns().iterator(); colItr.hasNext();) { String col = colItr.next(); Integer val = reportTable.getTableDataItem(row, col); if (val != null) { totTab[rowIdx][colIdx] = val.toString(); rowTotal += val.intValue(); } colIdx++; } String rowTotalStr = Integer.toString(rowTotal); float totWidth = getTextWidth(rowTotalStr, TABLE_HEADER_FONT); if (totWidth > maxTotWidth) { maxTotWidth = totWidth; } totTab[rowIdx][columns - 1] = rowTotalStr; rowIdx++; } //add border and cell padding to licensor width maxLicWidth += (TABLE_CELL_PADDING * 2) + (TABLE_BORDER_SIZE * 2); maxTotWidth += (TABLE_CELL_PADDING * 2) + (TABLE_BORDER_SIZE * 2); float width = PAGE_SIZE.getWidth() - (2 * MARGIN); width -= maxLicWidth; float[] colWidths = new float[columns]; colWidths[0] = maxLicWidth; for (int i = 1; i < columns; i++) { colWidths[i] = maxTotWidth; } PdfPTable table = new PdfPTable(reportTable.getColumns().size() + 2); table.setHeaderRows(1); table.setLockedWidth(true); table.setTotalWidth(colWidths); table.setSpacingBefore(FONT_SIZE); setDefaultCellAttributes(table.getDefaultCell()); PdfPCell cell = null; cell = new PdfPCell(new Phrase("")); cell.setBorderWidthTop(0); cell.setBorderWidthLeft(0); table.addCell(cell); for (Iterator<String> itr = reportTable.getColumns().iterator(); itr.hasNext();) { cell = getRotatedHeaderCell(itr.next()); table.addCell(cell); } cell = getRotatedHeaderCell("Total"); table.addCell(cell); for (String[] row : totTab) { for (int i = 0; i < row.length; i++) { if (row[i] == null) { table.addCell(getNumberCell("")); } else { table.addCell(getCell(new Phrase(row[i], i == row.length - 1 ? TABLE_HEADER_FONT : FONT), i == 0 ? Element.ALIGN_LEFT : Element.ALIGN_CENTER)); } } } writeTable(table, document, canvas.getDirectContent(), colWidths, yLine, true); } catch (DocumentException de) { throw new TemplateException(de); } document.close(); }
From source file:gov.utah.dts.det.ccl.documents.reporting.reports.InspectionsConductedReport.java
@Override public void render(Map<String, Object> context, OutputStream outputStream, FileDescriptor fileDescriptor) throws TemplateException { FindingCategoryType fCat = getFindingCategory(context); PickListValue insType = getInspectionType(context); List<Object[]> results = getResults(context); ReportTable<Integer> reportTable = new ReportTable<Integer>(); for (Object[] res : results) { String row = (String) res[1]; String column = (String) res[0]; Integer val = ((BigDecimal) res[2]).intValue(); reportTable.addRow(row);/*w w w .j av a 2 s . c om*/ reportTable.addColumn(column); reportTable.addTableDataItem(row, column, val); } setFileName(context, fileDescriptor); Document document = new Document(PAGE_SIZE, 36, 36, 36, 36); try { PdfWriter.getInstance(document, outputStream); document.open(); StringBuilder sb = new StringBuilder(); if (insType != null) { sb.append(insType.getValue()); sb.append(" "); } sb.append("Inspections Conducted"); if (fCat != null) { sb.append(" With "); sb.append(fCat.getDisplayName()); sb.append(" Findings"); } Paragraph heading = new Paragraph(sb.toString()); heading.setAlignment(Element.ALIGN_CENTER); document.add(heading); Date startDate = (Date) context.get(DATE_RANGE_START_KEY); Date endDate = (Date) context.get(DATE_RANGE_END_KEY); clearStringBuilder(sb); if (startDate.compareTo(endDate) == 0) { sb.append("On "); sb.append(DATE_FORMATTER.format(startDate)); } else { sb.append(DATE_FORMATTER.format(startDate)); sb.append(" - "); sb.append(DATE_FORMATTER.format(endDate)); } Paragraph date = new Paragraph(sb.toString(), FONT); date.setAlignment(Element.ALIGN_RIGHT); document.add(date); PdfPTable table = new PdfPTable(reportTable.getColumns().size() + 2); table.setHeaderRows(1); table.setSpacingBefore(FONT_SIZE); table.setWidthPercentage(100f); setDefaultCellAttributes(table.getDefaultCell()); table.addCell(""); for (Iterator<String> itr = reportTable.getColumns().iterator(); itr.hasNext();) { table.addCell(getHeaderCell(itr.next())); } table.addCell(getHeaderCell("Total")); int[] colTotals = new int[reportTable.getColumns().size() + 1]; for (Iterator<String> rowItr = reportTable.getRows().iterator(); rowItr.hasNext();) { String row = rowItr.next(); table.addCell(getHeaderCell(row)); int total = 0; int idx = 0; for (Iterator<String> colItr = reportTable.getColumns().iterator(); colItr.hasNext();) { String column = colItr.next(); Integer value = reportTable.getTableDataItem(row, column); if (value == null) { table.addCell(getNumberCell("0")); } else { total += value; colTotals[idx] = colTotals[idx] + value; table.addCell(getNumberCell(value.toString())); } idx++; } table.addCell(getHeaderCell(Integer.toString(total))); colTotals[colTotals.length - 1] = colTotals[colTotals.length - 1] + total; idx++; } table.addCell(getHeaderCell("Total")); for (int i = 0; i < colTotals.length; i++) { table.addCell(getHeaderCell(Integer.toString(colTotals[i]))); } document.add(table); } catch (DocumentException de) { throw new TemplateException(de); } document.close(); }