Example usage for com.itextpdf.text Paragraph setKeepTogether

List of usage examples for com.itextpdf.text Paragraph setKeepTogether

Introduction

In this page you can find the example usage for com.itextpdf.text Paragraph setKeepTogether.

Prototype

public void setKeepTogether(boolean keeptogether) 

Source Link

Document

Indicates that the paragraph has to be kept together on one page.

Usage

From source file:com.kohmiho.mpsr.export.PDFGenerator.java

private void addImage(Document document, String filename, String caption, Font font, int indentationLeft,
        int spacingBefore, int spacingAfter)
        throws BadElementException, MalformedURLException, IOException, DocumentException {

    if (null == filename) {
        addParagraph(document, null, null, String.format("[*** No Picture for %s ***]", caption), font,
                indentationLeft, 0, 0);//from   ww  w .  j  av a  2  s.  co  m
        return;
    }

    try {
        Paragraph paragraph = new Paragraph();
        paragraph.setIndentationLeft(indentationLeft);
        paragraph.setSpacingBefore(spacingBefore);
        paragraph.setSpacingAfter(spacingAfter);
        if (null != font)
            paragraph.setFont(font);
        paragraph.setKeepTogether(true);
        paragraph.setAlignment(Element.ALIGN_CENTER);

        Image image = Image.getInstance(filename);
        image.scaleToFit(400, 400);

        paragraph.add(new Chunk(image, 0, 0, true));
        paragraph.add(new Chunk("\n"));
        paragraph.add(caption);
        document.add(paragraph);
    } catch (Exception e) {
        addParagraph(document, null, null, String.format("[*** Unable to render picture for %s ***]", caption),
                font, indentationLeft, 0, 0);
    }
}

From source file:fll.scheduler.TournamentSchedule.java

License:Open Source License

/**
 * Output the detailed schedule for a team for the day.
 * /* ww  w  . ja  v  a  2s  .  c o m*/
 * @throws DocumentException
 */
private void outputTeamSchedule(final SchedParams params, final Document detailedSchedules,
        final TeamScheduleInfo si) throws DocumentException {
    final Paragraph para = new Paragraph();
    para.add(new Chunk(
            String.format("Detailed schedule for Team #%d - %s", si.getTeamNumber(), si.getTeamName()),
            TEAM_TITLE_FONT));
    para.add(Chunk.NEWLINE);

    para.add(new Chunk(String.format("Organization: %s", si.getOrganization()), TEAM_TITLE_FONT));
    para.add(Chunk.NEWLINE);

    para.add(new Chunk("Division: ", TEAM_HEADER_FONT));
    para.add(new Chunk(si.getAwardGroup(), TEAM_VALUE_FONT));
    para.add(Chunk.NEWLINE);

    for (final String subjectiveStation : subjectiveStations) {
        para.add(new Chunk(subjectiveStation + ": ", TEAM_HEADER_FONT));
        final LocalTime start = si.getSubjectiveTimeByName(subjectiveStation).getTime();
        final LocalTime end = start.plus(params.getStationByName(subjectiveStation).getDuration());
        para.add(new Chunk(String.format("%s - %s", formatTime(start), formatTime(end)), TEAM_VALUE_FONT));
        para.add(Chunk.NEWLINE);
    }

    for (int round = 0; round < getNumberOfRounds(); ++round) {
        para.add(new Chunk(String.format(PERF_HEADER_FORMAT, round + 1) + ": ", TEAM_HEADER_FONT));
        final LocalTime start = si.getPerfTime(round);
        final LocalTime end = start.plus(Duration.ofMinutes(params.getPerformanceMinutes()));
        para.add(new Chunk(String.format("%s - %s %s %d", formatTime(start), formatTime(end),
                si.getPerfTableColor(round), si.getPerfTableSide(round)), TEAM_VALUE_FONT));
        para.add(Chunk.NEWLINE);
    }

    para.add(Chunk.NEWLINE);
    para.add(new Chunk(
            "Performance rounds must start on time, and will start without you. Please ensure your team arrives at least 5 minutes ahead of scheduled time, and checks in.",
            TEAM_HEADER_FONT));

    para.add(Chunk.NEWLINE);
    para.add(new Chunk(
            "Note that there may be more judging and a head to head round after this judging, please see the main tournament schedule for these details.",
            TEAM_HEADER_FONT));
    para.add(Chunk.NEWLINE);
    para.add(Chunk.NEWLINE);
    para.add(Chunk.NEWLINE);

    para.setKeepTogether(true);
    detailedSchedules.add(para);
}