Example usage for com.lowagie.text.pdf PdfPCell setBackgroundColor

List of usage examples for com.lowagie.text.pdf PdfPCell setBackgroundColor

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPCell setBackgroundColor.

Prototype


public void setBackgroundColor(Color backgroundColor) 

Source Link

Document

Sets the backgroundcolor of the rectangle.

Usage

From source file:ambit.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

public void xml2pdf(InputSource xml, OutputStream pdf) {

    try {/*from   w w w.ja  va2  s .com*/
        Document document = new Document(PageSize.A4, 80, 50, 30, 65);

        PdfWriter writer = PdfWriter.getInstance(document, pdf);
        //writer.setViewerPreferences(PdfWriter.HideMenubar| PdfWriter.HideToolbar);
        writer.setViewerPreferences(PdfWriter.PageModeUseThumbs | PdfWriter.PageModeUseOutlines);
        //PdfOutline root = writer.getDirectContent().getRootOutline();
        //new PdfOutline(root, new PDFAction("http://nina.acad.bg/qmrf"), "a bookmark");

        //writer.addFileAttachment(arg0, arg1, arg2, arg3)

        if (docBuilder == null)
            docBuilder = docBuilderFactory.newDocumentBuilder();
        docBuilder.setErrorHandler(new SimpleErrorHandler(getClass().getName()));
        QMRFSchemaResolver resolver = new QMRFSchemaResolver("http://ambit.acad.bg/qmrf/qmrf.dtd", null);
        resolver.setIgnoreSystemID(true);
        docBuilder.setEntityResolver(resolver);

        org.w3c.dom.Document doc = null;
        try {
            doc = docBuilder.parse(xml);
        } catch (Exception x) {
            document.addCreationDate();
            document.addCreator(getClass().getName());
            document.open();
            document.add(new Paragraph(new Chunk(x.getMessage())));
            document.close();
            return;
        }

        document.addCreationDate();
        document.addCreator(getClass().getName());
        document.addKeywords(replaceTags(findNodeValue("keywords", doc)));
        document.addTitle(replaceTags(findNodeValue("QSAR_title", doc)));

        try {
            NodeList info = doc.getElementsByTagName("QMRF");
            for (int i = 0; i < info.getLength(); i++)
                document.addSubject(findAttributeValue("name", info.item(i)) + '.'
                        + findAttributeValue("version", info.item(i)));
        } catch (Exception x) {
            document.addSubject("QMRF");
        }
        try {
            document.addAuthor(listNodeAttributes(doc, "qmrf_authors", "author_ref", "author", att_author,
                    new Boolean(true)));
        } catch (Exception x) {
            document.addAuthor(getClass().getName());
        }

        document.open();
        PdfContentByte cb = writer.getDirectContent();

        try {
            headerTable(document, doc);
        } catch (Exception x) {
            document.add(new Paragraph(new Chunk(x.getMessage())));
            document.close();
            return;
        }

        PdfOutline root = writer.getDirectContent().getRootOutline();

        for (int i = 0; i < subchapters.length; i++)

            try {
                int align = Paragraph.ALIGN_LEFT;
                if (Mode.chapter == (Mode) subchapters[i][2]) {
                    document.add(new Paragraph(new Chunk('\n')));
                    PdfPTable table = new PdfPTable(1);

                    table.setWidthPercentage(100);

                    StringBuffer b = new StringBuffer();
                    b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter, doc));
                    b.append('.');
                    b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_name, doc));

                    String bookmark = b.toString();

                    Chunk title = new Chunk(bookmark);
                    title.setLocalDestination(bookmark);
                    title.setFont(bfont);

                    PdfDestination destination = new PdfDestination(PdfDestination.FITH);
                    PdfOutline outline = new PdfOutline(root, destination, bookmark);

                    Paragraph p = new Paragraph(title);

                    PdfPCell cell = new PdfPCell(p);
                    cell.setBackgroundColor(chapterColor);
                    table.addCell(cell);
                    document.add(table);
                    float pos = writer.getVerticalPosition(false);
                    if (pos < 90)
                        document.newPage();
                } else {
                    Phrase phrase = new Phrase();
                    switch ((Mode) subchapters[i][2]) {
                    case title: {
                        StringBuffer b = new StringBuffer();
                        String cn = findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter,
                                doc);
                        if (cn == null)
                            break;

                        b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter, doc));
                        b.append('.');
                        b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_name, doc));

                        String subchapterBookmark = b.toString();
                        b.append(':');

                        Chunk title = new Chunk(b.toString());
                        title.setLocalDestination(subchapterBookmark);
                        title.setFont(bfont);
                        phrase.add(title);

                        PdfDestination destination = new PdfDestination(PdfDestination.FITBH);
                        PdfOutline outline = new PdfOutline(root, destination, subchapterBookmark);

                        break;

                    }
                    case text: {
                        createNodePhrase(subchapters[i][0].toString(), doc, phrase, font);
                        align = Paragraph.ALIGN_JUSTIFIED;
                        break;
                    }
                    case answer: {
                        String a = findAnswer(subchapters[i][0].toString(), doc);
                        if (a != null) {
                            Chunk answer = new Chunk(a);
                            answer.setFont(font);
                            phrase.add(answer);
                        }
                        break;
                    }
                    case dataset: {
                        StringBuffer b = new StringBuffer();
                        b.append(findDataAvailable(subchapters[i][0].toString(), doc));
                        Chunk dataset = new Chunk(b.toString());
                        dataset.setFont(font);
                        phrase.add(dataset);
                        break;
                    }
                    case attachments: {
                        PdfPTable table = getAttachmentsAsTable(doc, "attachment_training_data");
                        if (table != null) {
                            phrase.add(new Paragraph("Training set(s)"));
                            phrase.add(table);
                        }
                        table = getAttachmentsAsTable(doc, "attachment_validation_data");
                        if (table != null) {
                            phrase.add(new Paragraph("Test set(s)"));
                            phrase.add(table);
                        }
                        table = getAttachmentsAsTable(doc, "attachment_documents");
                        if (table != null) {
                            phrase.add(new Paragraph("Supporting information"));
                            phrase.add(table);
                        }
                        break;
                        /*
                        StringBuffer b = new StringBuffer();
                        b.append("Training set(s)\n");
                         b.append(listAttachments(doc,"attachment_training_data"));
                         b.append("Test set(s)\n");
                         b.append(listAttachments(doc,"attachment_validation_data"));
                         b.append("Supporting information\n");
                         b.append(listAttachments(doc,"attachment_documents"));
                        Chunk attachments = new Chunk(b.toString());
                        attachments.setFont(font);
                        phrase.add(attachments);
                                
                        break;
                        */
                    }
                    case reference: {
                        try {
                            String value = listNodeAttributes(doc, subchapters[i][0].toString(),
                                    subchapters[i][3].toString(), subchapters[i][4].toString(),
                                    (String[]) subchapters[i][5], (Boolean) subchapters[i][6]);

                            Chunk reference = new Chunk(value);
                            reference.setFont(font);
                            align = Paragraph.ALIGN_JUSTIFIED;
                            phrase.add(reference);
                        } catch (Exception x) {

                        }
                        break;

                    }
                    }

                    Paragraph p = new Paragraph(phrase);
                    p.setAlignment(align);
                    document.add(p);
                    float pos = writer.getVerticalPosition(false);
                    /*
                    cb.moveTo(0, pos);
                    cb.lineTo(PageSize.A4.width(), pos);
                    cb.stroke();
                    */
                    if (pos < 90)
                        document.newPage();
                }
            } catch (Exception x) {
                x.printStackTrace();
            }

        document.close();

    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
    }
}

