Example usage for com.itextpdf.text Paragraph setAlignment

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

Introduction

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

Prototype

public void setAlignment(int alignment) 

Source Link

Document

Sets the alignment of this paragraph.

Usage

From source file:org.cejug.yougi.web.report.EventAttendeeCertificate.java

License:Open Source License

public void generateCertificate(Attendee attendee) throws DocumentException {

    Font helvetica = new Font(Font.FontFamily.HELVETICA, 12);
    BaseFont baseFont = helvetica.getCalculatedBaseFont(false);
    canvas.saveState();// w ww.ja  va2  s . c om
    canvas.beginText();
    canvas.setFontAndSize(baseFont, 12);
    canvas.showTextAligned(Element.ALIGN_LEFT, "Validation code: " + attendee.getCertificateCode()
            + " ( http://www.cejug.org/certificate_validation.xhtml) ", 30, 30, 0);
    canvas.endText();
    canvas.restoreState();

    String[] contentLine = new String[8];
    contentLine[0] = "Certificamos que";
    contentLine[1] = attendee.getCertificateFullname();
    contentLine[2] = "participou do evento";
    contentLine[3] = attendee.getCertificateEvent();
    contentLine[4] = "realizado na";
    contentLine[5] = attendee.getCertificateVenue();
    contentLine[6] = "no dia "
            + TextUtils.INSTANCE.getFormattedDate(attendee.getCertificateDate(), "dd.MM.yyyy");

    Font normalFont = new Font(Font.FontFamily.HELVETICA, 24);
    Font largeFont = new Font(Font.FontFamily.HELVETICA, 28, Font.FontStyle.BOLD.ordinal());
    Paragraph p;

    for (int i = 0; i < 5; i++) {
        p = new Paragraph(" ", normalFont);
        this.document.add(p);
    }

    Font currentFont = normalFont;
    for (int i = 0; i < contentLine.length; i++) {
        p = new Paragraph(contentLine[i], currentFont);
        p.setAlignment(Element.ALIGN_CENTER);
        this.document.add(p);

        currentFont = currentFont.equals(normalFont) ? largeFont : normalFont;
    }
}

From source file:org.cherchgk.actions.tournament.result.show.GetPDFTournamentResultAction.java

License:Apache License

