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

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

Introduction

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

Prototype

public void setPhrase(Phrase phrase) 

Source Link

Document

Sets the Phrase for this cell.

Usage

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

private void agregaTablaDePagos() throws DocumentException {
    PdfPTable t1 = new PdfPTable(9);
    float total = setTableHeading(t1, pagos);
    PdfPCell cTotal = new PdfPCell(new Phrase("Total", F_NORMAL));
    cTotal.setColspan(6);/*w w w  .  ja va  2s  . c o m*/
    cTotal.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
    t1.addCell(cTotal);
    Phrase phrase = new Phrase(String.valueOf(total).concat(" pesos"), F_NORMAL);
    PdfPCell cMontoTotal = new PdfPCell();
    cMontoTotal.setColspan(3);
    cMontoTotal.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cMontoTotal.setPhrase(phrase);
    t1.addCell(cMontoTotal);
    t1.setSpacingBefore(20);
    documento.add(t1);
}

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

private float setTableHeading(PdfPTable t1, Ingreso[] ingresos) {
    PdfPCell cConcepto = new PdfPCell(new Phrase("Concepto", F_CELL_HEADER_TEXT));
    cConcepto.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cConcepto.setColspan(3);//from  ww  w.  ja  v a  2s  . co m
    cConcepto.setBackgroundColor(new BaseColor(0xff009846));
    t1.addCell(cConcepto);
    PdfPCell cFecha = new PdfPCell(new Phrase("Fecha", F_CELL_HEADER_TEXT));
    cFecha.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cFecha.setColspan(3);
    cFecha.setBackgroundColor(new BaseColor(0xff009846));
    t1.addCell(cFecha);
    PdfPCell cMonto = new PdfPCell(new Phrase("Monto", F_CELL_HEADER_TEXT));
    cMonto.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cMonto.setColspan(3);
    cMonto.setBackgroundColor(new BaseColor(0xff009846));
    t1.addCell(cMonto);
    PdfPCell concepto;
    PdfPCell monto;
    PdfPCell fecha;
    float total = 0;
    boolean isTenue = false;
    for (Ingreso ingreso : ingresos) {
        concepto = new PdfPCell();
        concepto.setColspan(3);
        concepto.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        if (isTenue) {
            concepto.setPhrase(
                    new Phrase(ingreso.getConceptoDeIngreso().getConceptoDeIngreso(), F_CELL_HEADER_TEXT));
            concepto.setBackgroundColor(new BaseColor(0xaa009846));
        } else {
            concepto.setPhrase(new Phrase(ingreso.getConceptoDeIngreso().getConceptoDeIngreso()));
        }
        t1.addCell(concepto);
        fecha = new PdfPCell();
        fecha.setColspan(3);
        fecha.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        if (isTenue) {
            fecha.setBackgroundColor(new BaseColor(0xaa009846));
            fecha.setPhrase(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault())
                    .format(new Date(ingreso.getFecha())), F_CELL_HEADER_TEXT));
        } else {
            fecha.setPhrase(new Phrase(DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.getDefault())
                    .format(new Date(ingreso.getFecha()))));
        }
        t1.addCell(fecha);
        monto = new PdfPCell();
        monto.setColspan(3);
        monto.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        if (isTenue) {
            monto.setBackgroundColor(new BaseColor(0xaa009846));
            monto.setPhrase(new Phrase(String.format("%.2f pesos", ingreso.getMonto()), F_CELL_HEADER_TEXT));
        } else {
            monto.setPhrase(new Phrase(String.format("%.2f pesos", ingreso.getMonto())));
        }
        t1.addCell(monto);
        total += ingreso.getMonto();
        isTenue = !isTenue;
        System.out.println("Total: " + total);
    }
    return total;
}

From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java

License:Open Source License

private void insertCell(PdfPTable table, String text, int colSpan) {
    Chunk chunk;/*from  w w  w .  ja  v  a 2 s . co  m*/
    chunk = new Chunk(text);
    PdfPCell cell = table.getDefaultCell();
    cell.setPhrase(new Phrase(chunk));
    cell.setColspan(colSpan);
    table.addCell(cell);
}

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

License:Open Source License

