Example usage for com.itextpdf.text.pdf PdfPTable getDefaultCell

List of usage examples for com.itextpdf.text.pdf PdfPTable getDefaultCell

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPTable getDefaultCell.

Prototype

public PdfPCell getDefaultCell() 

Source Link

Document

Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell).

Usage

From source file:com.softwaremagico.tm.pdf.small.fighting.ArmourTable.java

License:Open Source License

private PdfPTable getShieldRange(CharacterPlayer characterPlayer) {
    float[] widths = { 1f, 3f, 1f, 3f, 1f };
    PdfPTable table = new PdfPTable(widths);
    BaseElement.setTablePropierties(table);
    table.getDefaultCell().setBorder(0);
    table.getDefaultCell().setPadding(0);
    table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

    table.addCell(createEmptyElementLine("("));
    if (characterPlayer == null || characterPlayer.getShield() == null) {
        table.addCell(createEmptyElementLine(" ", ARMOUR_VALUE_COLUMN_WIDTH));
    } else {/*from  w ww  .j  a v  a2 s .  c  o m*/
        table.addCell(
                createElementLine(characterPlayer.getShield().getImpact() + "", ARMOUR_VALUE_COLUMN_WIDTH));
    }
    table.addCell(createEmptyElementLine("/"));
    if (characterPlayer == null || characterPlayer.getShield() == null) {
        table.addCell(createEmptyElementLine(" ", ARMOUR_VALUE_COLUMN_WIDTH));
    } else {
        table.addCell(
                createElementLine(characterPlayer.getShield().getForce() + "", ARMOUR_VALUE_COLUMN_WIDTH));
    }
    table.addCell(createEmptyElementLine(")"));

    return table;
}

From source file:com.softwaremagico.tm.pdf.small.skills.LearnedSkillsTable.java

License:Open Source License

public static PdfPTable getSkillsTable(CharacterPlayer characterPlayer, String language)
        throws InvalidXmlElementException {
    float[] widths = { 1f };
    PdfPTable table = new PdfPTable(widths);
    setTablePropierties(table);/*from  ww  w . j a  v a 2 s  . co  m*/
    table.getDefaultCell().setBorder(0);
    table.addCell(getSkillsColumnTable(characterPlayer, language));
    return table;
}

From source file:com.softwaremagico.tm.pdf.small.skills.LearnedSkillsTable.java

License:Open Source License

private static PdfPCell getSkillsColumnTable(CharacterPlayer characterPlayer, String language)
        throws InvalidXmlElementException {
    float[] widths = { 4f, 1f };
    PdfPTable table = new PdfPTable(widths);
    setTablePropierties(table);/*from ww  w .j av a  2s . c  om*/
    table.getDefaultCell().setBorder(0);

    table.addCell(createCompactTitle(getTranslator().getTranslatedText("learnedSkills"),
            FadingSunsTheme.CHARACTER_SMALL_SKILLS_TITLE_FONT_SIZE));

    int added = 0;
    if (characterPlayer != null) {
        for (AvailableSkill skill : characterPlayer.getLearnedSkills()) {
            if (characterPlayer.getSkillTotalRanks(skill) > 0) {
                table.addCell(createSkillElement(characterPlayer, skill,
                        FadingSunsTheme.CHARACTER_SMALL_SKILLS_LINE_FONT_SIZE, MAX_SKILL_COLUMN_WIDTH));
                table.addCell(createSkillValue(characterPlayer.getSkillTotalRanks(skill),
                        characterPlayer.isSkillSpecial(skill)
                                || characterPlayer.hasSkillTemporalModificator(skill),
                        characterPlayer.hasSkillModificator(skill),
                        FadingSunsTheme.CHARACTER_SMALL_SKILLS_LINE_FONT_SIZE));
                added++;
            }
        }
    }

    if (characterPlayer == null) {
        for (int i = added; i < ROWS; i++) {
            table.addCell(CustomPdfTable.createEmptyElementLine(GAP, MAX_SKILL_COLUMN_WIDTH));
            table.addCell(CustomPdfTable.createEmptyElementLine(GAP, MAX_SKILL_RANK_WIDTH));
        }
    } else {
        for (int i = added; i < ROWS; i++) {
            table.addCell(CustomPdfTable.createEmptyElementLine(" ", MAX_SKILL_COLUMN_WIDTH));
            table.addCell(CustomPdfTable.createEmptyElementLine(" ", MAX_SKILL_RANK_WIDTH));
        }
    }

    PdfPCell cell = new PdfPCell();
    setCellProperties(cell);

    cell.addElement(table);
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    return cell;
}