From source file:ambit.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

protected PdfPTable getAttachmentsAsTable(org.w3c.dom.Document doc, String attachments) {
    NodeList nodes = doc.getElementsByTagName(attachments);
    if (nodes.getLength() > 0) {

        float[] widths = { 3f, 3f };
        PdfPTable table = new PdfPTable(widths);
        table.setWidthPercentage(100);//  w  ww .j a va  2  s.  co  m
        for (int i = 0; i < nodes.getLength(); i++)
            if (nodes.item(i) instanceof org.w3c.dom.Element) {
                NodeList attachment = nodes.item(i).getChildNodes();
                if (attachment.getLength() == 0)
                    ;//b.append("N/A\n");
                else
                    for (int j = 0; j < attachment.getLength(); j++)
                        if (attachment.item(j) instanceof org.w3c.dom.Element) {
                            org.w3c.dom.Element e = ((org.w3c.dom.Element) attachment.item(j));

                            Paragraph p = new Paragraph(org.apache.commons.lang.StringEscapeUtils
                                    .unescapeXml(e.getAttribute("description")));
                            PdfPCell cell = new PdfPCell(p);
                            cell.setBackgroundColor(Color.white);
                            table.addCell(cell);

                            String c = org.apache.commons.lang.StringEscapeUtils
                                    .unescapeXml(e.getAttribute("url"));

                            PdfAction action = new PdfAction(c);
                            p = new Paragraph();
                            p.add(new Chunk(c).setAction(action));
                            cell = new PdfPCell(p);
                            cell.setBackgroundColor(Color.white);
                            table.addCell(cell);

                        }
            }
        return table;
    } else
        return null;

}

