Example usage for com.itextpdf.text.pdf PdfPCell addElement

List of usage examples for com.itextpdf.text.pdf PdfPCell addElement

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell addElement.

Prototype

public void addElement(Element element) 

Source Link

Document

Adds an iText element to the cell.

Usage

From source file:fenix.planner.pdf.PDFGenerator.java

License:Open Source License

private void createAndAddEventTable() throws DocumentException {
    PdfPTable table = new PdfPTable(new float[] { 1, 7, 1.2f });
    table.setWidthPercentage(100f);/*from www  .  j av  a 2  s .c  om*/
    table.getDefaultCell().setUseAscender(true);
    table.getDefaultCell().setUseDescender(true);
    table.setSpacingBefore(20);
    table.setSpacingAfter(20);

    // Header row
    table.getDefaultCell().setBorderWidthLeft(0);
    table.getDefaultCell().setBorderWidthTop(0);
    table.getDefaultCell().setBorderWidthRight(0);
    table.getDefaultCell().setPadding(5);
    table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
    table.addCell(new Phrase("Datum", headerFont));
    table.addCell(new Phrase("mne", headerFont));
    table.addCell(new Phrase("Ansvarig", headerFont));
    table.setHeaderRows(1);
    table.getDefaultCell().setBackgroundColor(null);

    // Events
    for (Event event : program.getSortedCopyOfEvents()) {
        if (event.getDate().getMonthOfYear() % 2 == 0) {
            table.getDefaultCell().setBackgroundColor(new BaseColor(0xdd, 0xdd, 0xdd));
        } else {
            table.getDefaultCell().setBackgroundColor(null);
        }

        if (!event.getType().getBackgroundColor().equals(Color.WHITE)) {
            table.getDefaultCell()
                    .setBackgroundColor(awtColorToBaseColor(event.getType().getBackgroundColor()));
        }

        final BaseColor textColor = awtColorToBaseColor(event.getType().getForegroundColor());

        PdfPCell dateCell = new PdfPCell(table.getDefaultCell());
        dateCell.addElement(
                new Phrase(event.getDate().toString("dd.MM", locale), changeColor(subjectFont, textColor)));
        table.addCell(dateCell);

        PdfPCell subjectCell = new PdfPCell(table.getDefaultCell());
        subjectCell.addElement(new Phrase(event.getSubject(), changeColor(subjectFont, textColor)));
        if (event.getDescription().length() > 0) {
            subjectCell.addElement(new Phrase(event.getDescription(), changeColor(descriptionFont, textColor)));
        }
        if (event.getOrganizer() == null) {
            subjectCell.setColspan(2);
        }
        table.addCell(subjectCell);

        if (event.getOrganizer() != null) {
            PdfPCell organizerCell = new PdfPCell(table.getDefaultCell());
            organizerCell.addElement(
                    new Phrase(event.getOrganizer().getInitials(), changeColor(subjectFont, textColor)));
            table.addCell(organizerCell);
        }
    }

    document.add(table);
}

From source file:fll.web.playoff.ScoresheetGenerator.java

License:Open Source License

