Example usage for com.itextpdf.text Paragraph getFont

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

Introduction

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

Prototype

public Font getFont() 

Source Link

Document

Gets the font of the first Chunk that appears in this Phrase.

Usage

From source file:com.github.wolfposd.imsqti2pdf.PDFCreator.java

License:Open Source License

private void addQuestionText(Paragraph paragraph, Question question, int questionnumber) throws IOException {
    String fixedFonts = question.questiontext.replace("font-size: 12pt", "font-size: 10pt");

    fixedFonts = fixedFonts.replace("face=\"courier new\"", "face=\"Courier\"");

    fixedFonts = fixedFonts.replace("src=\"media/", getPathToMedia());

    ArrayList<Element> htmllist = (ArrayList<Element>) HTMLWorker.parseToList(new StringReader(fixedFonts),
            null);/*  w ww.j a v  a2  s  .  com*/

    ArrayList<Paragraph> codeParagraphs = new ArrayList<Paragraph>();

    for (int i = 0; i < htmllist.size(); i++) {
        Element e = htmllist.get(i);
        if (e instanceof Paragraph) {
            Paragraph p = (Paragraph) e;
            if (i == 0) {
                p.setIndentationLeft(INDENTATION);
                p.getFont().setSize(OVERALLFONTSIZE);
                p.add(0, getQuestionNumberChunk(p.getFont(), questionnumber));
                p.add(getPointsChunk(p.getFont(), question));
                paragraph.add(p);
            } else {
                codeParagraphs.add(p);
            }
        }
    }
    if (codeParagraphs.size() > 0) {
        PdfPTable table = new PdfPTable(1);
        table.setWidthPercentage(90);
        table.setKeepTogether(true);

        Paragraph codeParagraph = new Paragraph();

        for (Paragraph p : codeParagraphs) {
            p.setIndentationLeft(INDENTATION);
            p.getFont().setSize(OVERALLFONTSIZE);
            codeParagraph.add(p);
            fixFonts(p);
        }
        codeParagraph.add(Chunk.NEWLINE);

        PdfPCell cell = new PdfPCell();
        cell.addElement(codeParagraph);
        cell.setBorderColor(BaseColor.BLACK);
        table.addCell(cell);

        paragraph.add(Chunk.NEWLINE);
        paragraph.add(table);
    }
}

From source file:com.github.wolfposd.imsqti2pdf.PDFCreator.java

License:Open Source License