From source file:ambit.io.PDFWriter.java

License:Open Source License

@Override
protected void writeHeader() throws IOException {

    PdfPCell cell = new PdfPCell(new Paragraph("Structure"));
    cell.setBackgroundColor(Color.white);
    table.addCell(cell);//w  ww.  j a v  a 2s.com

    cell = new PdfPCell(new Paragraph("Properties"));
    cell.setBackgroundColor(Color.white);
    table.addCell(cell);

}

From source file:ambit.io.PDFWriter.java

License:Open Source License

public void writeMolecule(IMolecule molecule) {
    Object value;//  ww  w  .  j  a v a2  s  .co  m

    try {

        //give it a chance to create a header just before the first write
        if (!writingStarted) {
            if (header == null)
                setHeader(molecule.getProperties());
            writeHeader();
            writingStarted = true;
        }

        Paragraph p = new Paragraph("");
        String s;
        for (int i = 0; i < header.size(); i++) {
            StringBuffer b = new StringBuffer();
            b.append(header.getList().get(i));
            b.append(" = ");
            value = molecule.getProperty(header.getList().get(i));
            if (i == smilesIndex) {

                if (value == null) //no SMILES available
                    try {
                        value = ""; //sg.createSMILES(molecule);
                    } catch (Exception x) {
                        logger.error("Error while createSMILES\t", x.getMessage());
                        value = "";
                    }
            }
            if (value != null) {
                if (value instanceof Number) {
                    s = value.toString();
                } else {
                    s = value.toString();

                }

                b.append(s);
                p.add(new Paragraph(b.toString()));
            }

        }
        BufferedImage image = imageTools.getImage(molecule);
        image.flush();

        Image png_struc = Image.getInstance(image, Color.white);
        png_struc.setAlignment(Image.LEFT);
        png_struc.scalePercent(100);

        PdfPCell cell = new PdfPCell();
        cell.setMinimumHeight(cell.height());
        cell.addElement(png_struc);
        table.addCell(cell);

        cell = new PdfPCell(p);
        cell.setBackgroundColor(Color.white);
        table.addCell(cell);

    } catch (Exception x) {
        logger.error("ERROR while writing Molecule: ", x.getMessage());
        logger.debug(x);
        x.printStackTrace();
    }

}

From source file:ambit2.core.io.PDFWriter.java

License:Open Source License

public void writeMolecule(IMolecule molecule) {
    Object value;/*from w  w  w . j a  v  a  2 s. co  m*/

    try {

        //give it a chance to create a header just before the first write
        if (!writingStarted) {
            if (header == null)
                setHeader(molecule.getProperties());
            writeHeader();
            writingStarted = true;
        }

        Paragraph p = new Paragraph("");
        String s;
        for (int i = 0; i < header.size(); i++) {
            StringBuffer b = new StringBuffer();
            b.append(header.get(i));
            b.append(" = ");
            value = molecule.getProperty(header.get(i));
            if (i == smilesIndex) {

                if (value == null) //no SMILES available
                    try {
                        value = ""; //sg.createSMILES(molecule);
                    } catch (Exception x) {
                        logger.log(Level.WARNING, "Error while createSMILES\t", x);
                        value = "";
                    }
            }
            if (value != null) {
                if (value instanceof Number) {
                    s = value.toString();
                } else {
                    s = value.toString();

                }

                b.append(s);
                p.add(new Paragraph(b.toString()));
            }

        }
        BufferedImage image = imageTools.getImage(molecule);
        image.flush();

        Image png_struc = Image.getInstance(image, Color.white);
        png_struc.setAlignment(Image.LEFT);
        png_struc.scalePercent(100);

        PdfPCell cell = new PdfPCell();
        cell.setMinimumHeight(cell.height());
        cell.addElement(png_struc);
        table.addCell(cell);

        cell = new PdfPCell(p);
        cell.setBackgroundColor(Color.white);
        table.addCell(cell);

    } catch (Exception x) {
        logger.log(Level.SEVERE, "Error while writing molecule", x);
    }

}