/**
 * Create a PDF File/*from   w w  w  . ja  v a 2s . co  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//from ww  w  .  j  a v a 2s  .c  om
 * @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:pdf.PDFDesign.java

private PdfPCell createEuroCell(Item item) throws DocumentException, IOException {
    Font descFont = new Font(droidsans, 12, Font.NORMAL, color);
    Font unitPriceFont = new Font(droidsans, 10, Font.NORMAL, color);

    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100f);//  w  w w.  j  av  a 2s  .com
    PdfPCell cell;
    Paragraph p;

    cell = new PdfPCell();
    p = new Paragraph();
    p.setFont(descFont);
    p.add(item.getTitle());
    cell.setFixedHeight(28f);
    cell.setPhrase(p);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBorder(0);
    table.addCell(cell);

    cell = new PdfPCell();
    p = new Paragraph();
    p.setFont(descFont);
    p.add(item.getAmount() + item.getUnit());
    cell.setFixedHeight(16f);
    cell.setPhrase(p);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBorder(0);
    table.addCell(cell);

    table.addCell(createEuroInnerPrice(item));

    cell = new PdfPCell();
    p = new Paragraph();
    p.setFont(unitPriceFont);
    p.add("Cena za 1" + item.getXUnit() + ": " + item.getUnitPrice() + item.getCurrency() + "/"
            + item.getSecondUnitPrice() + item.getSecondCurrency());
    cell.setPhrase(p);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBorder(0);
    cell.setLeading(2f, 0f);
    table.addCell(cell);

    PdfPCell finalCell = new PdfPCell(table);
    finalCell.setFixedHeight(117.4f);
    finalCell.setBorderColor(BaseColor.GRAY);
    return finalCell;
}

From source file:pdf.PDFDesign.java

private PdfPCell createEuro_6_Cell(Item item) throws DocumentException {
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100f);/*from   www.ja v a 2 s. c om*/

    PdfPCell cell;
    Paragraph p;

    cell = new PdfPCell();
    p = new Paragraph();
    p.setFont(new Font(droidsans, 13, Font.NORMAL, color));
    String t = item.getTitle();
    String[] split = t.split("//");
    for (String split1 : split) {
        p.add(split1 + "\n");
    }
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setPhrase(p);
    cell.setColspan(2);
    cell.setFixedHeight(30f);
    cell.setBorder(0);
    table.addCell(cell);

    cell = new PdfPCell();
    p = new Paragraph();
    p.setFont(new Font(droidsans, 11, Font.NORMAL, color));
    p.add(item.getAmount() + "" + item.getUnit());
    cell.setPhrase(p);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(0);
    table.addCell(cell);

    table.addCell(createEuro_6_InnerPrice(item));

    cell = new PdfPCell();
    p = new Paragraph();
    p.setFont(new Font(droidsans, 11, Font.NORMAL, color));
    p.add("Cena za 1" + item.getXUnit() + ": " + item.getUnitPrice() + item.getCurrency() + "/"
            + item.getSecondUnitPrice() + item.getSecondCurrency());
    cell.setPhrase(p);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBorder(0);
    table.addCell(cell);

    PdfPCell finalCell = new PdfPCell(table);
    finalCell.setFixedHeight(cellHeight);//175f
    finalCell.setBorderColor(BaseColor.GRAY);
    return finalCell;
}

From source file:pdf.PdfUtility.java

private PdfPCell getSummaryCell(Achievement a) {
    PdfPCell summaryCell = new PdfPCell();
    summaryCell.setBorder(PdfPCell.NO_BORDER);

    Phrase summaryPhrase = null;//from w  w  w  . j  a v a2 s .com
    if (a instanceof Academic) {
        Academic aux = (Academic) a;
        summaryPhrase = new SummaryPhrase(aux);
    } else if (a instanceof Professional) {
        Professional aux = (Professional) a;
        summaryPhrase = new SummaryPhrase(aux);
    } else if (a instanceof Certification) {
        Certification aux = (Certification) a;
        summaryPhrase = new SummaryPhrase(aux);
    } else if (a instanceof Linguistic) {
        Linguistic aux = (Linguistic) a;
        summaryPhrase = new SummaryPhrase(aux);
    } else if (a instanceof Entrepeneurship) {
        Entrepeneurship aux = (Entrepeneurship) a;
        summaryPhrase = new SummaryPhrase(aux);
    } else if (a instanceof Social) {
        Social aux = (Social) a;
        summaryPhrase = new SummaryPhrase(aux);
    } else if (a instanceof Other) {
        Other aux = (Other) a;
        summaryPhrase = new SummaryPhrase(aux);
    }
    summaryCell.setPhrase(summaryPhrase);

    return summaryCell;
}