private void fixFonts(Paragraph para) {
    for (Element element : para) {
        if (element instanceof Paragraph) {
            Paragraph p = (Paragraph) element;
            p.getFont().setSize(OVERALLFONTSIZE);
            fixFonts(p);//from  w  w w  . jav a2s . co  m
        } else if (element instanceof Chunk) {
            Chunk c = (Chunk) element;
            c.getFont().setSize(OVERALLFONTSIZE);
        } else if (element instanceof List) {
        } else if (element instanceof PdfPTable) {
            PdfPTable table = (PdfPTable) element;
            for (Chunk c : table.getChunks()) {
                c.getFont().setSize(OVERALLFONTSIZE);
            }
        } else {
            // System.out.println(element);
        }
    }
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java

License:Open Source License

protected Paragraph getDefaultParagraph() {

    Paragraph result = new Paragraph();
    result.setFont(CONTENT_NORMAL);//from  www. j  a va  2 s.c om
    result.setAlignment(Element.ALIGN_JUSTIFIED);
    result.setSpacingAfter(result.getFont().getSize() * 1.5f);
    return result;
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java

License:Open Source License

protected Phrase getDefaultPhrase() {

    Paragraph result = new Paragraph();
    result.setFont(CONTENT_NORMAL);//from www .  j a  va2s .  c  o m
    result.setAlignment(Element.ALIGN_JUSTIFIED);
    result.setSpacingAfter(result.getFont().getSize() * 1.5f);
    return result;
}

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

License:Apache License

private void createFirstPage() throws DocumentException, IOException {
    Rectangle savePagesize = document.getPageSize();
    document.setPageSize(PageSize.A4);//w  ww. j a  v a 2 s.  c o  m
    document.newPage();
    Image imageLogo = Image.getInstance(PdfRenderer.class.getResource("/logo.png"));
    imageLogo.scaleToFit(document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(),
            imageLogo.getHeight());
    document.add(imageLogo);

    Paragraph paragraph = new Paragraph("21, 22 et 23 mai");
    paragraph.setSpacingAfter(80);
    paragraph.getFont().setSize(20);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    document.add(paragraph);

    Paragraph title = new Paragraph("Programme 2014");
    title.setSpacingAfter(100);
    title.getFont().setSize(56);
    title.setAlignment(Element.ALIGN_CENTER);
    document.add(title);

    PdfPTable sponsors = new PdfPTable(4);
    sponsors.setWidthPercentage(90f);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/LogoZenika-H-(Quadri).jpg", 2);
    addSponsor(sponsors,
            "http://blogs.technet.com/resized-image.ashx/__size/450x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-80-54/6864.Microsoft-Logo.png",
            2);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/Google_Logo_3564x1189.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/cbpaas.jpeg", 1);
    addSponsor(sponsors, "https://github.global.ssl.fastly.net/images/modules/logos_page/GitHub-Logo.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/sonarsource-300x94.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/serli.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/Logo_sqli_group.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/SofteamCadextanLogo_w200.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/logoSII_w200.png", 1);
    document.add(sponsors);

    Image istic = Image.getInstance("http://www.breizhcamp.org/img/Logo_ISTIC_BLACK_FRA.jpg");
    istic.scaleToFit(150, 150);
    istic.setAlignment(Element.ALIGN_CENTER);
    document.add(istic);

    document.setPageSize(savePagesize);
}

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

License:Apache License

private void createTalksPages(List<Talk> talksToExplain) throws DocumentException, IOException {
    document.setPageSize(PageSize.A4);//w ww .j a v  a  2 s.  c  o 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:Measurment_Result_Record.MeasurmentSetup.java

/**
 *  write the given table datas to the given document
 * @param doc  document to write the result tables on
 * @param table  the result table /*from  w  w  w .ja v a2  s  .c o m*/
 * @param m_title   the measurment title
 */
public static void addResultTablesTotheDocument(Document doc, JTable table, String m_title)
        throws DocumentException {
    //add the measurment title and table
    Paragraph measurmenttitle = new Paragraph(m_title + "\n ");
    measurmenttitle.getFont().setStyle(com.itextpdf.text.Font.BOLD);
    doc.add(measurmenttitle);

    int colmWidth = table.getColumnCount();
    int rowCount = table.getModel().getRowCount();
    PdfPTable resultTable = new PdfPTable(colmWidth);
    resultTable.setHorizontalAlignment(Element.ALIGN_LEFT);

    //add the table headers
    for (int i = 0; i < colmWidth; i++) {
        String headertext = table.getModel().getColumnName(i);
        PdfPCell cell = new PdfPCell(new Paragraph(headertext));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        resultTable.addCell(cell);
    }

    //add the table body

    for (int r = 0; r < rowCount; r++) {
        for (int c = 0; c < colmWidth; c++) {
            String data = table.getValueAt(r, c).toString();
            resultTable.addCell(data);
        }
    }

    resultTable.setSpacingAfter(10);
    //add the table to the document
    doc.add(resultTable);

}

From source file:org.spinsuite.print.ReportPrintData.java

License:Open Source License

/**
 * Create a PDF File/*  w ww.  j a  va  2 s  . c o m*/
 * @author Yamel Senih, ysenih@erpcya.com, ERPCyA http://www.erpcya.com 02/04/2014, 22:52:09
 * @param outFile
 * @throws FileNotFoundException
 * @throws DocumentException
 * @return void
 */
private void createPDF(File outFile) throws FileNotFoundException, DocumentException {
    Document document = new Document(PageSize.LETTER);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outFile));
    PDFHeaderAndFooter event = new PDFHeaderAndFooter();
    writer.setPageEvent(event);
    document.open();
    //   
    document.addAuthor(ctx.getResources().getString(R.string.app_name));
    document.addCreationDate();
    //   
    Paragraph title = new Paragraph(m_reportQuery.getInfoReport().getName());
    //   Set Font
    title.getFont().setStyle(Font.BOLD);
    //   Set Alignment
    title.setAlignment(Paragraph.ALIGN_CENTER);
    //   Add Title
    document.add(title);
    //   Add New Line
    document.add(Chunk.NEWLINE);
    //   Parameters
    ProcessInfoParameter[] param = m_pi.getParameter();
    //   Get Parameter
    if (param != null) {
        //   
        boolean isFirst = true;
        //   Iterate
        for (ProcessInfoParameter para : param) {
            //   Get SQL Name
            String name = para.getInfo();
            StringBuffer textParameter = new StringBuffer();
            if (para.getParameter() == null && para.getParameter_To() == null)
                continue;
            else {
                //   Add Parameters Title
                if (isFirst) {
                    Paragraph titleParam = new Paragraph(
                            ctx.getResources().getString(R.string.msg_ReportParameters));
                    //   Set Font
                    titleParam.getFont().setStyle(Font.BOLDITALIC);
                    //   Add to Document
                    document.add(titleParam);
                    isFirst = false;
                }
                //   Add Parameters Name
                if (para.getParameter() != null && para.getParameter_To() != null) { //   From and To is filled
                    //   
                    textParameter.append(name).append(" => ").append(para.getDisplayValue()).append(" <= ")
                            .append(para.getDisplayValue_To());
                } else if (para.getParameter() != null) { //   Only From
                    //   
                    textParameter.append(name).append(" = ").append(para.getDisplayValue());
                } else if (para.getParameter_To() != null) { //   Only To
                    //   
                    textParameter.append(name).append(" <= ").append(para.getDisplayValue_To());
                }
            }
            //   Add to Document
            Paragraph viewParam = new Paragraph(textParameter.toString());
            document.add(viewParam);
        }
    }
    document.add(Chunk.NEWLINE);
    //   
    InfoReportField[] columns = m_reportQuery.getColumns();
    //   Add Table
    PdfPTable table = new PdfPTable(columns.length);
    table.setSpacingBefore(4);
    //   Add Header
    PdfPCell headerCell = new PdfPCell(new Phrase(m_reportQuery.getInfoReport().getName()));
    headerCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    headerCell.setColspan(columns.length);
    //   Add to Table
    table.addCell(headerCell);
    //   Add Header
    //   Decimal and Date Format
    DecimalFormat[] cDecimalFormat = new DecimalFormat[columns.length];
    SimpleDateFormat[] cDateFormat = new SimpleDateFormat[columns.length];
    for (int i = 0; i < columns.length; i++) {
        InfoReportField column = columns[i];
        //   Only Numeric
        if (DisplayType.isNumeric(column.DisplayType))
            cDecimalFormat[i] = DisplayType.getNumberFormat(ctx, column.DisplayType, column.FormatPattern);
        //   Only Date
        else if (DisplayType.isDate(column.DisplayType))
            cDateFormat[i] = DisplayType.getDateFormat(ctx, column.DisplayType, column.FormatPattern);
        //   
        Phrase phrase = new Phrase(column.PrintName);
        PdfPCell cell = new PdfPCell(phrase);
        if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        else
            cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
        //   
        table.addCell(cell);
    }
    //   Add Detail
    for (int row = 0; row < m_data.size(); row++) {
        //   Get Row
        RowPrintData rPrintData = m_data.get(row);
        //   Iterate
        for (int col = 0; col < columns.length; col++) {
            InfoReportField column = columns[col];
            ColumnPrintData cPrintData = rPrintData.get(col);
            Phrase phrase = null;
            PdfPCell cell = new PdfPCell();
            //   
            String value = cPrintData.getValue();
            //   Only Values
            if (value != null) {
                if (DisplayType.isNumeric(column.DisplayType)) { //   Number
                    //   Format
                    DecimalFormat decimalFormat = cDecimalFormat[col];
                    //   Format
                    if (decimalFormat != null)
                        value = decimalFormat.format(DisplayType.getNumber(value));
                    //   Set Value
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                } else if (DisplayType.isDate(column.DisplayType)) { //   Is Date
                    SimpleDateFormat dateFormat = cDateFormat[col];
                    if (dateFormat != null && value.trim().length() > 0) {
                        long date = Long.parseLong(value);
                        value = dateFormat.format(new Date(date));
                    }
                }
            }
            //   Set Value
            phrase = new Phrase(value);
            //   
            if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            else
                cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
            //   Set Font
            if (rPrintData.isFunctionRow()) {
                //   Set Function Value
                if (cPrintData.getFunctionValue() != null && cPrintData.getFunctionValue().length() > 0)
                    phrase = new Phrase(cPrintData.getFunctionValue());
                //   Set Font
                phrase.getFont().setStyle(Font.BOLDITALIC);
            }
            //   Add to Table
            cell.setPhrase(phrase);
            table.addCell(cell);
        }
    }
    //   Add Table to Document
    document.add(table);
    //   New Line
    document.add(Chunk.NEWLINE);
    //   Add Footer
    StringBuffer footerText = new StringBuffer(Env.getContext("#SUser"));
    footerText.append("(");
    footerText.append(Env.getContext("#AD_Role_Name"));
    footerText.append("@");
    footerText.append(Env.getContext("#AD_Client_Name"));
    footerText.append(".");
    footerText.append(Env.getContext("#AD_Org_Name"));
    footerText.append("{").append(Build.MANUFACTURER).append(".").append(Build.MODEL).append("}) ");
    //   Date
    SimpleDateFormat pattern = DisplayType.getDateFormat(ctx, DisplayType.DATE_TIME);
    footerText.append(" ").append(ctx.getResources().getString(R.string.Date)).append(" = ");
    footerText.append(pattern.format(new Date()));
    //   
    Paragraph footer = new Paragraph(footerText.toString());
    footer.setAlignment(Paragraph.ALIGN_CENTER);
    //   Set Font
    footer.getFont().setSize(8);
    //   Add Footer
    document.add(footer);
    //   Close Document
    document.close();
}

From source file:org.spinsuite.view.report.ReportPrintData.java

License:Open Source License

/**
 * Create a PDF File// w ww  .  j  av  a  2 s . co  m
 * @author <a href="mailto:yamelsenih@gmail.com">Yamel Senih</a> 02/04/2014, 22:52:09
 * @param outFile
 * @throws FileNotFoundException
 * @throws DocumentException
 * @return void
 */
private void createPDF(File outFile) throws FileNotFoundException, DocumentException {
    Document document = new Document(PageSize.LETTER);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outFile));
    PDFHeaderAndFooter event = new PDFHeaderAndFooter();
    writer.setPageEvent(event);
    document.open();
    //   
    document.addAuthor(ctx.getResources().getString(R.string.app_name));
    document.addCreationDate();
    //   
    Paragraph title = new Paragraph(m_reportQuery.getInfoReport().getName());
    //   Set Font
    title.getFont().setStyle(Font.BOLD);
    //   Set Alignment
    title.setAlignment(Paragraph.ALIGN_CENTER);
    //   Add Title
    document.add(title);
    //   Add New Line
    document.add(Chunk.NEWLINE);
    //   Parameters
    ProcessInfoParameter[] param = m_pi.getParameter();
    //   Get Parameter
    if (param != null) {
        //   
        boolean isFirst = true;
        //   Iterate
        for (ProcessInfoParameter para : param) {
            //   Get SQL Name
            String name = para.getInfo();
            StringBuffer textParameter = new StringBuffer();
            if (para.getParameter() == null && para.getParameter_To() == null)
                continue;
            else {
                //   Add Parameters Title
                if (isFirst) {
                    Paragraph titleParam = new Paragraph(
                            ctx.getResources().getString(R.string.msg_ReportParameters));
                    //   Set Font
                    titleParam.getFont().setStyle(Font.BOLDITALIC);
                    //   Add to Document
                    document.add(titleParam);
                    isFirst = false;
                }
                //   Add Parameters Name
                if (para.getParameter() != null && para.getParameter_To() != null) { //   From and To is filled
                    //   
                    textParameter.append(name).append(" => ").append(para.getDisplayValue()).append(" <= ")
                            .append(para.getDisplayValue_To());
                } else if (para.getParameter() != null) { //   Only From
                    //   
                    textParameter.append(name).append(" = ").append(para.getDisplayValue());
                } else if (para.getParameter_To() != null) { //   Only To
                    //   
                    textParameter.append(name).append(" <= ").append(para.getDisplayValue_To());
                }
            }
            //   Add to Document
            Paragraph viewParam = new Paragraph(textParameter.toString());
            document.add(viewParam);
        }
    }
    document.add(Chunk.NEWLINE);
    //   
    InfoReportField[] columns = m_reportQuery.getColumns();
    //   Add Table
    PdfPTable table = new PdfPTable(columns.length);
    table.setSpacingBefore(4);
    //   Add Header
    PdfPCell headerCell = new PdfPCell(new Phrase(m_reportQuery.getInfoReport().getName()));
    headerCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    headerCell.setColspan(columns.length);
    //   Add to Table
    table.addCell(headerCell);
    //   Add Header
    //   Decimal and Date Format
    DecimalFormat[] cDecimalFormat = new DecimalFormat[columns.length];
    SimpleDateFormat[] cDateFormat = new SimpleDateFormat[columns.length];
    for (int i = 0; i < columns.length; i++) {
        InfoReportField column = columns[i];
        //   Only Numeric
        if (DisplayType.isNumeric(column.DisplayType))
            cDecimalFormat[i] = DisplayType.getNumberFormat(ctx, column.DisplayType, column.FormatPattern);
        //   Only Date
        else if (DisplayType.isDate(column.DisplayType))
            cDateFormat[i] = DisplayType.getDateFormat(ctx, column.DisplayType, column.FormatPattern);
        //   
        Phrase phrase = new Phrase(column.PrintName);
        PdfPCell cell = new PdfPCell(phrase);
        if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        else
            cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
        //   
        table.addCell(cell);
    }
    //   Add Detail
    for (int row = 0; row < m_data.size(); row++) {
        //   Get Row
        RowPrintData rPrintData = m_data.get(row);
        //   Iterate
        for (int col = 0; col < columns.length; col++) {
            InfoReportField column = columns[col];
            ColumnPrintData cPrintData = rPrintData.get(col);
            Phrase phrase = null;
            PdfPCell cell = new PdfPCell();
            //   
            String value = cPrintData.getValue();
            if (DisplayType.isNumeric(column.DisplayType)) { //   Number
                //   Format
                DecimalFormat decimalFormat = cDecimalFormat[col];
                //   Format
                if (decimalFormat != null)
                    value = decimalFormat.format(DisplayType.getNumber(value));
                //   Set Value
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            } else if (DisplayType.isDate(column.DisplayType)) { //   Is Date
                SimpleDateFormat dateFormat = cDateFormat[col];
                if (dateFormat != null) {
                    long date = Long.getLong(value, 0);
                    value = dateFormat.format(new Date(date));
                }
            }
            //   Set Value
            phrase = new Phrase(value);
            //   
            if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            else
                cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
            //   Set Font
            if (rPrintData.isFunctionRow()) {
                //   Set Function Value
                if (cPrintData.getFunctionValue() != null && cPrintData.getFunctionValue().length() > 0)
                    phrase = new Phrase(cPrintData.getFunctionValue());
                //   Set Font
                phrase.getFont().setStyle(Font.BOLDITALIC);
            }
            //   Add to Table
            cell.setPhrase(phrase);
            table.addCell(cell);
        }
    }
    //   Add Table to Document
    document.add(table);
    //   New Line
    document.add(Chunk.NEWLINE);
    //   Add Footer
    StringBuffer footerText = new StringBuffer(Env.getContext(ctx, "#SUser"));
    footerText.append("(");
    footerText.append(Env.getContext(ctx, "#AD_Role_Name"));
    footerText.append("@");
    footerText.append(Env.getContext(ctx, "#AD_Client_Name"));
    footerText.append(".");
    footerText.append(Env.getContext(ctx, "#AD_Org_Name"));
    footerText.append("{").append(Build.MANUFACTURER).append(".").append(Build.MODEL).append("}) ");
    //   Date
    SimpleDateFormat pattern = DisplayType.getDateFormat(ctx, DisplayType.DATE_TIME);
    footerText.append(" ").append(ctx.getResources().getString(R.string.Date)).append(" = ");
    footerText.append(pattern.format(new Date()));
    //   
    Paragraph footer = new Paragraph(footerText.toString());
    footer.setAlignment(Paragraph.ALIGN_CENTER);
    //   Set Font
    footer.getFont().setSize(8);
    //   Add Footer
    document.add(footer);
    //   Close Document
    document.close();
}

