List of usage examples for com.itextpdf.text Chunk NEXTPAGE
Chunk NEXTPAGE
To view the source code for com.itextpdf.text Chunk NEXTPAGE.
Click Source Link
From source file:fll.scheduler.TournamentSchedule.java
License:Open Source License
/** * Output the subjective schedules with a table for each category and sorted * by judging station, then by time./*from ww w . j ava2 s .c o m*/ * * @param pdfFos where to output the schedule * @throws DocumentException */ public void outputSubjectiveSchedulesByJudgingStation(final OutputStream pdfFos) throws DocumentException { final Document detailedSchedulesByDivision = PdfUtils.createPortraitPdfDoc(pdfFos, new SimpleFooterHandler()); for (final String subjectiveStation : subjectiveStations) { outputSubjectiveScheduleByDivision(detailedSchedulesByDivision, subjectiveStation); detailedSchedulesByDivision.add(Chunk.NEXTPAGE); } detailedSchedulesByDivision.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 w ww .j a va 2 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.web.report.CategoryScoresByScoreGroup.java
License:Open Source License
@SuppressFBWarnings(value = { "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" }, justification = "Category name determines table column, winner criteria determines sort") private void generateReport(final Connection connection, final Document pdfDoc, final ChallengeDescription challengeDescription, final Tournament tournament) throws SQLException, DocumentException { PreparedStatement prep = null; ResultSet rs = null;/*from w ww .j a va 2 s .c o m*/ try { final String challengeTitle = challengeDescription.getTitle(); final WinnerType winnerCriteria = challengeDescription.getWinner(); final List<ScoreCategory> subjectiveCategories = challengeDescription.getSubjectiveCategories(); final Collection<String> eventDivisions = Queries.getAwardGroups(connection); final Collection<String> judgingGroups = Queries.getJudgingStations(connection, tournament.getTournamentID()); for (final ScoreCategory catElement : subjectiveCategories) { final String catName = catElement.getName(); final String catTitle = catElement.getTitle(); prep = connection.prepareStatement("SELECT "// + " Teams.TeamNumber, Teams.TeamName, Teams.Organization, FinalScores." + catName // + " FROM Teams, FinalScores" // + " WHERE FinalScores.Tournament = ?" // + " AND FinalScores.TeamNumber = Teams.TeamNumber" // + " AND FinalScores.TeamNumber IN (" // + " SELECT TeamNumber FROM TournamentTeams"// + " WHERE Tournament = ?" // + " AND event_division = ?" // + " AND judging_station = ?)" // + " ORDER BY " + catName + " " + winnerCriteria.getSortString() // ); prep.setInt(1, tournament.getTournamentID()); prep.setInt(2, tournament.getTournamentID()); for (final String division : eventDivisions) { for (final String judgingGroup : judgingGroups) { final PdfPTable table = PdfUtils.createTable(4); createHeader(table, challengeTitle, catTitle, division, judgingGroup, tournament); prep.setString(3, division); prep.setString(4, judgingGroup); boolean haveData = false; rs = prep.executeQuery(); while (rs.next()) { haveData = true; final int teamNumber = rs.getInt(1); final String teamName = rs.getString(2); final String organization = rs.getString(3); table.addCell(PdfUtils.createCell(String.valueOf(teamNumber))); table.addCell(PdfUtils.createCell(null == teamName ? "" : teamName)); table.addCell(PdfUtils.createCell(null == organization ? "" : organization)); double score = rs.getDouble(4); if (rs.wasNull()) { score = Double.NaN; } if (Double.isNaN(score)) { table.addCell(PdfUtils.createCell("No Score")); } else { table.addCell(PdfUtils.createCell(Utilities.NUMBER_FORMAT_INSTANCE.format(score))); } } if (haveData) { table.keepRowsTogether(0); pdfDoc.add(table); pdfDoc.add(Chunk.NEXTPAGE); } } // foreach station } // foreach division SQLFunctions.close(prep); prep = null; } // foreach category } finally { SQLFunctions.close(rs); SQLFunctions.close(prep); } }
From source file:fll.web.report.finalist.AbstractFinalistSchedule.java
License:Open Source License
/** * Create a page for the specified category. * // www . j a va 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.finalist.TeamFinalistSchedule.java
License:Open Source License
protected void processRequest(final HttpServletRequest request, final HttpServletResponse response, final ServletContext application, final HttpSession session) throws IOException, ServletException { Connection connection = null; try {// w ww.ja va 2 s .c o m final DataSource datasource = ApplicationAttributes.getDataSource(application); connection = datasource.getConnection(); final ChallengeDescription challengeDescription = ApplicationAttributes .getChallengeDescription(application); // create simple doc and write to a ByteArrayOutputStream final Document document = new Document(PageSize.LETTER); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new ReportPageEventHandler(HEADER_FONT, "Finalist Callback Schedule", challengeDescription.getTitle(), Queries.getCurrentTournamentName(connection))); document.open(); document.addTitle("Ranking Report"); // add content final int currentTournament = Queries.getCurrentTournament(connection); final Collection<String> divisions = FinalistSchedule.getAllDivisions(connection, currentTournament); final Collection<FinalistSchedule> schedules = new LinkedList<FinalistSchedule>(); for (final String division : divisions) { final FinalistSchedule schedule = new FinalistSchedule(connection, currentTournament, division); schedules.add(schedule); } final Map<Integer, TournamentTeam> tournamentTeams = Queries.getTournamentTeams(connection, currentTournament); final List<Integer> teamNumbers = new LinkedList<Integer>(tournamentTeams.keySet()); Collections.sort(teamNumbers); for (final int teamNum : teamNumbers) { final TournamentTeam team = tournamentTeams.get(teamNum); for (final FinalistSchedule schedule : schedules) { final List<FinalistDBRow> finalistTimes = schedule.getScheduleForTeam(teamNum); final Map<String, String> rooms = schedule.getRooms(); if (!finalistTimes.isEmpty()) { final Paragraph para = new Paragraph(); para.add(Chunk.NEWLINE); para.add(new Chunk("Finalist times for Team " + teamNum, TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk(team.getTeamName() + " / " + team.getOrganization(), TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk("Award Group: " + team.getAwardGroup(), TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(Chunk.NEWLINE); final PdfPTable table = new PdfPTable(3); // table.getDefaultCell().setBorder(0); table.setWidthPercentage(100); table.addCell(new Phrase(new Chunk("Time", HEADER_FONT))); table.addCell(new Phrase(new Chunk("Room", HEADER_FONT))); table.addCell(new Phrase(new Chunk("Category", HEADER_FONT))); for (final FinalistDBRow row : finalistTimes) { final String categoryName = row.getCategoryName(); String room = rooms.get(categoryName); if (null == room) { room = ""; } table.addCell(new Phrase(String.format("%d:%02d", row.getHour(), row.getMinute()), VALUE_FONT)); table.addCell(new Phrase(new Chunk(room, VALUE_FONT))); table.addCell(new Phrase(new Chunk(categoryName, VALUE_FONT))); } // foreach row para.add(table); document.add(para); document.add(Chunk.NEXTPAGE); } // non-empty list of teams } // foreach schedule } // foreach team document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // setting the content type response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "filename=teamFinalistSchedule.pdf"); // the content length is needed for MSIE!!! response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream final ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); } catch (final SQLException e) { LOG.error(e, e); throw new RuntimeException(e); } catch (final DocumentException e) { LOG.error(e, e); throw new RuntimeException(e); } finally { SQLFunctions.close(connection); } }
From source file:fll.web.report.PerformanceScoreReport.java
License:Open Source License
@Override protected void processRequest(HttpServletRequest request, HttpServletResponse response, ServletContext application, HttpSession session) throws IOException, ServletException { Connection connection = null; try {//from w ww. ja v a2 s. c o m final DataSource datasource = ApplicationAttributes.getDataSource(application); connection = datasource.getConnection(); final ChallengeDescription challengeDescription = ApplicationAttributes .getChallengeDescription(application); final int tournamentId = Queries.getCurrentTournament(connection); final Tournament tournament = Tournament.findTournamentByID(connection, tournamentId); final int numSeedingRounds = TournamentParameters.getNumSeedingRounds(connection, tournament.getTournamentID()); // create simple doc and write to a ByteArrayOutputStream final Document document = new Document(PageSize.LETTER, 36, 36, 72, 36); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PdfWriter writer = PdfWriter.getInstance(document, baos); final PerformanceScoreReportPageEventHandler headerHandler = new PerformanceScoreReportPageEventHandler( HEADER_FONT, REPORT_TITLE, challengeDescription.getTitle(), tournament.getName()); writer.setPageEvent(headerHandler); document.open(); document.addTitle(REPORT_TITLE); final Map<Integer, TournamentTeam> teams = Queries.getTournamentTeams(connection); if (teams.isEmpty()) { final Paragraph para = new Paragraph(); para.add(Chunk.NEWLINE); para.add(new Chunk("No teams in the tournament.")); document.add(para); } else { for (Map.Entry<Integer, TournamentTeam> entry : teams.entrySet()) { headerHandler.setTeamInfo(entry.getValue()); outputTeam(connection, document, tournament, challengeDescription, numSeedingRounds, entry.getValue()); document.add(Chunk.NEXTPAGE); } } document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // setting the content type response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "filename=performanceScoreReport.pdf"); // the content length is needed for MSIE!!! response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream final ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); } catch (final SQLException e) { LOG.error(e, e); throw new RuntimeException(e); } catch (final DocumentException e) { LOG.error(e, e); throw new RuntimeException(e); } finally { SQLFunctions.close(connection); } }
From source file:fll.web.report.RankingReport.java
License:Open Source License
protected void processRequest(final HttpServletRequest request, final HttpServletResponse response, final ServletContext application, final HttpSession session) throws IOException, ServletException { if (PromptSummarizeScores.checkIfSummaryUpdated(response, application, session, "/report/RankingReport")) { return;/*from w w w .j av a 2s . c om*/ } Connection connection = null; try { final DataSource datasource = ApplicationAttributes.getDataSource(application); connection = datasource.getConnection(); final boolean useQuartiles = GlobalParameters.getUseQuartilesInRankingReport(connection); final ChallengeDescription challengeDescription = ApplicationAttributes .getChallengeDescription(application); // create simple doc and write to a ByteArrayOutputStream final Document document = new Document(PageSize.LETTER); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new ReportPageEventHandler(HEADER_FONT, "Final Computed Rankings", challengeDescription.getTitle(), Queries.getCurrentTournamentName(connection))); document.open(); document.addTitle("Ranking Report"); // add content final Map<Integer, TeamRanking> teamRankings = Queries.getTeamRankings(connection, challengeDescription); final List<Integer> teamNumbers = new LinkedList<Integer>(teamRankings.keySet()); Collections.sort(teamNumbers); final Map<Integer, TournamentTeam> tournamentTeams = Queries.getTournamentTeams(connection); for (final int teamNum : teamNumbers) { final TournamentTeam team = tournamentTeams.get(teamNum); final Paragraph para = new Paragraph(); para.add(Chunk.NEWLINE); para.add(new Chunk("Ranks for Team " + teamNum, TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk(team.getTeamName() + " / " + team.getOrganization(), TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk("Award Group: " + team.getAwardGroup(), TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk( "Each team is ranked in each category in the judging group and award group they were judged in. Performance scores are ranked by division only. Teams may have the same rank if they were tied.", RANK_VALUE_FONT)); para.add(Chunk.NEWLINE); para.add(Chunk.NEWLINE); final TeamRanking teamRanks = teamRankings.get(teamNum); final List<String> categories = teamRanks.getCategories(); Collections.sort(categories); // pull out performance next if (categories.contains(CategoryRank.PERFORMANCE_CATEGORY_NAME)) { final String category = CategoryRank.PERFORMANCE_CATEGORY_NAME; outputCategory(para, teamRanks, category, useQuartiles); } para.add(Chunk.NEWLINE); for (final String category : categories) { if (!CategoryRank.PERFORMANCE_CATEGORY_NAME.equals(category) && !CategoryRank.OVERALL_CATEGORY_NAME.equals(category)) { outputCategory(para, teamRanks, category, useQuartiles); } } document.add(para); final Paragraph definitionPara = new Paragraph(); definitionPara.add(Chunk.NEWLINE); definitionPara.add(new Chunk( "The 1st quartile is the top 25% of teams, 2nd quartile is the next 25%, quartiles 3 and 4 are the following 25% groupings of teams.")); document.add(definitionPara); document.add(Chunk.NEXTPAGE); } document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // setting the content type response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "filename=rankingReport.pdf"); // the content length is needed for MSIE!!! response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream final ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); } catch (final SQLException e) { LOG.error(e, e); throw new RuntimeException(e); } catch (final DocumentException e) { LOG.error(e, e); throw new RuntimeException(e); } finally { SQLFunctions.close(connection); } }
From source file:MailSender.PDF.java
public void createInvoice(ArrayList<Guest> guestarray, Reservation res, String roomType, int roomPrice) throws DocumentException, IOException { filePath = "Invoice" + guestarray.get(0).getReservationNo() + ".pdf"; // step 1/* w w w . j a v a2 s . co m*/ String firstName = guestarray.get(0).getGuestFirstName(); String lastName = guestarray.get(0).getGuestFamilyName(); int deposit = roomPrice / 2; DateFormat dateFormat = new SimpleDateFormat("dd-MM-yy"); Document document = new Document(); System.out.println("document"); // step 2 FileOutputStream fos = new FileOutputStream(filePath); PdfWriter.getInstance(document, fos); System.out.println("fos"); // step 3 document.open(); // step 4 Font font = FontFactory.getFont("Times-Roman", 18); Font fontbold = FontFactory.getFont("Times-Roman", 34, Font.BOLD); document.add(new Paragraph("Invoice", fontbold)); document.add(new Paragraph(" Casablanca Holiday Centre", font)); document.add(new Paragraph(" " + c.getTime(), font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Dear " + firstName + " " + lastName + ",", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("thank you for your reservation.", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("++++++Reservation details+++++++", font)); document.add(new Paragraph( "Name: " + guestarray.get(0).getGuestFirstName() + " " + guestarray.get(0).getGuestFamilyName(), font)); document.add(new Paragraph("From: " + dateFormat.format(res.getFromDate()), font)); document.add(new Paragraph("To: " + dateFormat.format(res.getEndDate()), font)); document.add(new Paragraph("Room type: " + roomType, font)); document.add(new Paragraph("++++++++++++++++++++++++++++++++", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Please place the deposit in our follwing bank account in 5 days.", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Deposit ammount: " + deposit + " USD", font)); document.add(new Paragraph("Bank account: xxxx xxxx xxxx", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Please read our cancel rule mentioned in the next page", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("Regards,", font)); document.add(new Paragraph("CasaBlanca Hotel Resort", font)); document.add(new Paragraph(Chunk.NEXTPAGE)); document.add(new Paragraph("The deposit and rules of cancellations", fontbold)); document.add(new Paragraph(Chunk.NEWLINE)); document.add( new Paragraph("The deposit must be paid at the latest 5 days after receiving the invoice.", font)); document.add(new Paragraph( "The deposit is half the bill. If deposit is not received by the centre within this deadline the booking will be cancelled.", font)); document.add(new Paragraph( "In case of cancellation your deposit will be refunded after deducting the cancellation fees as follows.", font)); document.add(new Paragraph(Chunk.NEWLINE)); document.add(new Paragraph("2 weeks before the date of arrival: the deposit will be refunded", font)); document.add(new Paragraph("1 week before the date of arrival: the deposit will be refunded", font)); document.add(new Paragraph("Less than a week no deposit is refunded.", font)); // step 5 document.close(); System.out.println("closed"); }