public void writeFile(final OutputStream out, final boolean orientationIsPortrait) throws DocumentException {

    // This creates our new PDF document and declares its orientation
    Document pdfDoc;/* w  ww  . j  a  va2s. c om*/
    if (orientationIsPortrait) {
        pdfDoc = new Document(PageSize.LETTER); // portrait
    } else {
        pdfDoc = new Document(PageSize.LETTER.rotate()); // landscape
    }
    PdfWriter.getInstance(pdfDoc, out);

    // Measurements are always in points (72 per inch)
    // This sets up 1/2 inch margins side margins and 0.35in top and bottom
    // margins
    pdfDoc.setMargins(0.5f * POINTS_PER_INCH, 0.5f * POINTS_PER_INCH, 0.35f * POINTS_PER_INCH,
            0.35f * POINTS_PER_INCH);
    pdfDoc.open();

    // Header cell with challenge title to add to both scoresheets
    final Paragraph titleParagraph = new Paragraph();
    final Chunk titleChunk = new Chunk(m_pageTitle,
            FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14, Font.NORMAL, BaseColor.WHITE));
    titleParagraph.setAlignment(Element.ALIGN_CENTER);
    titleParagraph.add(titleChunk);

    titleParagraph.add(Chunk.NEWLINE);
    final Chunk swVersionChunk = new Chunk("SW version: " + Version.getVersion(),
            FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE));
    titleParagraph.add(swVersionChunk);
    if (null != m_revision) {

        final Chunk revisionChunk = new Chunk(" Descriptor revision: " + m_revision,
                FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE));

        titleParagraph.add(revisionChunk);
    }

    final PdfPCell head = new PdfPCell();
    head.setColspan(2);
    head.setBorder(1);
    head.setPaddingTop(0);
    head.setPaddingBottom(3);
    head.setBackgroundColor(new BaseColor(64, 64, 64));
    head.setVerticalAlignment(Element.ALIGN_TOP);
    head.addElement(titleParagraph);

    // Cells for score field, and 2nd check initials
    final Phrase des = new Phrase("Data Entry Score _______", ARIAL_8PT_NORMAL);
    final PdfPCell desC = new PdfPCell(des);
    desC.setBorder(0);
    desC.setPaddingTop(9);
    desC.setPaddingRight(36);
    desC.setHorizontalAlignment(Element.ALIGN_RIGHT);
    final Phrase sci = new Phrase("2nd Check Initials _______", ARIAL_8PT_NORMAL);
    final PdfPCell sciC = new PdfPCell(sci);
    sciC.setBorder(0);
    sciC.setPaddingTop(9);
    sciC.setPaddingRight(36);
    sciC.setHorizontalAlignment(Element.ALIGN_RIGHT);

    // Create a table with a grid cell for each scoresheet on the page
    PdfPTable wholePage = getTableForPage(orientationIsPortrait);
    wholePage.setWidthPercentage(100);
    for (int i = 0; i < m_numSheets; i++) {
        if (i > 0 && (orientationIsPortrait || (i % 2) == 0)) {
            pdfDoc.newPage();
            wholePage = getTableForPage(orientationIsPortrait);
            wholePage.setWidthPercentage(100);
        }

        // This table is a single score sheet
        final PdfPTable scoreSheet = new PdfPTable(2);
        // scoreSheet.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.BOTTOM
        // | Rectangle.RIGHT | Rectangle.TOP); //FIXME DEBUG should be NO_BORDER
        scoreSheet.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        scoreSheet.getDefaultCell().setPaddingRight(1);
        scoreSheet.getDefaultCell().setPaddingLeft(0);

        scoreSheet.addCell(head);

        final PdfPTable teamInfo = new PdfPTable(7);
        teamInfo.setWidthPercentage(100);
        teamInfo.setWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, .9f });

        // Time label cell
        final Paragraph timeP = new Paragraph("Time:", ARIAL_10PT_NORMAL);
        timeP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell timeLc = new PdfPCell(scoreSheet.getDefaultCell());
        timeLc.addElement(timeP);
        teamInfo.addCell(timeLc);
        // Time value cell
        final Paragraph timeV = new Paragraph(null == m_time[i] ? SHORT_BLANK : m_time[i], COURIER_10PT_NORMAL);
        final PdfPCell timeVc = new PdfPCell(scoreSheet.getDefaultCell());
        timeVc.addElement(timeV);
        teamInfo.addCell(timeVc);

        // Table label cell
        final Paragraph tblP = new Paragraph("Table:", ARIAL_10PT_NORMAL);
        tblP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell tblLc = new PdfPCell(scoreSheet.getDefaultCell());
        tblLc.addElement(tblP);
        teamInfo.addCell(tblLc);
        // Table value cell
        final Paragraph tblV = new Paragraph(m_table[i], COURIER_10PT_NORMAL);
        final PdfPCell tblVc = new PdfPCell(scoreSheet.getDefaultCell());
        tblVc.addElement(tblV);
        teamInfo.addCell(tblVc);

        // Round number label cell
        final Paragraph rndP = new Paragraph("Round:", ARIAL_10PT_NORMAL);
        rndP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell rndlc = new PdfPCell(scoreSheet.getDefaultCell());
        rndlc.addElement(rndP);
        teamInfo.addCell(rndlc);
        // Round number value cell
        final Paragraph rndV = new Paragraph(m_round[i], COURIER_10PT_NORMAL);
        final PdfPCell rndVc = new PdfPCell(scoreSheet.getDefaultCell());
        // rndVc.setColspan(2);
        rndVc.addElement(rndV);
        teamInfo.addCell(rndVc);

        final PdfPCell temp1 = new PdfPCell(scoreSheet.getDefaultCell());
        // temp1.setColspan(2);
        temp1.addElement(new Paragraph("Judge ____", ARIAL_8PT_NORMAL));
        teamInfo.addCell(temp1);

        // Team number label cell
        final Paragraph nbrP = new Paragraph("Team #:", ARIAL_10PT_NORMAL);
        nbrP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell nbrlc = new PdfPCell(scoreSheet.getDefaultCell());
        nbrlc.addElement(nbrP);
        teamInfo.addCell(nbrlc);
        // Team number value cell
        final Paragraph nbrV = new Paragraph(null == m_number[i] ? SHORT_BLANK : String.valueOf(m_number[i]),
                COURIER_10PT_NORMAL);
        final PdfPCell nbrVc = new PdfPCell(scoreSheet.getDefaultCell());
        nbrVc.addElement(nbrV);
        teamInfo.addCell(nbrVc);

        // Team division label cell
        final Paragraph divP = new Paragraph(m_divisionLabel[i], ARIAL_10PT_NORMAL);
        divP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell divlc = new PdfPCell(scoreSheet.getDefaultCell());
        divlc.addElement(divP);
        divlc.setColspan(2);
        teamInfo.addCell(divlc);
        // Team division value cell
        final Paragraph divV = new Paragraph(m_division[i], COURIER_10PT_NORMAL);
        final PdfPCell divVc = new PdfPCell(scoreSheet.getDefaultCell());
        divVc.setColspan(2);
        divVc.addElement(divV);
        teamInfo.addCell(divVc);

        final PdfPCell temp2 = new PdfPCell(scoreSheet.getDefaultCell());
        // temp2.setColspan(2);
        temp2.addElement(new Paragraph("Team ____", ARIAL_8PT_NORMAL));
        teamInfo.addCell(temp2);

        // Team name label cell
        final Paragraph nameP = new Paragraph("Team Name:", ARIAL_10PT_NORMAL);
        nameP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell namelc = new PdfPCell(scoreSheet.getDefaultCell());
        namelc.setColspan(2);
        namelc.addElement(nameP);
        teamInfo.addCell(namelc);
        // Team name value cell
        final Paragraph nameV = new Paragraph(m_name[i], COURIER_10PT_NORMAL);
        final PdfPCell nameVc = new PdfPCell(scoreSheet.getDefaultCell());
        nameVc.setColspan(5);
        nameVc.addElement(nameV);
        teamInfo.addCell(nameVc);

        // add team info cell to the team table
        final PdfPCell teamInfoCell = new PdfPCell(scoreSheet.getDefaultCell());
        teamInfoCell.addElement(teamInfo);
        teamInfoCell.setColspan(2);

        scoreSheet.addCell(teamInfoCell);

        if (null != m_goalsTable) {
            final PdfPCell goalCell = new PdfPCell(m_goalsTable);
            goalCell.setBorder(0);
            goalCell.setPadding(0);
            goalCell.setColspan(2);
            scoreSheet.addCell(goalCell);
        }

        scoreSheet.addCell(desC);
        scoreSheet.addCell(sciC);

        if (null != m_copyright) {
            final Phrase copyright = new Phrase("\u00A9" + m_copyright, f6i);
            final PdfPCell copyrightC = new PdfPCell(scoreSheet.getDefaultCell());
            copyrightC.addElement(copyright);
            copyrightC.setBorder(0);
            copyrightC.setHorizontalAlignment(Element.ALIGN_CENTER);
            copyrightC.setColspan(2);

            scoreSheet.addCell(copyrightC);
        }

        // the cell in the whole page table that will contain the single score
        // sheet
        final PdfPCell scoresheetCell = new PdfPCell(scoreSheet);
        scoresheetCell.setBorder(0);
        scoresheetCell.setPadding(0);

        // Interior borders between scoresheets on a page
        if (!orientationIsPortrait) {
            if (i % 2 == 0) {
                scoresheetCell.setPaddingRight(0.1f * POINTS_PER_INCH);
            } else {
                scoresheetCell.setPaddingLeft(0.1f * POINTS_PER_INCH);
            }
        }

        // Add the current scoresheet to the page
        wholePage.addCell(scoresheetCell);

        // Add the current table of scoresheets to the document
        if (orientationIsPortrait || (i % 2 != 0)) {
            pdfDoc.add(wholePage);
        }
    }

    // Add a blank cells to complete the table of the last page
    if (!orientationIsPortrait && m_numSheets % 2 != 0) {
        final PdfPCell blank = new PdfPCell();
        blank.setBorder(0);
        wholePage.addCell(blank);
        pdfDoc.add(wholePage);
    }

    pdfDoc.close();
}