From source file:com.softwaremagico.tm.pdf.small.skills.NaturalSkillsTable.java

License:Open Source License

private static PdfPCell getSkillsColumnTable(CharacterPlayer characterPlayer, String language)
        throws InvalidXmlElementException {
    float[] widths = { 4f, 1f };
    PdfPTable table = new PdfPTable(widths);
    setTablePropierties(table);/*from  w w w. j  av  a2 s .c  om*/
    table.getDefaultCell().setBorder(0);

    table.addCell(createCompactTitle(getTranslator().getTranslatedText("naturalSkills"),
            FadingSunsTheme.CHARACTER_SMALL_SKILLS_TITLE_FONT_SIZE));

    if (characterPlayer == null) {
        for (AvailableSkill skill : AvailableSkillsFactory.getInstance().getNaturalSkills(language)) {
            table.addCell(createSkillElement(null, skill, FadingSunsTheme.CHARACTER_SMALL_SKILLS_LINE_FONT_SIZE,
                    MAX_SKILL_COLUMN_WIDTH));
            table.addCell(
                    createSkillLine(SKILL_VALUE_GAP, FadingSunsTheme.CHARACTER_SMALL_SKILLS_LINE_FONT_SIZE));
        }
    } else {
        for (AvailableSkill skill : characterPlayer.getNaturalSkills()) {
            table.addCell(createSkillElement(characterPlayer, skill,
                    FadingSunsTheme.CHARACTER_SMALL_SKILLS_LINE_FONT_SIZE, MAX_SKILL_COLUMN_WIDTH));
            table.addCell(createSkillValue(characterPlayer.getSkillTotalRanks(skill),
                    characterPlayer.isSkillSpecial(skill) || characterPlayer.hasSkillTemporalModificator(skill),
                    characterPlayer.hasSkillModificator(skill),
                    FadingSunsTheme.CHARACTER_SMALL_SKILLS_LINE_FONT_SIZE));
        }
    }

    PdfPCell cell = new PdfPCell();
    setCellProperties(cell);

    cell.addElement(table);
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    return cell;
}

From source file:com.softwaremagico.tm.pdf.small.SmallCharacterSheet.java

License:Open Source License

