Example usage for com.itextpdf.text Document addTitle

List of usage examples for com.itextpdf.text Document addTitle

Introduction

In this page you can find the example usage for com.itextpdf.text Document addTitle.

Prototype


public boolean addTitle(String title) 

Source Link

Document

Adds the title to a Document.

Usage

From source file:fll.web.report.finalist.AbstractFinalistSchedule.java

License:Open Source License

protected void processRequest(final String division, final boolean showPrivate,
        final HttpServletResponse response, final ServletContext application)
        throws IOException, ServletException {
    Connection connection = null;
    try {//from www.  j a v a 2 s . co 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);

        final FinalistSchedule schedule = new FinalistSchedule(connection,
                Queries.getCurrentTournament(connection), division);

        writer.setPageEvent(new PageEventHandler(challengeDescription.getTitle(),
                Queries.getCurrentTournamentName(connection), schedule.getDivision(), showPrivate));

        document.open();

        document.addTitle("Finalist Schedule");

        final Map<String, String> rooms = schedule.getRooms();
        for (final Map.Entry<String, Boolean> entry : schedule.getCategories().entrySet()) {
            if (showPrivate || entry.getValue()) {
                createCategoryPage(document, connection, entry.getKey(), rooms.get(entry.getKey()), schedule);
            }
        }

        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=finalist-schedule.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) {
        LOGGER.error(e, e);
        throw new RuntimeException(e);
    } catch (final DocumentException e) {
        LOGGER.error(e, e);
        throw new RuntimeException(e);
    } finally {
        SQLFunctions.close(connection);
    }

}

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 {/*from w  w w . j  a v a  2 s  .  com*/
        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 ww  w  . j a  va 2s  . 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.PlayoffReport.java

License:Open Source License

@Override
protected void processRequest(HttpServletRequest request, HttpServletResponse response,
        ServletContext application, HttpSession session) throws IOException, ServletException {
    Connection connection = null;
    try {//ww  w. j av  a  2s  .  c  o  m
        final DataSource datasource = ApplicationAttributes.getDataSource(application);
        connection = datasource.getConnection();
        final ChallengeDescription challengeDescription = ApplicationAttributes
                .getChallengeDescription(application);

        final Tournament tournament = Tournament.findTournamentByID(connection,
                Queries.getCurrentTournament(connection));

        // 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, "Head to Head Winners",
                challengeDescription.getTitle(), tournament.getName()));

        document.open();

        document.addTitle("Head to Head Report");

        final List<String> playoffDivisions = Playoff.getPlayoffBrackets(connection,
                tournament.getTournamentID());
        for (final String division : playoffDivisions) {

            Paragraph para = processDivision(connection, tournament, division);
            document.add(para);
        }

        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=playoffReport.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) {
        LOGGER.error(e, e);
        throw new RuntimeException(e);
    } catch (final DocumentException e) {
        LOGGER.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;// w  w  w  . j a  v  a 2  s.  com
    }

    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:generadorPDF.generarPDF.java

private static void addMetaData(Document document) {
       document.addTitle("My first PDF");
       document.addSubject("Using iText");
       document.addKeywords("Java, PDF, iText");
       document.addAuthor("Lars Vogel");
       document.addCreator("Lars Vogel");
   }//from w ww.j  a v a 2  s  .  c  om

From source file:grupoj.entregajsf.toPDF.PdfCreator.java

private static void addEvent(Document doc, Evento ev) throws DocumentException {
    doc.addTitle(ev.getNombre());
    Paragraph evento = new Paragraph();
    evento.add(new Paragraph(ev.getNombre(), catFont));
    evento.add(new Paragraph(" "));
    evento.add(new Paragraph(ev.getDescripcion(), subFont));
    evento.add(new Paragraph(" "));
    evento.add(new Paragraph(
            "Fecha de inicio: " + new SimpleDateFormat("dd/MM/yyyy-HH:mm").format(ev.getFecha_inicio()),
            subFont));/*from w  w w. j  a  va 2  s  .co m*/
    evento.add(new Paragraph(
            "Fecha de fin:" + new SimpleDateFormat("dd/MM/yyyy-HH:mm").format(ev.getFecha_fin()), subFont));
    evento.add(new Paragraph(" "));
    evento.add(new Paragraph(ev.getDonde_comprar(), smallBold));
    evento.add(new Paragraph(" "));
    doc.add(evento);
}

From source file:GUI.Carburant.java

private static void addMetaData(Document document) {
    document.addTitle("Carburant PDF");
    document.addSubject("subject");
    document.addKeywords("Car Fleet Management, PDF, JAVA");
    document.addAuthor("Marwen");
    document.addCreator("Marwen");
}

From source file:GUI.Cars.java

private static void addMetaData(Document document) {
    document.addTitle("Cars PDF");
    document.addSubject("subject");
    document.addKeywords("Car Fleet Management, PDF, JAVA");
    document.addAuthor("Marwen");
    document.addCreator("Marwen");
}

From source file:GUI.Fixings.java

private static void addMetaData(Document document) {
    document.addTitle("Fixing PDF");
    document.addSubject("subject");
    document.addKeywords("Car Fleet Management, PDF, JAVA");
    document.addAuthor("Marwen");
    document.addCreator("Marwen");
}