From source file:Report.RelatorioAluno.java

/**
 * funcao para gerar o stream do relatorio
 *
 * @return ByteArrayOutputStream/*  w w  w  . jav  a2 s  .  c  o m*/
 */
public ByteArrayOutputStream relatorioAlunosMatriculados() {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    FacesContext faces = FacesContext.getCurrentInstance();
    // pega o contexto da aplicacao
    realPath = faces.getExternalContext().getRealPath("/");
    //realPath = "C:/Users/Alessandro/Desktop/TCC2/SisGES/build/web";

    try {
        BaseFont fHelvetica = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false);

        //----------------------------------------------------------------------
        // creation of the document with a certain size and certain margins
        // may want to use PageSize.LETTER instead
        Document document = new Document(PageSize.A4, 40, 40, 20, 50);
        document.addAuthor("SisGES"); // optional
        document.addSubject("Relatrio"); // opcional
        document.addKeywords("SisGES");
        document.addCreator("iText");
        //----------------------------------------------------------------------
        // creation of the different writers
        //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("web/resources/report/alunosMatriculados.pdf"));
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        writer.setBoxSize("header", new Rectangle(36, 54, 559, 788));
        //----------------------------------------------------------------------
        // ADICIONA HEADER E FOOTER
        //----------------------------------------------------------------------
        HeaderFooter headerFooter = new HeaderFooter();
        writer.setPageEvent(headerFooter);
        //----------------------------------------------------------------------
        // ABRE DOCUMENTO PARA ESCRITA
        //----------------------------------------------------------------------
        document.open();
        //----------------------------------------------------------------------
        //ADICIONAR LOGO NO DOCUMENTO
        //----------------------------------------------------------------------
        Image logoUfu = Image.getInstance(realPath + "/resources/images/logoUFU.png");
        logoUfu.scaleAbsolute(57, 56);//(largura,altura)
        logoUfu.isImgTemplate(); //add no template
        //logoUfu.setAbsolutePosition(30, 745); //x ,y por referencia do rodape
        document.add(logoUfu);

        Image logoFacom = Image.getInstance(realPath + "/resources/images/logoFacom.png");
        logoFacom.scaleAbsolute(62, 55);//(largura,altura)
        logoFacom.setAbsolutePosition(92, 767); //x ,y por referencia do rodape
        //logoFacom.isImgTemplate(); //add no template            
        document.add(logoFacom);

        //----------------------------------------------------------------------
        //ADICIONAR CABEALHO
        //----------------------------------------------------------------------
        PdfContentByte univ = writer.getDirectContentUnder();
        univ.beginText();
        univ.setFontAndSize(fHelvetica, 10);
        univ.setTextMatrix(349, 805); // x e y
        univ.showText("UNIVERSIDADE FEDERAL DE UBERLNDIA");
        univ.setTextMatrix(405, 790); // x e y
        univ.showText("FACULDADE DE COMPUTAO");
        univ.setTextMatrix(403, 775); // x e y
        univ.showText("COORDENADORIA DE ESTGIO ");
        univ.endText();

        PdfContentByte univEnd = writer.getDirectContentUnder();
        univEnd.beginText();
        univEnd.setFontAndSize(fHelvetica, 7);
        univEnd.setTextMatrix(326, 761); // x e y
        univEnd.showText("Campus Universitrio - Santa Mnica - CEP 38408-100 - Uberlndia - MG");
        univEnd.setTextMatrix(432, 750); // x e y
        univEnd.showText("Telefone: (34) 3239-4144 ou 3239-4393");
        univEnd.endText();

        //----------------------------------------------------------------------
        //ADICIONAR TITULO
        //----------------------------------------------------------------------
        PdfContentByte titulo = writer.getDirectContentUnder();
        titulo.beginText();
        titulo.setFontAndSize(fHelvetica, 16);
        titulo.setTextMatrix(210, 700); // x e y
        titulo.showText("Alunos Matrculados");
        titulo.endText();
        //----------------------------------------------------------------------

        //----------------------------------------------------------------------
        AlunoDAO aDAO = new AlunoDAO();
        List<Aluno> allAlunos = aDAO.getAllAlunos();
        aDAO.closeSession();

        PdfPTable table = new PdfPTable(5);

        table.setTotalWidth(100f);
        table.setWidthPercentage(100);
        float[] widths = { 10, 30, 30, 13, 17 };//largura das colunas
        table.setWidths(widths);
        table.setHeaderRows(1);

        Paragraph cabecalho = new Paragraph("Matricula");
        PdfPCell cellMatricula = new PdfPCell(cabecalho); // celula
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        cellMatricula.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cellMatricula.setBorderColor(BaseColor.LIGHT_GRAY);
        cellMatricula.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cellMatricula);

        cabecalho = new Paragraph("Nome");
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        PdfPCell cellNome = new PdfPCell(cabecalho); // celula
        cellNome.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cellNome.setBorderColor(BaseColor.LIGHT_GRAY);
        cellNome.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cellNome);

        cabecalho = new Paragraph("Email");
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        PdfPCell cellEmail = new PdfPCell(cabecalho); // celula
        cellEmail.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cellEmail.setBorderColor(BaseColor.LIGHT_GRAY);
        cellEmail.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cellEmail);

        cabecalho = new Paragraph("Telefone");
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        PdfPCell cellTelefone = new PdfPCell(cabecalho); // celula
        cellTelefone.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cellTelefone.setBorderColor(BaseColor.LIGHT_GRAY);
        cellTelefone.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cellTelefone);

        cabecalho = new Paragraph("Curso");
        cabecalho.getFont().setStyle(Font.BOLD);
        cabecalho.getFont().setSize(8);
        PdfPCell cellCurso = new PdfPCell(cabecalho); // celula
        cellCurso.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cellCurso.setBorderColor(BaseColor.LIGHT_GRAY);
        cellCurso.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cellCurso);

        for (int i = 0; i < allAlunos.size(); i++) {
            Aluno aluno = allAlunos.get(i);
            Paragraph texto = new Paragraph(aluno.getMatricula());
            cellMatricula = new PdfPCell(texto); // celula
            cellMatricula.setBorderColor(BaseColor.LIGHT_GRAY);
            texto.getFont().setSize(8);
            table.addCell(cellMatricula);
            texto = new Paragraph(aluno.getNome());
            texto.getFont().setSize(8);
            cellNome = new PdfPCell(texto); // celula
            cellNome.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cellNome);
            texto = new Paragraph(aluno.getEmail());
            texto.getFont().setSize(8);
            cellEmail = new PdfPCell(texto); // celula
            cellEmail.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cellEmail);
            texto = new Paragraph(aluno.getTelefone());
            texto.getFont().setSize(8);
            cellTelefone = new PdfPCell(texto); // celula
            cellTelefone.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cellTelefone);
            texto = new Paragraph(aluno.getCursoidcurso().getNomecurso());
            texto.getFont().setSize(8);
            cellCurso = new PdfPCell(texto); // celula
            cellCurso.setBorderColor(BaseColor.LIGHT_GRAY);
            table.addCell(cellCurso);

        }
        table.setSpacingBefore(100);
        table.setSpacingAfter(10);
        table.completeRow();

        document.add(table);
        //add nova pagina
        document.newPage();
        //close document
        document.close();
    } catch (DocumentException | IOException ex) {
        Logger.getLogger(RelatorioAluno.class.getName()).log(Level.SEVERE, null, ex);
    } catch (Exception ex) {
        Logger.getLogger(RelatorioAluno.class.getName()).log(Level.SEVERE, null, ex);
    }
    //return stream
    return baos;
}