From source file:ambit2.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

public void xml2pdf(InputSource xml, OutputStream pdf) {

    try {/*  www.j a  v  a 2s  . c om*/
        Document document = new Document(PageSize.A4, 80, 50, 30, 65);

        PdfWriter writer = PdfWriter.getInstance(document, pdf);
        //writer.setViewerPreferences(PdfWriter.HideMenubar| PdfWriter.HideToolbar);
        writer.setViewerPreferences(PdfWriter.PageModeUseThumbs | PdfWriter.PageModeUseOutlines);
        //PdfOutline root = writer.getDirectContent().getRootOutline();
        //new PdfOutline(root, new PDFAction("http://nina.acad.bg/qmrf"), "a bookmark");

        //writer.addFileAttachment(arg0, arg1, arg2, arg3)

        if (docBuilder == null)
            docBuilder = docBuilderFactory.newDocumentBuilder();
        docBuilder.setErrorHandler(new SimpleErrorHandler(getClass().getName()));
        QMRFSchemaResolver resolver = new QMRFSchemaResolver("http://ambit2.acad.bg/qmrf/qmrf.dtd", null);
        resolver.setIgnoreSystemID(true);
        docBuilder.setEntityResolver(resolver);

        org.w3c.dom.Document doc = null;
        try {
            doc = docBuilder.parse(xml);
        } catch (Exception x) {
            document.addCreationDate();
            document.addCreator(getClass().getName());
            document.open();
            document.add(new Paragraph(new Chunk(x.getMessage())));
            document.close();
            return;
        }

        document.addCreationDate();
        document.addCreator(getClass().getName());
        document.addKeywords(replaceTags(findNodeValue("keywords", doc)));
        document.addTitle(replaceTags(findNodeValue("QSAR_title", doc)));

        try {
            NodeList info = doc.getElementsByTagName("QMRF");
            for (int i = 0; i < info.getLength(); i++)
                document.addSubject(findAttributeValue("name", info.item(i)) + '.'
                        + findAttributeValue("version", info.item(i)));
        } catch (Exception x) {
            document.addSubject("QMRF");
        }
        try {
            document.addAuthor(listNodeAttributes(doc, "qmrf_authors", "author_ref", "author", att_author,
                    new Boolean(true)));
        } catch (Exception x) {
            document.addAuthor(getClass().getName());
        }

        document.open();
        PdfContentByte cb = writer.getDirectContent();

        try {
            headerTable(document, doc);
        } catch (Exception x) {
            document.add(new Paragraph(new Chunk(x.getMessage())));
            document.close();
            return;
        }

        PdfOutline root = writer.getDirectContent().getRootOutline();

        for (int i = 0; i < subchapters.length; i++)

            try {
                int align = Paragraph.ALIGN_LEFT;
                if (Mode.chapter == (Mode) subchapters[i][2]) {
                    document.add(new Paragraph(new Chunk('\n')));
                    PdfPTable table = new PdfPTable(1);

                    table.setWidthPercentage(100);

                    StringBuffer b = new StringBuffer();
                    b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter, doc));
                    b.append('.');
                    b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_name, doc));

                    String bookmark = b.toString();

                    Chunk title = new Chunk(bookmark);
                    title.setLocalDestination(bookmark);
                    title.setFont(bfont);

                    PdfDestination destination = new PdfDestination(PdfDestination.FITH);
                    PdfOutline outline = new PdfOutline(root, destination, bookmark);

                    Paragraph p = new Paragraph(title);

                    PdfPCell cell = new PdfPCell(p);
                    cell.setBackgroundColor(chapterColor);
                    table.addCell(cell);
                    document.add(table);
                    float pos = writer.getVerticalPosition(false);
                    if (pos < 90)
                        document.newPage();
                } else {
                    Phrase phrase = new Phrase();
                    switch ((Mode) subchapters[i][2]) {
                    case title: {
                        StringBuffer b = new StringBuffer();
                        String cn = findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter,
                                doc);
                        if (cn == null)
                            break;

                        b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_chapter, doc));
                        b.append('.');
                        b.append(findAttributeValue(subchapters[i][0].toString(), xml_attribute_name, doc));

                        String subchapterBookmark = b.toString();
                        b.append(':');

                        Chunk title = new Chunk(b.toString());
                        title.setLocalDestination(subchapterBookmark);
                        title.setFont(bfont);
                        phrase.add(title);

                        PdfDestination destination = new PdfDestination(PdfDestination.FITBH);
                        PdfOutline outline = new PdfOutline(root, destination, subchapterBookmark);

                        break;

                    }
                    case text: {
                        createNodePhrase(subchapters[i][0].toString(), doc, phrase, font);
                        align = Paragraph.ALIGN_JUSTIFIED;
                        break;
                    }
                    case answer: {
                        String a = findAnswer(subchapters[i][0].toString(), doc);
                        if (a != null) {
                            Chunk answer = new Chunk(a);
                            answer.setFont(font);
                            phrase.add(answer);
                        }
                        break;
                    }
                    case dataset: {
                        StringBuffer b = new StringBuffer();
                        b.append(findDataAvailable(subchapters[i][0].toString(), doc));
                        Chunk dataset = new Chunk(b.toString());
                        dataset.setFont(font);
                        phrase.add(dataset);
                        break;
                    }
                    case attachments: {
                        PdfPTable table = getAttachmentsAsTable(doc, "attachment_training_data");
                        if (table != null) {
                            phrase.add(new Paragraph("Training set(s)"));
                            phrase.add(table);
                        }
                        table = getAttachmentsAsTable(doc, "attachment_validation_data");
                        if (table != null) {
                            phrase.add(new Paragraph("Test set(s)"));
                            phrase.add(table);
                        }
                        table = getAttachmentsAsTable(doc, "attachment_documents");
                        if (table != null) {
                            phrase.add(new Paragraph("Supporting information"));
                            phrase.add(table);
                        }
                        break;
                        /*
                        StringBuffer b = new StringBuffer();
                        b.append("Training set(s)\n");
                         b.append(listAttachments(doc,"attachment_training_data"));
                         b.append("Test set(s)\n");
                         b.append(listAttachments(doc,"attachment_validation_data"));
                         b.append("Supporting information\n");
                         b.append(listAttachments(doc,"attachment_documents"));
                        Chunk attachments = new Chunk(b.toString());
                        attachments.setFont(font);
                        phrase.add(attachments);
                                
                        break;
                        */
                    }
                    case reference: {
                        try {
                            String value = listNodeAttributes(doc, subchapters[i][0].toString(),
                                    subchapters[i][3].toString(), subchapters[i][4].toString(),
                                    (String[]) subchapters[i][5], (Boolean) subchapters[i][6]);

                            Chunk reference = new Chunk(value);
                            reference.setFont(font);
                            align = Paragraph.ALIGN_JUSTIFIED;
                            phrase.add(reference);
                        } catch (Exception x) {

                        }
                        break;

                    }
                    }

                    Paragraph p = new Paragraph(phrase);
                    p.setAlignment(align);
                    document.add(p);
                    float pos = writer.getVerticalPosition(false);
                    /*
                    cb.moveTo(0, pos);
                    cb.lineTo(PageSize.A4.width(), pos);
                    cb.stroke();
                    */
                    if (pos < 90)
                        document.newPage();
                }
            } catch (Exception x) {
                x.printStackTrace();
            }

        document.close();

    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
    }
}