protected PdfPTable createCharacterContent(CharacterPlayer characterPlayer) throws Exception {
    float[] widths = { 2.2f, 1f };
    PdfPTable mainTable = new PdfPTable(widths);
    BaseElement.setTablePropierties(mainTable);
    mainTable.getDefaultCell().setPadding(0);

    PdfPTable infoTable = CharacterBasicsReducedTableFactory.getCharacterBasicsTable(characterPlayer);
    PdfPCell infoCell = new PdfPCell(infoTable);
    infoCell.setBorderWidthTop(0);/*from   w  ww.j a  v a  2s .c om*/
    infoCell.setBorderWidthLeft(0);
    infoCell.setBorderWidthBottom(1);
    mainTable.addCell(infoCell);

    PdfPTable learnedSkillsTable = LearnedSkillsTable.getSkillsTable(characterPlayer, getLanguage());
    PdfPCell learnedSkillsCell = new PdfPCell(learnedSkillsTable);
    learnedSkillsCell.setColspan(2);
    learnedSkillsCell.setRowspan(3);
    learnedSkillsCell.setBorderWidthTop(0);
    learnedSkillsCell.setBorderWidthRight(0);
    mainTable.addCell(learnedSkillsCell);

    PdfPTable basicTable = new PdfPTable(new float[] { 5f, 4f });
    BaseElement.setTablePropierties(basicTable);
    basicTable.getDefaultCell().setBorder(0);

    PdfPTable characteristicsTable = CharacteristicsTableFactory.getCharacteristicsBasicsTable(characterPlayer);
    PdfPCell characteristicCell = new PdfPCell(characteristicsTable);
    characteristicCell.setBorderWidthLeft(0);
    basicTable.addCell(characteristicCell);

    PdfPTable naturalSkillsTable = NaturalSkillsTable.getSkillsTable(characterPlayer, getLanguage());
    PdfPCell naturalSkillsCell = new PdfPCell(naturalSkillsTable);
    naturalSkillsCell.setBorderWidthRight(0);
    basicTable.addCell(naturalSkillsCell);

    PdfPCell basicComposedCell = new PdfPCell(basicTable);
    basicComposedCell.setBorder(0);
    mainTable.addCell(basicComposedCell);

    PdfPTable composedTable = new PdfPTable(new float[] { 5f, 2f });

    PdfPTable blessingsTable = new BlessingTable(characterPlayer);
    PdfPCell blessingsCell = new PdfPCell(blessingsTable);
    blessingsCell.setBorderWidthLeft(0);
    blessingsCell.setBorderWidthBottom(1);
    composedTable.addCell(blessingsCell);

    PdfPTable beneficesTable = new BeneficesTable(characterPlayer);
    PdfPCell beneficesCell = new PdfPCell(beneficesTable);
    beneficesCell.setBorderWidthBottom(1);
    composedTable.addCell(beneficesCell);

    PdfPCell composedCell = new PdfPCell(composedTable);
    composedCell.setRowspan(2);
    composedCell.setBorder(0);
    mainTable.addCell(composedCell);

    PdfPTable armourTable = new ArmourTable(characterPlayer);
    PdfPCell armourCell = new PdfPCell(armourTable);
    armourCell.setBorderWidthRight(0);
    armourCell.setBorderWidthBottom(1);
    mainTable.addCell(armourCell);

    PdfPTable fightTable = new PdfPTable(new float[] { 3f, 5f, 1f });

    if (characterPlayer != null
            && (characterPlayer.getSelectedPowers().isEmpty() && !characterPlayer.getCybernetics().isEmpty())) {
        PdfPTable cyberneticsTable = new CyberneticsTable(characterPlayer);
        PdfPCell cyberneticsCell = new PdfPCell(cyberneticsTable);
        cyberneticsCell.setBorderWidthLeft(0);
        fightTable.addCell(cyberneticsCell);
    } else {
        PdfPTable occultismTable = new OccultismTable(characterPlayer, getLanguage());
        PdfPCell occultismCell = new PdfPCell(occultismTable);
        occultismCell.setBorderWidthLeft(0);
        fightTable.addCell(occultismCell);
    }

    PdfPTable weaponsTable = new WeaponsTable(characterPlayer);
    fightTable.addCell(weaponsTable);

    PdfPCell victoryPointsCell = new PdfPCell(new VerticalVictoryPointsTable());
    victoryPointsCell.setPadding(0);
    victoryPointsCell.setRowspan(3);
    fightTable.addCell(victoryPointsCell);

    PdfPTable vitalityTable = new VitalityTable(characterPlayer);
    PdfPCell vitalityCell = new PdfPCell(vitalityTable);
    vitalityCell.setColspan(2);
    vitalityCell.setBorderWidth(1);
    fightTable.addCell(vitalityCell);

    PdfPTable wyrdTable = new WyrdTable(characterPlayer);
    PdfPCell wyrdCell = new PdfPCell(wyrdTable);
    wyrdCell.setBorderWidth(1);
    wyrdCell.setColspan(2);
    fightTable.addCell(wyrdCell);

    PdfPCell fightCell = new PdfPCell(fightTable);
    fightCell.setBorder(0);
    fightCell.setColspan(2);

    mainTable.addCell(fightCell);
    return mainTable;
}

From source file:com.solidmaps.webapp.report.MapCivilPdfGenerator.java

License:Open Source License

private void createSignature(Document doc) throws DocumentException {

    Calendar currDate = Calendar.getInstance();

    StringBuilder sbSignature = new StringBuilder().append(company.getCity()).append(", ")
            .append(DateUtils.getDay(currDate.getTime())).append(" de ")
            .append(DateUtils.getMonthName(currDate)).append(" de ")
            .append(DateUtils.getYear(currDate.getTime()));

    StringBuilder sbUser = new StringBuilder().append("P.P_________________________________________________ \n")
            .append("Nome: ").append(company.getUserResponsable().getName()).append("\n")
            .append("RG: " + company.getUserResponsable().getRg());

    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100f);//w  ww .j  av  a 2s.c om
    table.setHeaderRows(0);
    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    insertCell(table, sbSignature.toString(), Element.ALIGN_LEFT, fontHeaderTable, false);
    insertCell(table, sbUser.toString(), Element.ALIGN_LEFT, fontHeaderTable, false);

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

From source file:com.solidmaps.webapp.report.MapExercitoPdfGenerator.java