From source file:fll.web.playoff.ScoresheetGenerator.java

License:Open Source License

/**
 * Stores the goal cells that are inserted into the output after the team name
 * headers and before the scoring/initials blanks at the bottom of the
 * scoresheet./*from w  ww  . ja  v  a2  s . c om*/
 */
private void setChallengeInfo(final ChallengeDescription description) {
    setPageTitle(description.getTitle());

    if (null != description.getRevision()) {
        setRevisionInfo(description.getRevision());
    }

    if (null != description.getCopyright()) {
        m_copyright = description.getCopyright();
    } else {
        m_copyright = null;
    }

    final PerformanceScoreCategory performanceElement = description.getPerformance();
    // use ArrayList as we will be doing indexed access in the loop
    final List<AbstractGoal> goals = new ArrayList<>(performanceElement.getGoals());

    final float[] relativeWidths = new float[3];
    relativeWidths[0] = 4;
    relativeWidths[1] = 48;
    relativeWidths[2] = 48;
    m_goalsTable = new PdfPTable(relativeWidths);

    String prevCategory = null;
    for (int goalIndex = 0; goalIndex < goals.size(); ++goalIndex) {
        final AbstractGoal goal = goals.get(goalIndex);
        if (!goal.isComputed()) {
            final String category = goal.getCategory();

            // add category cell if needed
            boolean firstRowInCategory = false;
            if (!StringUtils.equals(prevCategory, category)) {
                if (!StringUtils.isEmpty(category)) {

                    // find out how many future goals have the same category
                    int categoryRowSpan = 1;
                    for (int otherIndex = goalIndex + 1; otherIndex < goals.size(); ++otherIndex) {
                        final AbstractGoal otherGoal = goals.get(otherIndex);
                        if (!otherGoal.isComputed()) {
                            if (StringUtils.equals(category, otherGoal.getCategory())) {
                                ++categoryRowSpan;
                            } else {
                                break;
                            }
                        }
                    }

                    final Paragraph catPara = new Paragraph(category, ARIAL_10PT_NORMAL);
                    final PdfPCell categoryCell = new PdfPCell(catPara);
                    categoryCell.setBorderWidthTop(1);
                    categoryCell.setBorderWidthBottom(0);
                    categoryCell.setBorderWidthLeft(0);
                    categoryCell.setBorderWidthRight(0);
                    categoryCell.setVerticalAlignment(Element.ALIGN_CENTER);
                    categoryCell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    categoryCell.setRotation(90);
                    categoryCell.setRowspan(categoryRowSpan);
                    m_goalsTable.addCell(categoryCell);
                }

                // first row in a new category, which may be empty
                firstRowInCategory = true;
            }

            // This is the text for the left hand "label" cell
            final String title = goal.getTitle();
            final Paragraph p = new Paragraph(title, ARIAL_10PT_NORMAL);
            final PdfPCell goalLabel = new PdfPCell(p);
            goalLabel.setHorizontalAlignment(Element.ALIGN_RIGHT);
            goalLabel.setVerticalAlignment(Element.ALIGN_CENTER);
            if (firstRowInCategory) {
                goalLabel.setBorderWidthTop(1);
                goalLabel.setBorderWidthBottom(0);
                goalLabel.setBorderWidthLeft(0);
                goalLabel.setBorderWidthRight(0);
            } else {
                goalLabel.setBorder(0);
            }
            goalLabel.setPaddingRight(9);
            goalLabel.setVerticalAlignment(Element.ALIGN_TOP);
            if (StringUtils.isEmpty(category)) {
                // category column and goal label column
                goalLabel.setColspan(2);
            }
            m_goalsTable.addCell(goalLabel);

            // define the value cell
            final double min = goal.getMin();
            final String minStr = FP.equals(min, Math.round(min), 1E-6) ? String.valueOf((int) min)
                    : String.valueOf(min);
            final double max = goal.getMax();
            final String maxStr = FP.equals(max, Math.round(max), 1E-6) ? String.valueOf((int) max)
                    : String.valueOf(max);

            // If element has child nodes, then we have an enumerated list
            // of choices. Otherwise it is either yes/no or a numeric field.
            final PdfPCell goalValue = new PdfPCell();
            final Chunk choices = new Chunk("", COURIER_10PT_NORMAL);
            if (goal.isEnumerated()) {
                // replace spaces with "no-break" spaces
                boolean first = true;
                final List<EnumeratedValue> values = goal.getSortedValues();
                for (final EnumeratedValue value : values) {
                    if (!first) {
                        choices.append(" /" + Utilities.NON_BREAKING_SPACE);
                    } else {
                        first = false;
                    }
                    choices.append(value.getTitle().toUpperCase().replace(' ', Utilities.NON_BREAKING_SPACE));
                }
                goalValue.addElement(choices);

            } else {
                if (goal.isYesNo()) {
                    // order of yes/no needs to match ScoreEntry.generateYesNoButtons
                    final Paragraph q = new Paragraph("NO / YES", COURIER_10PT_NORMAL);
                    goalValue.addElement(q);

                } else {
                    final String range = "(" + minStr + " - " + maxStr + ")";
                    final PdfPTable t = new PdfPTable(2);
                    t.setHorizontalAlignment(Element.ALIGN_LEFT);
                    t.setTotalWidth(1 * POINTS_PER_INCH);
                    t.setLockedWidth(true);
                    final Phrase r = new Phrase("", ARIAL_8PT_NORMAL);
                    t.addCell(new PdfPCell(r));
                    final Phrase q = new Phrase(range, ARIAL_8PT_NORMAL);
                    t.addCell(new PdfPCell(q));
                    goalValue.setPaddingTop(9);
                    goalValue.addElement(t);
                }
            }

            if (firstRowInCategory) {
                goalValue.setBorderWidthTop(1);
                goalValue.setBorderWidthBottom(0);
                goalValue.setBorderWidthLeft(0);
                goalValue.setBorderWidthRight(0);
            } else {
                goalValue.setBorder(0);
            }
            goalValue.setVerticalAlignment(Element.ALIGN_MIDDLE);

            m_goalsTable.addCell(goalValue);

            // setup for next loop
            prevCategory = category;
        } // if not computed goal

    } // foreach goal

}