From source file:ambit2.db.reporters.PDFReporter.java

protected void writeHeader(Document writer) throws IOException {
    String[] tops = new String[] { "Structure", "Properties" };
    for (String top : tops) {
        Chunk chunk = new Chunk(top);
        chunk.setFont(font);/*www  .j  a  v a  2  s  . c o  m*/
        PdfPCell cell = new PdfPCell(new Paragraph(chunk));
        cell.setBackgroundColor(Color.white);
        table.addCell(cell);
    }

}

From source file:ambit2.db.reporters.PDFReporter.java

protected void writeMolecule(IAtomContainer molecule) {
    Object value;//from  www . ja  va 2s.  c  o  m

    try {

        Paragraph p = new Paragraph("");

        String s;

        for (Property property : header) {
            StringBuffer b = new StringBuffer();
            b.append(property.getLabel());
            b.append(" = ");
            value = molecule.getProperty(property);

            if (value != null) {
                if (value instanceof Number) {
                    s = value.toString();
                } else {
                    s = value.toString();
                }
                b.append(s);

                Chunk chunk = new Chunk(b.toString());
                chunk.setFont(font);
                p.add(new Paragraph(chunk));
            }

        }

        BufferedImage image = depict.getImage(molecule);
        image.flush();

        Image png_struc = Image.getInstance(image, Color.white);
        png_struc.setAlignment(Image.LEFT);
        png_struc.scalePercent(100);

        PdfPCell cell = new PdfPCell();
        cell.setMinimumHeight(cell.height());
        cell.addElement(png_struc);
        table.addCell(cell);

        cell = new PdfPCell(p);
        cell.setBackgroundColor(Color.white);
        table.addCell(cell);

    } catch (Exception x) {
        logger.log(java.util.logging.Level.FINE, x.getMessage(), x);
    }

}