License:Open Source License

private void createFooter(Document doc) throws DocumentException {

    Calendar cal = Calendar.getInstance();
    PdfPTable table = new PdfPTable(1);
    table.setWidthPercentage(100f);//from www.j  a v  a  2 s. c  om

    table.setHeaderRows(0);

    table.getDefaultCell().setBorder(PdfPCell.NO_BORDER);

    StringBuilder sbData = new StringBuilder();
    sbData.append(company.getCity()).append(" / ").append(company.getState()).append(", ")
            .append(cal.get(Calendar.DAY_OF_MONTH)).append(" de ").append(DateUtils.getMonthName(cal))
            .append(" de ").append(cal.get(Calendar.YEAR)).append("\n\n");

    insertCell(table, sbData.toString(), Element.ALIGN_RIGHT, fontHeaderTableBig, false);

    insertCell(table, "_________________________________________________ \n Nome: "
            + company.getUserResponsable().getName() + " \n Cargo: " + company.getUserResponsable().getOffice(),
            Element.ALIGN_RIGHT, fontHeaderTable, false);

    doc.add(Chunk.NEWLINE);

    doc.add(table);
}

From source file:com.xumpy.itext.services.HeaderFooter.java

@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfPTable header = new PdfPTable(3);
    try {//  www  .j ava  2 s . co m
        header.setWidths(new int[] { 24, 24, 24 });
        header.setTotalWidth(527);
        header.setLockedWidth(true);
        header.getDefaultCell().setFixedHeight(20);
        header.getDefaultCell().setBorder(Rectangle.BOTTOM);
        for (PdfPCell cell : tableHeader) {
            cell.setBorder(Rectangle.NO_BORDER);
            header.addCell(cell);
        }
        header.writeSelectedRows(0, -1, 60, 803, writer.getDirectContent());
    } catch (DocumentException ex) {
        Logger.getLogger(HeaderFooter.class.getName()).log(Level.SEVERE, null, ex);
    }

    PdfPTable footer = new PdfPTable(3);
    try {
        footer.setWidths(new int[] { 24, 24, 24 });
        footer.setTotalWidth(527);
        footer.setLockedWidth(true);
        footer.getDefaultCell().setFixedHeight(20);
        footer.getDefaultCell().setBorder(Rectangle.BOTTOM);
        for (PdfPCell cell : tableFooter) {
            cell.setBorder(Rectangle.NO_BORDER);
            footer.addCell(cell);
        }
        footer.writeSelectedRows(0, -1, 60, 200, writer.getDirectContent());
    } catch (DocumentException ex) {
        Logger.getLogger(HeaderFooter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:comisionesafis.informes.FacturasComisionesAgentes.java

public boolean generar() {

    // Abrimos el fichero de comisiones
    Periodos periodos = new Periodos(pb.getFicheroComisiones());
    String sSQL = "";
    Statement stmt;/*  w ww.j a v  a 2s.  co  m*/
    ResultSet rsComisiones;
    String sFactura1;
    String sFactura2;

    // Generamos la sentencia de Seleccin de Datos
    try {

        // Generamos el PDF
        Document documento = new Document(PageSize.A4, 80, 80, 50, 50);
        FileOutputStream salida = new FileOutputStream("FacturasComisionesAgentes.pdf");
        PdfWriter writer = PdfWriter.getInstance(documento, salida);
        writer.setInitialLeading(0);

        //  Obtenemos una instancia de nuestro manejador de eventos
        FacturasComisionesAgentesPie pie = new FacturasComisionesAgentesPie();
        //Asignamos el manejador de eventos al escritor.
        writer.setPageEvent(pie);

        // Abrimos el Documento
        documento.open();

        sSQL = "SELECT * ";
        sSQL += "  FROM ResumenComisiones";
        sSQL += " ORDER BY CodAgente";
        stmt = conexion.createStatement();
        rsComisiones = stmt.executeQuery(sSQL);

        while (rsComisiones.next()) {

            // Generamos los prrafos
            // Datos del agente
            Paragraph pAgente[] = new Paragraph[5];
            pAgente[0] = new Paragraph();
            pAgente[0].add(rsComisiones.getString("Nombre"));
            pAgente[0].setAlignment(Paragraph.ALIGN_LEFT);
            pAgente[1] = new Paragraph();
            pAgente[1].add(rsComisiones.getString("Direccion"));
            pAgente[1].setAlignment(Paragraph.ALIGN_LEFT);
            pAgente[2] = new Paragraph();
            pAgente[2].add(rsComisiones.getString("CodPostal") + "  " + rsComisiones.getString("Poblacion"));
            pAgente[2].setAlignment(Paragraph.ALIGN_LEFT);
            pAgente[3] = new Paragraph();
            pAgente[3].add(rsComisiones.getString("Provincia"));
            pAgente[3].setAlignment(Paragraph.ALIGN_LEFT);
            pAgente[4] = new Paragraph();
            pAgente[4].add(rsComisiones.getString("NIF"));
            pAgente[4].setAlignment(Paragraph.ALIGN_LEFT);

            // creating separators
            LineSeparator separador = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -2);

            // Datos fijos
            Paragraph pPelayo[] = new Paragraph[5];
            pPelayo[0] = new Paragraph();
            pPelayo[0].add("PELAYO VIDA");
            pPelayo[0].setAlignment(Paragraph.ALIGN_RIGHT);
            pPelayo[1] = new Paragraph();
            pPelayo[1].add("CL SANTA ENGRACIA 69");
            pPelayo[1].setAlignment(Paragraph.ALIGN_RIGHT);
            pPelayo[2] = new Paragraph();
            pPelayo[2].add("28010  MADRID");
            pPelayo[2].setAlignment(Paragraph.ALIGN_RIGHT);
            pPelayo[3] = new Paragraph();
            pPelayo[3].add("MADRID");
            pPelayo[3].setAlignment(Paragraph.ALIGN_RIGHT);
            pPelayo[4] = new Paragraph();
            pPelayo[4].add("06422");
            pPelayo[4].setAlignment(Paragraph.ALIGN_RIGHT);

            // Fecha
            Paragraph pFecha = new Paragraph();
            pFecha = new Paragraph("Madrid, a " + periodos.extraeFechaLarga());
            pFecha.setAlignment(Paragraph.ALIGN_RIGHT);

            // Lnea 1 de FACTURA
            Paragraph pFactura1 = new Paragraph();
            sFactura1 = "FACTURA: n factura ";
            sFactura1 += rsComisiones.getString("CodAgente") + " - ";
            sFactura1 += periodos.extraePeriodoMY("MM-YYYY");
            pFactura1 = new Paragraph(sFactura1);

            // Lnea 2 de FACTURA
            Paragraph pFactura2 = new Paragraph();
            sFactura2 = "Factura por la prestacin de servicios relativos a las operaciones ";
            sFactura2 += "de intermediacin de seguros realizadas para su entidad del mes de ";
            sFactura2 += periodos.extraePeriodoMY("MM YYYY");
            ;
            pFactura2 = new Paragraph(sFactura2);

            // Datos Econmicos
            float[] anchuras = { 5f, 2f };
            PdfPTable table = new PdfPTable(anchuras);
            table.getDefaultCell().setBorder(0);

            // Tipo de letra para la tabla
            Font font = new Font(Font.FontFamily.COURIER, 11, Font.NORMAL);

            PdfPCell celda = new PdfPCell();

            celda = new PdfPCell(new Phrase("Comisiones pagadas", font));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(celda);

            celda = new PdfPCell(
                    new Phrase(Double.toString(rsComisiones.getDouble("TotalComisiones")) + " ", font));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(celda);

            celda = new PdfPCell(new Phrase("Otros conceptos", font));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(celda);

            celda = new PdfPCell(new Phrase(" ", font));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(celda);

            celda = new PdfPCell(new Phrase(
                    "Retencin (" + Double.toString(rsComisiones.getDouble("RetencionPorcentaje")) + "%)",
                    font));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(celda);

            Double dblRetencion = rsComisiones.getDouble("TotalComisiones")
                    * (rsComisiones.getDouble("RetencionPorcentaje") / 100);
            celda = new PdfPCell(new Phrase(Numeros.formateaDosDecimales(dblRetencion) + " ", font));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(celda);

            celda = new PdfPCell(new Phrase("Conceptos no sujetos", font));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(celda);

            celda = new PdfPCell(new Phrase(" ", font));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(celda);

            celda = new PdfPCell(new Phrase("Total a pagar", font));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_LEFT);
            table.addCell(celda);

            Double dblTotalPagar = rsComisiones.getDouble("TotalComisiones") - dblRetencion;
            celda = new PdfPCell(new Phrase(Numeros.formateaDosDecimales(dblTotalPagar) + " ", font));
            celda.setBorder(Rectangle.NO_BORDER);
            celda.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(celda);

            // Literal: Operacin exenta de IVA
            Paragraph pColetilla = new Paragraph();
            pColetilla.add("Operacin exenta de IVA");

            // Aadimos los prrafos al Documento
            for (int i = 0; i < 5; i++)
                documento.add(pAgente[i]);

            documento.add(new Paragraph(" "));
            documento.add(separador);

            for (int i = 0; i < 5; i++)
                documento.add(pPelayo[i]);

            documento.add(new Paragraph(" "));

            documento.add(pFecha);
            documento.add(new Paragraph(" "));

            documento.add(pFactura1);
            documento.add(separador);
            documento.add(pFactura2);

            // Agregamos la tabla al documento    
            documento.add(new Paragraph(" "));
            documento.add(table);

            documento.add(new Paragraph(" "));
            documento.add(new Paragraph(" "));
            documento.add(pColetilla);
            documento.newPage();
        }
        documento.close();
        return true;
    } catch (Exception e) {
        return false;
    }
}