From source file:fr.ybonnel.breizhcamppdf.PdfRenderer.java

License:Apache License

private List<Talk> createProgrammePages() throws DocumentException, IOException {
    List<Talk> talksToExplain = new ArrayList<>();
    document.setPageSize(PageSize.A4.rotate());
    Font font = new Font();
    font.setStyle(Font.BOLD);/* ww  w.  ja  v  a2  s .c o m*/
    font.setSize(14);

    for (String date : service.getDates()) {

        Set<String> tracksInPage = new HashSet<>();

        Map<String, Talk> precedentTalk = new HashMap<>();
        PdfPTable table = createBeginningOfPage(font, date);
        for (String creneau : service.getCreneaux().get(date)) {
            // Nouvelle page  14h
            if (creneau.startsWith("14:00") && !tracksInPage.isEmpty()) {
                document.add(table);

                addLegend(tracksInPage);
                table = createBeginningOfPage(font, date);
            }

            PdfPCell cellCreneau = new PdfPCell();
            cellCreneau.setPaddingBottom(10);
            Paragraph startTime = new Paragraph(creneau);
            startTime.setAlignment(Element.ALIGN_CENTER);
            cellCreneau.addElement(startTime);
            Paragraph endTime = new Paragraph(getEndTime(date, creneau));
            endTime.setAlignment(Element.ALIGN_CENTER);
            cellCreneau.addElement(endTime);
            table.addCell(cellCreneau);
            for (String room : service.getRooms(date)) {
                PdfPCell cell = new PdfPCell();
                cell.setPaddingBottom(10);
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);

                Talk talk = service.getTalkByDateAndCreneauxAndRoom(date, creneau, room);
                if (talk != null) {
                    talksToExplain.add(talk);
                    remplirCellWithTalk(cell, talk);
                    cell.setRowspan(getRowSpan(date, talk));
                    precedentTalk.put(room, talk);
                    tracksInPage.add(talk.getTrack());
                    table.addCell(cell);
                } else {
                    talk = precedentTalk.get(room);
                    if (!(talk != null && talk.getEnd().compareTo(creneau) > 0)) {
                        table.addCell(cell);
                    }
                }
            }
        }
        document.add(table);
        addLegend(tracksInPage);
    }
    return talksToExplain;
}

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  .j av a  2  s.com*/
    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  w w w  .  j  a  v a2 s .  co m
    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 List<Talk> createProgrammePages() throws DocumentException, IOException {
    List<Talk> talksToExplain = new ArrayList<>();
    document.setPageSize(PageSize.A4);/* ww w.  jav  a2  s .co m*/
    Font font = new Font();
    font.setStyle(Font.BOLD);
    font.setSize(14);

    for (String date : service.getDates()) {

        for (String room : service.getRooms(date)) {

            Set<String> tracksInPage = new HashSet<>();

            Map<String, Talk> precedentTalk = new HashMap<>();
            PdfPTable table = createBeginningOfPage(font, date, room);
            for (String creneau : service.getCreneaux().get(date)) {

                PdfPCell cellCreneau = new PdfPCell();
                cellCreneau.setPaddingBottom(10);
                Paragraph startTime = new Paragraph(creneau);
                startTime.setAlignment(Element.ALIGN_CENTER);
                cellCreneau.addElement(startTime);
                Paragraph endTime = new Paragraph(getEndTime(date, creneau));
                endTime.setAlignment(Element.ALIGN_CENTER);
                cellCreneau.addElement(endTime);
                table.addCell(cellCreneau);

                PdfPCell cell = new PdfPCell();
                cell.setPaddingBottom(10);
                cell.setHorizontalAlignment(Element.ALIGN_LEFT);

                Talk talk = service.getTalkByDateAndCreneauxAndRoom(date, creneau, room);
                if (talk != null) {
                    talksToExplain.add(talk);
                    remplirCellWithTalk(cell, talk);
                    cell.setRowspan(getRowSpan(date, talk));
                    precedentTalk.put(room, talk);
                    tracksInPage.add(talk.getTrack());
                    table.addCell(cell);
                } else {
                    talk = precedentTalk.get(room);
                    if (!(talk != null && talk.getEnd().compareTo(creneau) > 0)) {
                        table.addCell(cell);
                    }
                }

            }
            document.add(table);
            addLegend(tracksInPage);
        }
    }
    return talksToExplain;
}

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);// w w  w  .j ava  2  s .co 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:Functions.pdf_Export.java