From source file:reportes.ServletIntegral.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    HttpSession session = request.getSession();
    ServletConfig config = getServletConfig();
    ServletContext context = config.getServletContext();
    String path = context.getContextPath();
    String realPath = context.getRealPath("/");
    response.setContentType("application/pdf");
    //Para descargar el PDF
    response.setHeader("Content-Disposition", "attachment; filename=\"ResultadoIntegral.pdf\"");
    // step 1: creation of a document-object
    try {/*from  w w  w  .ja  va2  s  . c  o m*/
        Document document = new Document(PageSize.LETTER);
        // step 2:
        // we create a writer that listens to the document
        // and directs a PDF-stream to a temporary buffer
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        PdfWriter.getInstance(document, buffer);
        // step 3: we open the document
        document.open();
        // step 4: we add  content to the document
        Paragraph title = new Paragraph(
                (session.getAttribute("nEmpresa") != null) ? session.getAttribute("nEmpresa").toString()
                        : "Empresa");
        title.setAlignment(Element.ALIGN_CENTER);
        title.setFont(NORMAL);
        document.add(title);
        title = new Paragraph("Estado de resultado integral del 01 de Enero al 31 de Diciembre del "
                + (new Date().getYear() + 1900));
        title.setAlignment(Element.ALIGN_CENTER);
        title.setFont(NORMAL);
        document.add(title);
        title = new Paragraph("Cifras en miles de pesos");
        title.setAlignment(Element.ALIGN_CENTER);
        title.setFont(NORMAL);
        document.add(title);
        for (int i = 0; i < 2; i++) {
            document.add(new Paragraph(" "));
        }
        PdfPTable table = new PdfPTable(2);
        //Obtenemos los datos de la clase ResultadoIntegral
        ResultadoIntegral r = new ResultadoIntegral();
        r.calculaResultado(Integer.parseInt(session.getAttribute("Empresa").toString()));
        for (int i = 0; i < r.getSaldos().size(); i++) {
            PdfPCell dato = new PdfPCell();
            if (i == 2 || i == 7 || i == 12 || i == 14 || i == 16 || i == 18 || i == 19 || i == 17) {
                Chunk ch = new Chunk(descripciones[i]);
                ch.setFont(BOLD_Tot);
                Phrase ph = new Phrase(ch);
                dato.setPhrase(ph);
            } else {
                Phrase ph = new Phrase(descripciones[i]);
                dato.setPhrase(ph);
            }
            dato.setBorder(Rectangle.NO_BORDER);
            dato.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(dato);
            if (r.getValores().size() > 0) {
                Chunk ch = new Chunk();
                if (r.getSaldos().get(i) < 0) {
                    String valor = "(" + (r.getSaldos().get(i) * (-1)) + ")";
                    ch.append(valor);
                    ch.setFont(NORMAL_Negative);
                } else {
                    dato.setPhrase(new Phrase("" + r.getSaldos().get(i)));
                }
            } else {
                dato.setPhrase(new Phrase("0.0"));
            }
            if (i == 1 || i == 6 || i == 11 || i == 13 || i == 15 || i == 17 || i == 18) {
                dato.setBorder(Rectangle.BOTTOM);
            } else {
                dato.setBorder(Rectangle.NO_BORDER);
            }
            dato.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(dato);
        }
        document.add(table);
        document.add(new Paragraph(""));
        // step 5: we close the document
        document.close();
        // step 6: we output the writer as bytes to the response output
        DataOutputStream output = new DataOutputStream(response.getOutputStream());
        byte[] bytes = buffer.toByteArray();
        response.setContentLength(bytes.length);
        for (int i = 0; i < bytes.length; i++) {
            output.writeByte(bytes[i]);
        }
        output.close();
        response.getOutputStream();
        //session.removeAttribute("bean");
        //session.removeAttribute("producto");
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}