public InputStream getDocument() throws DocumentException, IOException {
    Font normalFont = getNormalFont();
    Font boldFont = getBoldFont();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Document document = new Document();
    PdfWriter.getInstance(document, out);
    document.open();/*w  w w  .jav  a 2  s. c  o  m*/

    Paragraph tournamentNameParagraph = new Paragraph(tournament.getTitle(), boldFont);
    tournamentNameParagraph.setAlignment(Element.ALIGN_CENTER);
    document.add(tournamentNameParagraph);

    Paragraph tournamentDateParagraph = new Paragraph(tournament.getDateAsString(), boldFont);
    tournamentDateParagraph.setAlignment(Element.ALIGN_CENTER);
    document.add(tournamentDateParagraph);

    if (teamCategory != null) {
        Paragraph teamCategoryParagraph = new Paragraph(teamCategory.getTitle(), boldFont);
        teamCategoryParagraph.setAlignment(Element.ALIGN_CENTER);
        document.add(teamCategoryParagraph);
    }

    int numColumns = 3 + tournamentResult.getRankingAlgorithms().size();
    PdfPTable resultTable = new PdfPTable(numColumns);
    int[] widths = new int[numColumns];
    widths[0] = 1;
    widths[1] = 3;
    for (int i = 2; i < numColumns; i++) {
        widths[i] = 1;
    }
    resultTable.setWidths(widths);
    resultTable.setSpacingBefore(10f);

    PdfPCell cell = new PdfPCell(new Phrase("", boldFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setColspan(2);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    resultTable.addCell(cell);

    for (RankingAlgorithm rankingAlgorithm : tournamentResult.getRankingAlgorithms()) {
        cell = new PdfPCell(new Phrase(rankingAlgorithm.getPointName(), boldFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        resultTable.addCell(cell);
    }

    cell = new PdfPCell(new Phrase("?", boldFont));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    resultTable.addCell(cell);

    boolean showTeamCategoryInTable = (teamCategory == null) && !tournament.getTeamCategories().isEmpty();

    for (TournamentResult.TeamResult teamResult : tournamentResult.getTeamResultList()) {
        if (showTeamCategoryInTable) {
            if (teamResult.getTeam().getTeamCategory() != null) {
                cell = new PdfPCell(new Phrase(teamResult.getTeam().getTeamCategory().getTitle(), normalFont));
            } else {
                cell = new PdfPCell(new Phrase("", normalFont));
            }
            resultTable.addCell(cell);
        }
        cell = new PdfPCell(new Phrase(teamResult.getTeam().getName(), normalFont));
        if (!showTeamCategoryInTable) {
            cell.setColspan(2);
        }
        resultTable.addCell(cell);
        for (Map<Team, RankingPoint> m : tournamentResult.getRankingPointsList()) {
            cell = new PdfPCell(new Phrase(m.get(teamResult.getTeam()).toString(), normalFont));
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
            resultTable.addCell(cell);
        }
        cell = new PdfPCell(new Phrase(teamResult.getPlace(), normalFont));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        resultTable.addCell(cell);
    }

    document.add(resultTable);
    document.close();

    return new ByteArrayInputStream(out.toByteArray());
}

From source file:org.fatec.lpbd.projetocurriculo.controller.CurriculoHelper.java

public static Paragraph simpleText(String text) {
    Font f = new Font(FontFamily.COURIER, 10, Font.NORMAL);
    Paragraph p = new Paragraph(text, f);
    p.setAlignment(Element.PARAGRAPH);
    return p;/*from  w ww .  j a  v  a  2  s .  c o m*/
}

From source file:org.fatec.lpbd.projetocurriculo.controller.CurriculoHelper.java

public static Paragraph titleString(String text) {
    Font f = new Font(FontFamily.COURIER, 20, Font.BOLD);
    Paragraph p = new Paragraph(text, f);
    p.setAlignment(Element.ALIGN_CENTER);
    p.setSpacingAfter(20);//from   w w  w .j a  va  2  s. com
    return p;
}

From source file:org.fossa.rolp.util.PdfStreamSource.java

License:Open Source License

private void addFacheinschaetzungen(Chapter chapterLEB, PdfWriter writer)
        throws DocumentException, PdfFormatierungsException {
    for (LebFacheinschaetzungData facheinschaetzungsdaten : lebData.getFacheinschaetzungsdaten()) {
        sectionCount += 1;/* www.j  a  v a  2s . c om*/
        breakHurenkind(writer);
        breakSchusterjunge(writer);
        Paragraph paragraphFacheinschaetzung = new Paragraph();
        Section facheinschaetzungsTextSection = chapterLEB.addSection(paragraphFacheinschaetzung);
        facheinschaetzungsTextSection.setNumberDepth(0);
        Collection<String> fachbezeichnungen = facheinschaetzungsdaten.getFachbezeichnungen();
        fachbezeichnungen.add(facheinschaetzungsdaten.getFachname());

        String facheinschaetzung = facheinschaetzungsdaten.getFacheinschaetzung();

        Integer firstIndex = null;
        String boldedWord = "";
        for (String fachbezeichnung : fachbezeichnungen) {
            int index = facheinschaetzung.toLowerCase().indexOf(fachbezeichnung.toLowerCase());
            if (index != -1 && (firstIndex == null || firstIndex > index)) {
                firstIndex = index;
                boldedWord = fachbezeichnung;
            }
        }
        Paragraph facheinschaetzungParapgraph = new Paragraph();
        facheinschaetzungParapgraph.setAlignment(Element.ALIGN_JUSTIFIED);
        facheinschaetzungParapgraph.setLeading(FIXED_LEADING_TEXT, zeilenabstandsfaktor);
        if (firstIndex == null) {
            facheinschaetzungParapgraph.add(new Phrase(
                    facheinschaetzungsdaten.getFacheinschaetzung().replace('\t', '\0'), standardTextFont));
        } else {
            String beforeBoldWord = facheinschaetzung.substring(0, firstIndex);
            facheinschaetzungParapgraph.add(new Phrase(beforeBoldWord.replace('\t', '\0'), standardTextFont));

            String boldWord = facheinschaetzung.substring(firstIndex, firstIndex + boldedWord.length());
            facheinschaetzungParapgraph.add(new Phrase(boldWord, standardTextBoldFont));

            String afterBoldWord = facheinschaetzung.substring(firstIndex + boldedWord.length());
            facheinschaetzungParapgraph.add(new Phrase(afterBoldWord.replace('\t', '\0'), standardTextFont));
        }
        facheinschaetzungParapgraph.setFont(standardTextFont);
        facheinschaetzungsTextSection.add(facheinschaetzungParapgraph);
        Paragraph unterschriftParagraph = new Paragraph();
        document.add(facheinschaetzungsTextSection);
        Section facheinschaetzungsUnterschriftSection = chapterLEB.addSection(unterschriftParagraph);
        facheinschaetzungsUnterschriftSection.setNumberDepth(0);
        unterschriftParagraph.add(
                new Phrase(facheinschaetzungsdaten.getUnterschrift().replace('\t', '\0'), standardTextFont));
        unterschriftParagraph.setAlignment(Element.ALIGN_RIGHT);
        unterschriftParagraph.add(Chunk.NEWLINE);
        unterschriftParagraph.add(Chunk.NEWLINE);
        document.add(facheinschaetzungsUnterschriftSection);
        alertHurenkind(writer);
        insertDummyLineIfNecessary(writer);
    }
}

From source file:org.fossa.rolp.util.PdfStreamSource.java

License:Open Source License

private void addIndividuelleEinschaetzung(Chapter chapterLEB, PdfWriter writer)
        throws DocumentException, PdfFormatierungsException {
    if (!lebData.getIndividuelleEinschaetzung().isEmpty()) {
        sectionCount += 1;//from w ww .j  a va  2 s  . co m
        breakHurenkind(writer);
        breakSchusterjunge(writer);
        Paragraph paragraphIndividuelleEinschaetzung = new Paragraph();
        Section individuelleEinschaetzungsTextSection = chapterLEB
                .addSection(paragraphIndividuelleEinschaetzung);
        individuelleEinschaetzungsTextSection.setNumberDepth(0);
        Paragraph schuelereinschaetzungParapgraph = new Paragraph(
                lebData.getIndividuelleEinschaetzung().replace('\t', '\0'), standardTextFont);
        schuelereinschaetzungParapgraph.setAlignment(Element.ALIGN_JUSTIFIED);
        schuelereinschaetzungParapgraph.setLeading(FIXED_LEADING_TEXT, zeilenabstandsfaktor);
        individuelleEinschaetzungsTextSection.add(schuelereinschaetzungParapgraph);
        document.add(individuelleEinschaetzungsTextSection);
        document.add(getKlassenlehrerunterschrift(chapterLEB));
        alertHurenkind(writer);
        insertDummyLineIfNecessary(writer);
    }
}

From source file:org.fossa.rolp.util.PdfStreamSource.java

License:Open Source License

private void addKlassenbrief(Chapter chapterLEB, PdfWriter writer)
        throws DocumentException, PdfFormatierungsException {
    if (!lebData.getKlassenbrief().isEmpty()) {
        sectionCount += 1;/*  ww  w. j a v a  2s .c  o m*/
        breakSchusterjunge(writer);
        Paragraph paragraphKlassenbrief = new Paragraph();
        Section klassenbriefSection = chapterLEB.addSection(paragraphKlassenbrief);
        klassenbriefSection.setNumberDepth(0);
        Paragraph klasseneinschaetzungParapgraph = new Paragraph(lebData.getKlassenbrief().replace('\t', '\0'),
                standardTextFont);
        klasseneinschaetzungParapgraph.setAlignment(Element.ALIGN_JUSTIFIED);
        klasseneinschaetzungParapgraph.setLeading(FIXED_LEADING_TEXT, zeilenabstandsfaktor);
        klasseneinschaetzungParapgraph.add(Chunk.NEWLINE);
        if (lebData.getIndividuelleEinschaetzung().isEmpty()) {
            klassenbriefSection.add(klasseneinschaetzungParapgraph);
            document.add(klassenbriefSection);
            document.add(getKlassenlehrerunterschrift(chapterLEB));
        } else {
            klasseneinschaetzungParapgraph.add(Chunk.NEWLINE);
            klassenbriefSection.add(klasseneinschaetzungParapgraph);
            document.add(klassenbriefSection);
        }
        alertLonelyHeader(writer);
        insertDummyLineIfNecessary(writer);
    }
}

From source file:org.fossa.rolp.util.PdfStreamSource.java

License:Open Source License

private Section getKlassenlehrerunterschrift(Section chapterLEB) {
    Paragraph unterschriftParagraph = new Paragraph();
    Section klassenbriefUnterschriftSection = chapterLEB.addSection(unterschriftParagraph);
    klassenbriefUnterschriftSection.setNumberDepth(0);
    unterschriftParagraph//from  w  w  w. j a v a 2s . co m
            .add(new Phrase(lebData.getKlassenlehrerUnterschrift().replace('\t', '\0'), standardTextFont));
    unterschriftParagraph.setAlignment(Element.ALIGN_RIGHT);
    unterschriftParagraph.add(Chunk.NEWLINE);
    unterschriftParagraph.add(Chunk.NEWLINE);
    return klassenbriefUnterschriftSection;
}

From source file:org.ganttproject.impex.htmlpdf.itext.ThemeImpl.java

License:GNU General Public License

private PdfPTable createColontitleTable(String topLeft, String topRight, String bottomLeft,
        String bottomRight) {//from  w  w  w . j  av a 2 s  .  c om
    PdfPTable head = new PdfPTable(2);
    {
        PdfPCell cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        Paragraph p = new Paragraph(topLeft, getSansRegularBold(18));
        p.setAlignment(Paragraph.ALIGN_LEFT);
        // colontitle.setLeading(0);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        // cell.setPaddingLeft(2);
        cell.setPaddingBottom(6);
        cell.setPhrase(p);
        head.addCell(cell);
    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        Paragraph p = new Paragraph(topRight, getSansRegularBold(10));
        p.setAlignment(Paragraph.ALIGN_RIGHT);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell.setPaddingBottom(6);
        cell.setPhrase(p);
        head.addCell(cell);
    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setPaddingLeft(3);
        cell.setPaddingTop(2);
        cell.setPaddingBottom(6);
        cell.setBorder(Rectangle.TOP);
        cell.setBorderWidthTop(2);
        cell.setBorderColor(SORTAVALA_GREEN);
        Paragraph p = new Paragraph(bottomLeft, getSansRegularBold(18));
        p.setAlignment(Paragraph.ALIGN_LEFT);
        p.setExtraParagraphSpace(0);
        p.setIndentationLeft(0);
        p.setSpacingBefore(0);
        cell.setPhrase(p);
        // cell.addElement(p);
        head.addCell(cell);
    }
    {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingTop(2);
        cell.setPaddingBottom(6);
        cell.setBorder(Rectangle.TOP);
        cell.setBorderWidthTop(2);
        cell.setBorderColor(SORTAVALA_GREEN);
        Paragraph p = new Paragraph(bottomRight, getSansRegularBold(10));
        p.setAlignment(Paragraph.ALIGN_RIGHT);
        cell.setPhrase(p);
        head.addCell(cell);
    }
    final Document document = myDoc;
    Rectangle page = document.getPageSize();
    head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
    return head;
}

From source file:org.inspira.condominio.pdf.DocumentoEstadoDeCuenta.java

private void bakeContent(String path, String imgResString) throws IOException, DocumentException {
    File outFile = new File(path);
    outFile.getParentFile().mkdirs();/*from   ww  w .  j a  va2s . c om*/
    PdfWriter.getInstance(documento, new FileOutputStream(outFile));
    documento.open();
    documento.add(new Paragraph(
            "Ciudad de Mxico, "
                    + DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(new Date()),
            new Font(FontFamily.HELVETICA, 18, Font.NORMAL, new BaseColor(0x000000))));
    Paragraph intro = new Paragraph(new Phrase("Comprobante de estado de cuenta", F_NORMAL));
    intro.setAlignment(Paragraph.ALIGN_RIGHT);
    intro.setSpacingBefore(10f);
    documento.add(intro);
    Image image = Image.getInstance(imgResString);
    PdfPTable table = new PdfPTable(1);
    table.setTotalWidth(image.getScaledWidth());
    table.setLockedWidth(true);
    PdfPCell cell = new PdfPCell();
    cell.setBorder(0);
    //cell.setCellEvent(new ImageBackgroundEvent(image));
    cell.setFixedHeight(image.getScaledHeight());
    table.addCell(cell);
    documento.add(table);
    Paragraph p1 = new Paragraph("Estado de cuenta: ".concat(idEdoCta), F_NORMAL);
    p1.setSpacingBefore(5f);
    p1.setSpacingAfter(25f);
    p1.setAlignment(Paragraph.ALIGN_CENTER);
    documento.add(p1);
    documento.add(new Paragraph("Pagos", F_NORMAL));
    agregaTablaDePagos();
    Paragraph pNotas = new Paragraph("Notas: ".concat(notas), F_NORMAL);
    pNotas.setSpacingAfter(12f);
    pNotas.setSpacingAfter(2f);
    documento.add(pNotas);
    Paragraph pAdeudos = new Paragraph("Adeudos", F_NORMAL);
    pAdeudos.setSpacingBefore(25f);
    documento.add(pAdeudos);
    agregaTablaDeAdeudos();
    documento.add(new Paragraph(
            "Recuerde que puede consultar su estado de pagos y adeudos desde la aplicacin mvil o directamente con su administrador.",
            F_NORMAL));
    Paragraph hechoPor = new Paragraph("Elabor:", F_NORMAL);
    hechoPor.setSpacingBefore(30f);
    hechoPor.setSpacingAfter(15f);
    documento.add(hechoPor);
    Paragraph nombreDelAdmin = new Paragraph(admin, F_NORMAL);
    nombreDelAdmin.setAlignment(Paragraph.ALIGN_CENTER);
    documento.add(nombreDelAdmin);
    Paragraph nombreDeCondominio = new Paragraph(condominio, F_NORMAL);
    nombreDeCondominio.setAlignment(Paragraph.ALIGN_CENTER);
    documento.add(nombreDeCondominio);
}