public void createHeader(Document doc, Integer soHoaDon) {
    try {/*from   w ww  .jav a 2s  .  c  o  m*/
        PdfPTable table = new PdfPTable(new float[] { 80, 20 });
        table.setWidthPercentage(100);

        LinkedHashMap<String, Font> lines = new LinkedHashMap<>();
        lines.put("Shop Name: " + shopName, titleFont);
        lines.put("Address: " + address, smallFont);
        lines.put("Phone Number: " + phoneNumb, smallFont);
        lines.put("Website: " + web, smallFont);
        lines.put("Email: " + email, smallFont);

        // left cell with shop's infor
        PdfPCell leftCell = new PdfPCell();
        leftCell.setPaddingTop(-7);
        leftCell.setPaddingRight(35);
        Set<String> singleLine = lines.keySet();
        // this below loop to create a line with text, and set it's font
        for (String line : singleLine) {
            leftCell.addElement(new Phrase(line, lines.get(line)));
        }
        leftCell.setHorizontalAlignment(Element.ALIGN_LEFT);
        leftCell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(leftCell);

        // right cell with bill's time
        String time = new HoaDonDAO().getHoaDon(soHoaDon).getNgayLapHoaDon().toString();
        PdfPCell rightCell = new PdfPCell();
        rightCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        rightCell.addElement(new Phrase("Date: " + time + "\nNo.: " + soHoaDon, smallFont));

        rightCell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(rightCell);

        doc.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(pdf_Export.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:fxml.test.PDFService.java

public PdfPTable createFooter1() {

    //String[] names = new String[]{"Md. Eamin Rahman", "Md. Mujibur Rahman", "Md Masum", "Md. Saiful Islam", "Husne Ara Chowdhury", "Sabir Ismail"};
    PdfPTable table = new PdfPTable(5);
    table.setHorizontalAlignment(Element.ALIGN_LEFT);

    try {//  w  w w .j  a v a  2 s. c om
        table.setTotalWidth(new float[] { 161f, 161f, 133f, 167f, 161f });
        table.setLockedWidth(true);

    } catch (DocumentException ex) {
        Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex);
    }
    //table.setWidthPercentage(100);
    PdfPCell chairmanSIgnature = new PdfPCell(new Paragraph("Signature of the Chairman:", font9));
    chairmanSIgnature.setBorder(Rectangle.NO_BORDER);
    chairmanSIgnature.setPaddingLeft(0f);
    chairmanSIgnature.setPaddingTop(5);
    table.addCell(chairmanSIgnature);

    PdfPCell underLine = new PdfPCell(new Paragraph("_______________________"));
    underLine.setBorder(Rectangle.NO_BORDER);
    table.addCell(underLine);

    PdfPCell blankColumn = new PdfPCell(new Paragraph(" "));
    blankColumn.setBorder(Rectangle.NO_BORDER);
    table.addCell(blankColumn);

    Paragraph p = new Paragraph("Signature of The Controller of Examinations:", font9);
    p.setLeading(0, 1.3f);
    PdfPCell controllerSignature = new PdfPCell();
    controllerSignature.addElement(p);
    controllerSignature.setBorder(Rectangle.NO_BORDER);
    table.addCell(controllerSignature);
    table.addCell(underLine);

    PdfPCell cell1 = new PdfPCell(new Paragraph(inputs.get(5).trim(), font9));
    cell1.setPaddingTop(0f);
    cell1.setBorder(Rectangle.NO_BORDER);

    PdfPCell cell2 = new PdfPCell(new Paragraph(inputs.get(6).trim(), font9));
    cell2.setPaddingTop(0f);
    cell2.setBorder(Rectangle.NO_BORDER);

    PdfPCell nameColumn = new PdfPCell(new Paragraph("Name :", font9));
    nameColumn.setBorder(Rectangle.NO_BORDER);
    nameColumn.setPaddingLeft(0f);
    nameColumn.setPaddingTop(0f);

    PdfPCell nameColumn2 = new PdfPCell(new Paragraph("Name :", font9));
    nameColumn2.setBorder(Rectangle.NO_BORDER);
    nameColumn2.setPaddingTop(0f);

    table.addCell(nameColumn);
    table.addCell(cell1);
    table.addCell(blankColumn);
    table.addCell(nameColumn2);
    table.addCell(cell2);

    table.setSpacingAfter(23.5f);
    return table;
}