From source file:ambit2.io.PDFWriter.java

License:Open Source License

public void writeMolecule(IMolecule molecule) {
    Object value;/*w w  w.j a v  a  2 s.  c  om*/

    try {

        //give it a chance to create a header just before the first write
        if (!writingStarted) {
            if (header == null)
                setHeader(molecule.getProperties());
            writeHeader();
            writingStarted = true;
        }

        Paragraph p = new Paragraph("");
        String s;
        for (int i = 0; i < header.size(); i++) {
            StringBuffer b = new StringBuffer();
            b.append(header.get(i));
            b.append(" = ");
            value = molecule.getProperty(header.get(i));
            if (i == smilesIndex) {

                if (value == null) //no SMILES available
                    try {
                        value = ""; //sg.createSMILES(molecule);
                    } catch (Exception x) {
                        logger.error("Error while createSMILES\t", x.getMessage());
                        value = "";
                    }
            }
            if (value != null) {
                if (value instanceof Number) {
                    s = value.toString();
                } else {
                    s = value.toString();

                }

                b.append(s);
                p.add(new Paragraph(b.toString()));
            }

        }
        BufferedImage image = imageTools.getImage(molecule);
        image.flush();

        Image png_struc = Image.getInstance(image, Color.white);
        png_struc.setAlignment(Image.LEFT);
        png_struc.scalePercent(100);

        PdfPCell cell = new PdfPCell();
        cell.setMinimumHeight(cell.height());
        cell.addElement(png_struc);
        table.addCell(cell);

        cell = new PdfPCell(p);
        cell.setBackgroundColor(Color.white);
        table.addCell(cell);

    } catch (Exception x) {
        logger.error("ERROR while writing Molecule: ", x.getMessage());
        logger.debug(x);
        x.printStackTrace();
    }

}

From source file:biblivre3.administration.reports.AllUsersReport.java

License:Open Source License

private final PdfPTable createSummaryTable(Map<String, Integer> tipos) {
    PdfPTable table = new PdfPTable(2);
    table.setWidthPercentage(50f);/*  w  w w.  jav a  2 s  . c om*/
    table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);

    int total = 0;
    PdfPCell cell;
    for (String description : tipos.keySet()) {
        total += tipos.get(description);
        cell = new PdfPCell(new Paragraph(this.getHeaderChunk(description.toUpperCase())));
        cell.setBackgroundColor(headerBgColor);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getNormalChunk(String.valueOf(tipos.get(description)))));
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
    }
    cell = new PdfPCell(new Paragraph(this.getHeaderChunk(this.getText("REPORTS_TOTAL"))));
    cell.setBackgroundColor(headerBgColor);
    cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);
    cell = new PdfPCell(new Paragraph(this.getNormalChunk(String.valueOf(total))));
    cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
    cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    table.addCell(cell);
    return table;
}