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:fll.web.report.FinalComputedScores.java
License:Open Source License
/** * Generate the actual report.//from w w w .j a v a2 s .com */ private void generateReport(final Connection connection, final OutputStream out, final ChallengeDescription challengeDescription, final String challengeTitle, final Tournament tournament, final PdfPageEventHelper pageHandler, final Set<Integer> bestTeams) throws SQLException, IOException { if (tournament.getTournamentID() != Queries.getCurrentTournament(connection)) { throw new FLLRuntimeException( "Cannot generate final score report for a tournament other than the current tournament"); } final WinnerType winnerCriteria = challengeDescription.getWinner(); final TournamentSchedule schedule; if (TournamentSchedule.scheduleExistsInDatabase(connection, tournament.getTournamentID())) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Found a schedule for tournament: " + tournament); } schedule = new TournamentSchedule(connection, tournament.getTournamentID()); } else { schedule = null; } try { // This creates our new PDF document and declares it to be in portrait // orientation final Document pdfDoc = PdfUtils.createPortraitPdfDoc(out, pageHandler); final Iterator<String> agIter = Queries.getAwardGroups(connection).iterator(); while (agIter.hasNext()) { final String awardGroup = agIter.next(); final ScoreCategory[] subjectiveCategories = challengeDescription.getSubjectiveCategories() .toArray(new ScoreCategory[0]); // Figure out how many subjective categories have weights > 0. final double[] weights = new double[subjectiveCategories.length]; int nonZeroWeights = 0; for (int catIndex = 0; catIndex < subjectiveCategories.length; catIndex++) { weights[catIndex] = subjectiveCategories[catIndex].getWeight(); if (weights[catIndex] > 0.0) { nonZeroWeights++; } } // Array of relative widths for the columns of the score page // Array length varies with the number of subjective scores weighted > // 0. final int numColumnsLeftOfSubjective = 3; final int numColumnsRightOfSubjective = 2; final float[] relativeWidths = new float[numColumnsLeftOfSubjective + nonZeroWeights + numColumnsRightOfSubjective]; relativeWidths[0] = 3f; relativeWidths[1] = 1.0f; relativeWidths[2] = 1.0f; relativeWidths[relativeWidths.length - numColumnsRightOfSubjective] = 1.5f; relativeWidths[relativeWidths.length - numColumnsRightOfSubjective + 1] = 1.5f; for (int i = numColumnsLeftOfSubjective; i < numColumnsLeftOfSubjective + nonZeroWeights; i++) { relativeWidths[i] = 1.5f; } // Create a table to hold all the scores for this division final PdfPTable divTable = new PdfPTable(relativeWidths); divTable.getDefaultCell().setBorder(0); divTable.setWidthPercentage(100); final PdfPTable header = createHeader(challengeTitle, tournament.getName(), awardGroup); final PdfPCell headerCell = new PdfPCell(header); headerCell.setColspan(relativeWidths.length); divTable.addCell(headerCell); if (LOGGER.isTraceEnabled()) { LOGGER.trace("num relative widths: " + relativeWidths.length); for (int i = 0; i < relativeWidths.length; ++i) { LOGGER.trace("\twidth[" + i + "] = " + relativeWidths[i]); } } writeColumnHeaders(schedule, weights, subjectiveCategories, relativeWidths, challengeDescription, divTable); writeScores(connection, subjectiveCategories, weights, relativeWidths, awardGroup, winnerCriteria, tournament, divTable, bestTeams); // Add the division table to the document pdfDoc.add(divTable); // If there is another division to process, start it on a new page if (agIter.hasNext()) { pdfDoc.newPage(); } } pdfDoc.close(); } catch (final ParseException pe) { throw new RuntimeException("Error parsing category weight!", pe); } catch (final DocumentException de) { throw new RuntimeException("Error creating PDF document!", de); } }
From source file:fll.web.report.FinalComputedScores.java
License:Open Source License
@SuppressFBWarnings(value = { "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" }, justification = "Category name determines table name") private void writeScores(final Connection connection, final ScoreCategory[] subjectiveCategories, final double[] weights, final float[] relativeWidths, final String awardGroup, final WinnerType winnerCriteria, final Tournament tournament, final PdfPTable divTable, final Set<Integer> bestTeams) throws SQLException { final Map<ScoreCategory, Map<String, Map<Integer, Integer>>> teamSubjectiveRanks = gatherRankedSubjectiveTeams( connection, subjectiveCategories, winnerCriteria, tournament, awardGroup); final Map<Integer, Integer> teamPerformanceRanks = gatherRankedPerformanceTeams(connection, winnerCriteria, tournament, awardGroup);/*from w ww . j av a 2s. co m*/ ResultSet rawScoreRS = null; PreparedStatement teamPrep = null; ResultSet teamsRS = null; PreparedStatement scorePrep = null; try { final StringBuilder query = new StringBuilder(); query.append( "SELECT Teams.Organization,Teams.TeamName,Teams.TeamNumber,FinalScores.OverallScore,FinalScores.performance,current_tournament_teams.judging_station"); for (int cat = 0; cat < subjectiveCategories.length; cat++) { if (weights[cat] > 0.0) { final String catName = subjectiveCategories[cat].getName(); query.append(",FinalScores." + catName); } } query.append(" FROM Teams,FinalScores,current_tournament_teams"); query.append(" WHERE FinalScores.TeamNumber = Teams.TeamNumber"); query.append(" AND FinalScores.Tournament = ?"); query.append(" AND current_tournament_teams.event_division = ?"); query.append(" AND current_tournament_teams.TeamNumber = Teams.TeamNumber"); query.append( " ORDER BY FinalScores.OverallScore " + winnerCriteria.getSortString() + ", Teams.TeamNumber"); teamPrep = connection.prepareStatement(query.toString()); teamPrep.setInt(1, tournament.getTournamentID()); teamPrep.setString(2, awardGroup); teamsRS = teamPrep.executeQuery(); scorePrep = connection .prepareStatement("SELECT score FROM performance_seeding_max" + " WHERE TeamNumber = ?"); while (teamsRS.next()) { final int teamNumber = teamsRS.getInt(3); final String organization = teamsRS.getString(1); final String teamName = teamsRS.getString(2); final String judgingGroup = teamsRS.getString(6); final double totalScore; final double ts = teamsRS.getDouble(4); if (teamsRS.wasNull()) { totalScore = Double.NaN; } else { totalScore = ts; } // /////////////////////////////////////////////////////////////////// // Build a table of data for this team // /////////////////////////////////////////////////////////////////// final PdfPTable curteam = new PdfPTable(relativeWidths); curteam.getDefaultCell().setBorder(0); // The first row of the team table... // First column is organization name final PdfPCell teamCol = new PdfPCell(new Phrase(organization, ARIAL_8PT_NORMAL)); teamCol.setBorder(0); teamCol.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_LEFT); curteam.addCell(teamCol); curteam.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT); final PdfPCell judgeGroupCell = new PdfPCell(new Phrase(judgingGroup, ARIAL_8PT_NORMAL)); judgeGroupCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); judgeGroupCell.setBorder(0); curteam.addCell(judgeGroupCell); // Second column is "Raw:" final PdfPCell rawLabel = new PdfPCell(new Phrase("Raw:", ARIAL_8PT_NORMAL)); rawLabel.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT); rawLabel.setBorder(0); curteam.addCell(rawLabel); insertRawScoreColumns(connection, tournament, winnerCriteria.getSortString(), subjectiveCategories, weights, teamNumber, curteam); // Column for the highest performance score of the seeding rounds scorePrep.setInt(1, teamNumber); rawScoreRS = scorePrep.executeQuery(); final double rawScore; if (rawScoreRS.next()) { final double v = rawScoreRS.getDouble(1); if (rawScoreRS.wasNull()) { rawScore = Double.NaN; } else { rawScore = v; } } else { rawScore = Double.NaN; } PdfPCell pCell = new PdfPCell((Double.isNaN(rawScore) ? new Phrase("No Score", ARIAL_8PT_NORMAL_RED) : new Phrase(Utilities.NUMBER_FORMAT_INSTANCE.format(rawScore), ARIAL_8PT_NORMAL))); pCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); pCell.setBorder(0); curteam.addCell(pCell); rawScoreRS.close(); // The "Overall score" column is not filled in for raw scores curteam.addCell(""); // The second row of the team table... // First column contains the team # and name final PdfPCell teamNameCol = new PdfPCell( new Phrase(Integer.toString(teamNumber) + " " + teamName, ARIAL_8PT_NORMAL)); teamNameCol.setBorder(0); teamNameCol.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_LEFT); curteam.addCell(teamNameCol); // Second column contains "Scaled:" final PdfPCell scaledCell = new PdfPCell(new Phrase("Scaled:", ARIAL_8PT_NORMAL)); scaledCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT); scaledCell.setBorder(0); scaledCell.setColspan(2); curteam.addCell(scaledCell); // Next, one column containing the scaled score for each subjective // category with weight > 0 for (int cat = 0; cat < subjectiveCategories.length; cat++) { final Map<String, Map<Integer, Integer>> catRanks = teamSubjectiveRanks .get(subjectiveCategories[cat]); final double catWeight = weights[cat]; if (catWeight > 0.0) { final double scaledScore; final double v = teamsRS.getDouble(6 + cat + 1); if (teamsRS.wasNull()) { scaledScore = Double.NaN; } else { scaledScore = v; } final Map<Integer, Integer> judgingRanks = catRanks.get(judgingGroup); Font scoreFont; final String rankText; if (judgingRanks.containsKey(teamNumber)) { final int rank = judgingRanks.get(teamNumber); rankText = String.format("%1$s(%2$d)", Utilities.NON_BREAKING_SPACE, rank); if (1 == rank) { scoreFont = ARIAL_8PT_BOLD; } else { scoreFont = ARIAL_8PT_NORMAL; } } else { rankText = String.format("%1$s%1$s%1$s%1$s%1$s", Utilities.NON_BREAKING_SPACE); scoreFont = ARIAL_8PT_NORMAL; } final String scoreText; if (Double.isNaN(scaledScore)) { scoreText = "No Score" + rankText; scoreFont = ARIAL_8PT_NORMAL_RED; } else { scoreText = Utilities.NUMBER_FORMAT_INSTANCE.format(scaledScore) + rankText; } final PdfPCell subjCell = new PdfPCell(new Phrase(scoreText, scoreFont)); subjCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); subjCell.setBorder(0); curteam.addCell(subjCell); } } // foreach category // 2nd to last column has the scaled performance score { Font scoreFont; final String rankText; if (teamPerformanceRanks.containsKey(teamNumber)) { final int rank = teamPerformanceRanks.get(teamNumber); rankText = String.format("%1$s(%2$d)", Utilities.NON_BREAKING_SPACE, rank); if (1 == rank) { scoreFont = ARIAL_8PT_BOLD; } else { scoreFont = ARIAL_8PT_NORMAL; } } else { rankText = String.format("%1$s%1$s%1$s%1$s%1$s", Utilities.NON_BREAKING_SPACE); scoreFont = ARIAL_8PT_NORMAL; } final double scaledScore; final double v = teamsRS.getDouble(5); if (teamsRS.wasNull()) { scaledScore = Double.NaN; } else { scaledScore = v; } final String scaledScoreStr; if (Double.isNaN(scaledScore)) { scoreFont = ARIAL_8PT_NORMAL_RED; scaledScoreStr = "No Score" + rankText; } else { scaledScoreStr = Utilities.NUMBER_FORMAT_INSTANCE.format(scaledScore) + rankText; } pCell = new PdfPCell(new Phrase(scaledScoreStr, scoreFont)); pCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); pCell.setBorder(0); curteam.addCell(pCell); } // performance score // Last column contains the overall scaled score final String overallScoreSuffix; if (bestTeams.contains(teamNumber)) { overallScoreSuffix = String.format("%1$s*", Utilities.NON_BREAKING_SPACE); } else { overallScoreSuffix = String.format("%1$s%1$s", Utilities.NON_BREAKING_SPACE); } pCell = new PdfPCell((Double.isNaN(totalScore) ? new Phrase("No Score" + overallScoreSuffix, ARIAL_8PT_NORMAL_RED) : new Phrase(Utilities.NUMBER_FORMAT_INSTANCE.format(totalScore) + overallScoreSuffix, ARIAL_8PT_NORMAL))); pCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); pCell.setBorder(0); curteam.addCell(pCell); // This is an empty row in the team table that is added to put a // horizontal rule under the team's score in the display final PdfPCell blankCell = new PdfPCell(); blankCell.setBorder(0); blankCell.setBorderWidthBottom(0.5f); blankCell.setBorderColorBottom(BaseColor.GRAY); blankCell.setColspan(relativeWidths.length); curteam.addCell(blankCell); // Create a new cell and add it to the division table - this cell will // contain the entire team table we just built above final PdfPCell curteamCell = new PdfPCell(curteam); curteamCell.setBorder(0); curteamCell.setColspan(relativeWidths.length); divTable.addCell(curteamCell); } teamsRS.close(); } finally { SQLFunctions.close(teamsRS); SQLFunctions.close(teamPrep); SQLFunctions.close(rawScoreRS); SQLFunctions.close(scorePrep); } }
From source file:fll.web.report.FinalComputedScores.java
License:Open Source License
private PdfPTable createHeader(final String challengeTitle, final String tournamentName, final String division) { // initialization of the header table final PdfPTable header = new PdfPTable(2); final Phrase p = new Phrase(); p.add(new Chunk(challengeTitle, TIMES_12PT_NORMAL)); p.add(Chunk.NEWLINE);//from w w w. jav a 2s . com p.add(new Chunk("Final Computed Scores", TIMES_12PT_NORMAL)); header.getDefaultCell().setBorderWidth(0); header.addCell(p); header.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT); final Phrase p2 = new Phrase(); p2.add(new Chunk("Tournament: " + tournamentName, TIMES_12PT_NORMAL)); p2.add(Chunk.NEWLINE); p2.add(new Chunk("Award Group: " + division, TIMES_12PT_NORMAL)); header.addCell(p2); return header; }
From source file:fll.web.report.finalist.AbstractFinalistSchedule.java
License:Open Source License
/** * Create a page for the specified category. * // www . java 2s . c o m * @throws DocumentException * @throws SQLException */ private void createCategoryPage(final Document document, final Connection connection, final String category, final String room, final FinalistSchedule schedule) throws DocumentException, SQLException { // header name final Paragraph para = new Paragraph(); para.add(Chunk.NEWLINE); para.add(new Chunk(String.format("Finalist schedule for %s", category), TITLE_FONT)); para.add(Chunk.NEWLINE); if (null != room && !"".equals(room)) { para.add(new Chunk(String.format("Room: %s", room), TITLE_FONT)); } document.add(para); final PdfPTable schedTable = new PdfPTable(new float[] { 12.5f, 12.5f, 37.5f, 37.5f }); schedTable.setWidthPercentage(100); schedTable.getDefaultCell().setBorder(0); schedTable.getDefaultCell().enableBorderSide(Rectangle.BOTTOM); schedTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); schedTable.addCell(new Phrase("Time", SCHEDULE_HEADER_FONT)); schedTable.addCell(new Phrase("Team #", SCHEDULE_HEADER_FONT)); schedTable.addCell(new Phrase("Team Name", SCHEDULE_HEADER_FONT)); schedTable.addCell(new Phrase("Organization", SCHEDULE_HEADER_FONT)); // foreach information output for (final FinalistDBRow row : schedule.getScheduleForCategory(category)) { // time, number, name, organization schedTable.addCell(new Phrase(String.format("%d:%02d", row.getHour(), row.getMinute()), SCHEDULE_FONT)); final Team team = Team.getTeamFromDatabase(connection, row.getTeamNumber()); schedTable.addCell(new Phrase(String.valueOf(team.getTeamNumber()), SCHEDULE_FONT)); schedTable.addCell(new Phrase(team.getTeamName(), SCHEDULE_FONT)); schedTable.addCell(new Phrase(team.getOrganization(), SCHEDULE_FONT)); } document.add(schedTable); document.add(Chunk.NEXTPAGE); }
From source file:fll.web.report.ReportPageEventHandler.java
License:Open Source License
@Override // initialization of the header table public void onEndPage(final PdfWriter writer, final Document document) { final PdfPTable header = new PdfPTable(2); final Phrase p = new Phrase(); final Chunk ck = new Chunk(_challengeTitle + "\n" + _reportTitle, _font); p.add(ck);//from w w w. j av a2 s .c o m header.getDefaultCell().setBorderWidth(0); header.addCell(p); header.getDefaultCell().setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT); header.addCell(new Phrase(new Chunk("Tournament: " + _tournament + "\nDate: " + _formattedDate, _font))); final PdfPCell blankCell = new PdfPCell(); blankCell.setBorder(0); blankCell.setBorderWidthTop(1.0f); blankCell.setColspan(2); header.addCell(blankCell); final PdfContentByte cb = writer.getDirectContent(); cb.saveState(); header.setTotalWidth(document.right() - document.left()); header.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 10, cb); cb.restoreState(); }
From source file:fr.pigouchet.gestion.util.GeneratePdf.java
public static PdfPTable getHeaderTable(int x, int y) { PdfPTable table = new PdfPTable(2); table.setTotalWidth(527);//from w w w. j a va 2s . c o m table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.addCell("FOOBAR FILMFESTIVAL"); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(String.format("Page %d of %d", x, y)); return table; }
From source file:fr.ybonnel.breizhcamppdf.PdfRenderer.java
License:Apache License
private void remplirCellWithTalk(PdfPCell cell, Talk talk) throws DocumentException, IOException { Image image = AvatarService.INSTANCE.getImage( PdfRenderer.class.getResource("/formats/" + talk.getFormat().replaceAll(" ", "") + ".png")); float[] widths = { 0.15f, 0.85f }; PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(100f);//from w w w .ja v a 2s.c o m table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.addCell(image); PdfPCell subCell = new PdfPCell(); Chunk chunk = new Chunk(talk.getTitle(), talkFont); chunk.setLocalGoto("talk" + talk.getId()); Paragraph titleTalk = new Paragraph(); titleTalk.add(chunk); titleTalk.setAlignment(Paragraph.ALIGN_CENTER); subCell.addElement(titleTalk); Paragraph track = new Paragraph(new Phrase(talk.getTrack(), themeFont)); track.setAlignment(Paragraph.ALIGN_CENTER); subCell.addElement(track); TalkDetail detail = TalkService.INSTANCE.getTalkDetail(talk); if (detail != null) { for (Speaker speaker : detail.getSpeakers()) { Paragraph speakerText = new Paragraph(speaker.getFullname(), speakerFont); speakerText.setAlignment(Paragraph.ALIGN_CENTER); subCell.addElement(speakerText); } } subCell.setBorder(Rectangle.NO_BORDER); table.addCell(subCell); cell.setBackgroundColor(mapTrack.get(talk.getTrack())); cell.addElement(table); }
From source file:fr.ybonnel.breizhcamppdf.PdfRenderer.java
License:Apache License
private void createTalksPages(List<Talk> talksToExplain) throws DocumentException, IOException { document.setPageSize(PageSize.A4);//from ww w. j ava2s.c om document.newPage(); Paragraph paragraph = new Paragraph("Liste des talks"); paragraph.setSpacingAfter(25); paragraph.getFont().setSize(25); paragraph.setAlignment(Element.ALIGN_CENTER); document.add(paragraph); for (TalkDetail talk : Lists.transform(talksToExplain, new Function<Talk, TalkDetail>() { @Override public TalkDetail apply(Talk input) { return TalkService.INSTANCE.getTalkDetail(input); } })) { if (talk == null) { continue; } Paragraph empty = new Paragraph(" "); PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); table.setKeepTogether(true); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); PdfPCell cell; Chunk titleTalk = new Chunk(talk.getTitle(), talkFontTitle); titleTalk.setLocalDestination("talk" + talk.getId()); float[] withTitle = { 0.05f, 0.95f }; PdfPTable titleWithFormat = new PdfPTable(withTitle); titleWithFormat.getDefaultCell().setBorder(Rectangle.NO_BORDER); titleWithFormat.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); Image image = AvatarService.INSTANCE.getImage(PdfRenderer.class .getResource("/formats/" + talk.getTalk().getFormat().replaceAll(" ", "") + ".png")); titleWithFormat.addCell(image); titleWithFormat.addCell(new Paragraph(titleTalk)); table.addCell(titleWithFormat); table.addCell(empty); table.addCell(new Paragraph("Salle " + talk.getTalk().getRoom() + " de " + talk.getTalk().getStart() + " " + talk.getTalk().getEnd(), presentFont)); table.addCell(empty); cell = new PdfPCell(); cell.setBorder(0); cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); for (Element element : HTMLWorker .parseToList(new StringReader(markdownProcessor.markdown(talk.getDescription())), null)) { if (element instanceof Paragraph) { ((Paragraph) element).setAlignment(Element.ALIGN_JUSTIFIED); } cell.addElement(element); } table.addCell(cell); table.addCell(empty); table.addCell(new Paragraph("Prsent par :", presentFont)); float[] widthSpeaker = { 0.05f, 0.95f }; for (Speaker speaker : talk.getSpeakers()) { PdfPTable speakerWithAvatar = new PdfPTable(widthSpeaker); speakerWithAvatar.getDefaultCell().setBorder(Rectangle.NO_BORDER); speakerWithAvatar.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); speakerWithAvatar.addCell(AvatarService.INSTANCE.getImage(speaker.getAvatar())); speakerWithAvatar.addCell(new Phrase(speaker.getFullname())); table.addCell(speakerWithAvatar); } table.addCell(empty); table.addCell(empty); document.add(table); } }
From source file:fr.ybonnel.breizhcamppdf.RoomPdfRenderer.java
License:Apache License
private void remplirCellWithTalk(PdfPCell cell, Talk talk) throws DocumentException, IOException { Image image = AvatarService.INSTANCE.getImage( RoomPdfRenderer.class.getResource("/formats/" + talk.getFormat().replaceAll(" ", "") + ".png")); float[] widths = { 0.05f, 0.95f }; PdfPTable table = new PdfPTable(widths); table.setWidthPercentage(100f);//from w ww. j a v a 2 s . c o m table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.addCell(image); PdfPCell subCell = new PdfPCell(); Chunk chunk = new Chunk(talk.getTitle(), talkFont); chunk.setLocalGoto("talk" + talk.getId()); Paragraph titleTalk = new Paragraph(); titleTalk.add(chunk); titleTalk.setAlignment(Paragraph.ALIGN_CENTER); subCell.addElement(titleTalk); Paragraph track = new Paragraph(new Phrase(talk.getTrack(), themeFont)); track.setAlignment(Paragraph.ALIGN_CENTER); subCell.addElement(track); TalkDetail detail = TalkService.INSTANCE.getTalkDetail(talk); if (detail != null) { for (Speaker speaker : detail.getSpeakers()) { Paragraph speakerText = new Paragraph(speaker.getFullname(), speakerFont); speakerText.setAlignment(Paragraph.ALIGN_CENTER); subCell.addElement(speakerText); } } subCell.setBorder(Rectangle.NO_BORDER); table.addCell(subCell); cell.setBackgroundColor(mapTrack.get(talk.getTrack())); cell.addElement(table); }
From source file:fxml.test.PDFService.java
private PdfPTable createDocumentHeader() throws IOException, BadElementException { //start creating header for the document...... PdfPTable headerTable = new PdfPTable(3); headerTable.setHorizontalAlignment(Element.ALIGN_LEFT); try {//from ww w . j av a 2 s . c o m headerTable.setTotalWidth(new float[] { 57.5f, 531.5f, 183f }); headerTable.setLockedWidth(true); } catch (DocumentException ex) { Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex); } Image image = Image.getInstance(getClass().getClassLoader().getResource("img/sust.jpg")); image.scalePercent(42f); image.setAlignment(Element.ALIGN_LEFT); PdfPCell imageCell = new PdfPCell(image, false); imageCell.setPaddingTop(6); imageCell.setBorder(Rectangle.NO_BORDER); headerTable.addCell(imageCell); //start info table..... PdfPTable infoTable = new PdfPTable(1); infoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); String universityText = "SHAHJALAL UNIVERSITY OF SCIENCE & TECHNOLOGY SYLHET, BANGLADESH"; String tabulationText = "TABULATION SHEET"; String deptText = inputs.get(0).trim(); String s1 = inputs.get(1).trim(); String s2 = inputs.get(2).trim(); String semesterText = ("B.Sc (Engg.) " + s1 + " SEMESTER EXAMINATION " + s2); String session = inputs.get(3).trim(); String date = inputs.get(4).trim(); String sessionDateText = ("SESSION:" + session + " EXAMINATION HELD IN: " + date); infoTable.addCell(getCellForHeaderString(universityText, 0, false, 0, Element.ALIGN_CENTER, font10, true)); infoTable.addCell(getCellForHeaderString(tabulationText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); infoTable.addCell(getCellForHeaderString(deptText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); infoTable.addCell(getCellForHeaderString(semesterText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); infoTable .addCell(getCellForHeaderString(sessionDateText, 0, false, 0, Element.ALIGN_CENTER, font10, false)); //end info table..... PdfPCell infoCell = new PdfPCell(infoTable); infoCell.setBorder(Rectangle.NO_BORDER); headerTable.addCell(infoCell); PdfPCell resultPublishDateCell = new PdfPCell( new Paragraph("Result Published On............................", new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD))); resultPublishDateCell.setBorder(Rectangle.NO_BORDER); resultPublishDateCell.setVerticalAlignment(Element.ALIGN_MIDDLE); resultPublishDateCell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(resultPublishDateCell); headerTable.setSpacingAfter(17.5f); // System.err.println("completed header table"); return headerTable; //end creating header for the document...... }