From source file:Control.ProcessaArq.java

public void gravaArquivoConsumoUnidades(ArrayList<Usuario> listaUsuario, String caminho)
        throws IOException, DocumentException {

    Document doc = null;//ww w. j av a 2s  . c om
    OutputStream os = null;
    PdfWriter pdf = null;
    Paragraph p = new Paragraph();
    Tratamento tempo = new Tratamento();
    PdfPTable table = new PdfPTable(5);
    DecimalFormat df = new DecimalFormat("#####.##");
    ArrayList<String> listaCidade = new ArrayList<String>();
    String local = new String();
    String informacao, tipo = new String();
    Double soma, valorTotal, diferenca = 0.0;
    Usuario unidade = new Usuario();
    ArrayList<Usuario> listaUnidades = new ArrayList<Usuario>();
    /*    
        if(banco.getConta().get(banco.getConta().size()-1).getDiferenca() > 0){
    diferenca = banco.getConta().get(banco.getConta().size()-1).getDiferenca()/9;
        }
        else{ diferenca = 0.0; }
    */
    for (int a = 0; a <= listaUsuario.size() - 1; a++) {
        if ((!listaCidade.contains(listaUsuario.get(a).getCidade()))) {
            listaCidade.add(listaUsuario.get(a).getCidade());
        }
    }

    float[] headerwidths = { 30, 80, 35, 35, 25 }; // define a largura de cada coluna       
    table.setWidths(headerwidths);

    caminho = localizaArquivo(false) + ".pdf";
    try {//configuraes da pgina          
        float fntSize, lineSpacing;
        fntSize = 8f;
        lineSpacing = 8f;

        doc = new Document(PageSize.A4.rotate(), 10, 10, 30, 40);
        os = new FileOutputStream(caminho);
        pdf.getInstance(doc, os);
        doc.open();

        /*
        local = new String();
        local = caminho +" "+ listaCidade.get(a) + ".pdf";
                
        doc = new Document(PageSize.A4.rotate(), 10, 10, 30, 40); 
        os = new FileOutputStream(local);            
        pdf.getInstance(doc, os);   
        doc.open();
        */
        //cabecalho da tabela
        table.getDefaultCell().setBorder(0);

        table.getDefaultCell().setBorder(0);
        table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.getDefaultCell().setColspan(5);

        table.addCell(new Paragraph("CONSUMO POR UNIDADE " + banco.periodoFatura()));

        table.getDefaultCell().setBorder(0);
        table.getDefaultCell().setColspan(0);
        table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        doc.add(table);

        for (int a = 0; a <= listaCidade.size() - 1; a++) {

            table = new PdfPTable(5);
            table.setWidths(headerwidths);
            table.getDefaultCell().setBorder(0);
            table.addCell(new Paragraph(""));
            table.addCell(new Paragraph(""));
            table.addCell(new Paragraph(""));
            table.addCell(new Paragraph(""));
            table.addCell(new Paragraph(""));
            table.getDefaultCell().setBorder(1);

            table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
            table.addCell(new Paragraph("Cidade"));
            table.addCell(new Paragraph("Usurio"));
            table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            table.addCell(new Paragraph("Nmero"));
            table.addCell(new Paragraph("Tipo"));
            table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            table.addCell(new Paragraph("Valor"));
            table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);

            soma = 0.0;
            for (int b = 0; b <= listaUsuario.size() - 1; b++) {

                if (listaCidade.get(a).equals(listaUsuario.get(b).getCidade())) {

                    //cidade
                    informacao = new String();
                    informacao = listaUsuario.get(b).getCidade();
                    table.addCell(new Paragraph(informacao));

                    //Usurio
                    informacao = new String();
                    informacao = listaUsuario.get(b).getNome();
                    table.addCell(new Paragraph(informacao));

                    //Nmero
                    informacao = new String();
                    informacao = String.valueOf(listaUsuario.get(b).getLinha());
                    table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                    table.addCell(new Paragraph(informacao));

                    //Tipo
                    informacao = new String();
                    informacao = listaUsuario.get(b).getTipo();
                    table.addCell(new Paragraph(informacao));

                    //Valor
                    informacao = new String();
                    soma += listaUsuario.get(b).getValor();
                    informacao = "R$" + df.format(listaUsuario.get(b).getValor());
                    table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                    table.addCell(new Paragraph(informacao));
                }
            }

            // Total
            table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
            informacao = new String();
            informacao = "Total apurado";
            table.addCell(informacao);

            // tempo                        
            table.addCell("");
            table.addCell("");
            table.addCell("");

            // valor
            informacao = new String();
            informacao = "R$" + df.format(soma);
            table.addCell(informacao);
            table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);

            if ((soma - diferenca) > 0) {
                table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
                informacao = new String();
                informacao = "Total a pagar";
                table.addCell(informacao);

                // tempo                        
                table.addCell("");
                table.addCell("");
                table.addCell("");

                // valor
                informacao = new String();
                informacao = "R$" + df.format(soma - diferenca);
                table.addCell(informacao);
                table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);
            }

            table.addCell("");
            table.addCell("");
            table.addCell("");
            table.addCell("");
            table.addCell("");

            unidade = new Usuario();
            unidade.setCidade(listaCidade.get(a));
            unidade.setValor(soma);
            listaUnidades.add(unidade);

            doc.add(table);
        }

        doc.newPage();
        table.getDefaultCell().setBorder(0);
        table.addCell(new Paragraph(""));
        table.addCell(new Paragraph(""));
        table.addCell(new Paragraph(""));
        table.addCell(new Paragraph(""));
        table.addCell(new Paragraph(""));
        table.getDefaultCell().setBorder(1);

        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        table.addCell(new Paragraph("Cidade"));
        table.addCell(new Paragraph(""));
        table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        table.addCell(new Paragraph(""));
        table.addCell(new Paragraph(""));
        table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        table.addCell(new Paragraph("Valor"));
        table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);

        soma = 0.0;
        for (int a = 0; a <= listaUnidades.size() - 1; a++) {
            //cidade
            informacao = new String();
            informacao = listaUnidades.get(a).getCidade();
            table.addCell(new Paragraph(informacao));

            table.addCell("");
            table.addCell("");
            table.addCell("");

            //Valor
            informacao = new String();
            soma += listaUnidades.get(a).getValor();
            informacao = "R$" + df.format(listaUnidades.get(a).getValor());
            table.getDefaultCell().setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            table.addCell(new Paragraph(informacao));
        }

        // Total
        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        informacao = new String();
        informacao = "Total apurado";
        table.addCell(informacao);

        // tempo                        
        table.addCell("");
        table.addCell("");
        table.addCell("");

        // valor
        informacao = new String();
        informacao = "R$" + df.format(soma);
        table.addCell(informacao);
        table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);

        table.getDefaultCell().setBackgroundColor(BaseColor.LIGHT_GRAY);
        informacao = new String();
        informacao = "Total a pagar";
        table.addCell(informacao);

        // tempo                        
        table.addCell("");
        table.addCell("");
        table.addCell("");

        // valor
        informacao = new String();
        informacao = "R$" + df.format(soma);
        //    informacao = "R$"+ df.format(soma-banco.getConta().get(banco.getConta().size()-1).getDiferenca());
        table.addCell(informacao);
        table.getDefaultCell().setBackgroundColor(BaseColor.WHITE);

        doc.add(table);
        doc.close();
        os.close();

    } finally {
        if (doc != null) {
            //fechamento do documento
            doc.close();
        }
        if (os != null) {
            //fechamento da stream de sada
            os.close();
        }
    }
}