Example usage for com.lowagie.text Font TIMES_ROMAN

List of usage examples for com.lowagie.text Font TIMES_ROMAN

Introduction

In this page you can find the example usage for com.lowagie.text Font TIMES_ROMAN.

Prototype

int TIMES_ROMAN

To view the source code for com.lowagie.text Font TIMES_ROMAN.

Click Source Link

Document

a possible value of a font family.

Usage

From source file:Driver.RunTestCases.java

License:Open Source License

public void generateReport() {

    File file = new File("Report1.pdf");
    FileOutputStream fileout = null;
    try {/*from w  w  w . j  a  va  2 s.com*/
        fileout = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, fileout);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.addAuthor("AGTT");
    document.addTitle("AGTT Report");

    document.open();
    Boolean status = true;
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader("Results.txt"));
        String line = null;
        String testCase = null;
        Chunk chunk = null;
        int index = 0;
        List list = new List();
        while ((line = reader.readLine()) != null) {
            if (line.contains("Case")) {

                if (index > 0) {
                    System.out.println(line + status + list.size());
                    if (status == false) {
                        chunk.setBackground(Color.RED);
                    }
                    if (status == true) {
                        chunk.setBackground(Color.GREEN);
                    }
                    document.add(chunk);
                    document.add((Element) list);
                    status = true;
                    list = new List();
                    testCase = null;
                }
                chunk = new Chunk(line + "\n");
                Font font = new Font(Font.TIMES_ROMAN);
                font.setSize(18);
                chunk.setFont(font);
                index++;
            } else {
                if (line.contains("not")) {
                    status = false;
                }
                list.add(line);
            }
            //   document.add(chunk);
        }
    } catch (IOException | DocumentException e) {
        e.printStackTrace();
    }
    document.close();
}

From source file:edu.harvard.mcz.imagecapture.encoder.LabelEncoder.java

License:Open Source License

@SuppressWarnings("hiding")
public static boolean printList(List<UnitTrayLabel> taxa) throws PrintFailedException {
    boolean result = false;
    UnitTrayLabel label = new UnitTrayLabel();
    LabelEncoder encoder = new LabelEncoder(label);
    Image image = encoder.getImage();
    int counter = 0;
    try {//w w  w.j  av  a2s. com
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("labels.pdf"));
        document.setPageSize(PageSize.LETTER);
        document.open();

        PdfPTable table = new PdfPTable(4);
        table.setWidthPercentage(100f);
        //table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        float[] cellWidths = { 30f, 20f, 30f, 20f };
        table.setWidths(cellWidths);

        UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle();
        if (taxa == null) {
            taxa = uls.findAll();
        }
        Iterator<UnitTrayLabel> i = taxa.iterator();
        PdfPCell cell = null;
        PdfPCell cell_barcode = null;
        // Create two lists of 12 cells, the first 6 of each representing
        // the left hand column of 6 labels, the second 6 of each 
        // representing the right hand column.  
        // cells holds the text for each label, cells_barcode the barcode.
        ArrayList<PdfPCell> cells = new ArrayList<PdfPCell>(12);
        ArrayList<PdfPCell> cells_barcode = new ArrayList<PdfPCell>(12);
        for (int x = 0; x < 12; x++) {
            cells.add(null);
            cells_barcode.add(null);
        }
        int cellCounter = 0;
        while (i.hasNext()) {
            // Loop through all of the taxa (unit tray labels) found to print 
            label = i.next();
            for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) {
                // For each taxon, loop through the number of requested copies 
                // Generate a text and a barcode cell for each, and add to array for page
                log.debug("Label " + toPrint + " of " + label.getNumberToPrint());
                cell = new PdfPCell();
                cell.setBorderColor(Color.LIGHT_GRAY);
                cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
                cell.disableBorderSide(PdfPCell.RIGHT);
                cell.setPaddingLeft(3);

                String higherNames = "";
                if (label.getTribe().trim().length() > 0) {
                    higherNames = label.getFamily() + ": " + label.getSubfamily() + ": " + label.getTribe();
                } else {
                    higherNames = label.getFamily() + ": " + label.getSubfamily();
                }
                Paragraph higher = new Paragraph();
                higher.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                higher.add(new Chunk(higherNames));
                cell.addElement(higher);

                Paragraph name = new Paragraph();
                Chunk genus = new Chunk(label.getGenus().trim() + " ");
                genus.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                Chunk species = new Chunk(label.getSpecificEpithet().trim());
                Chunk normal = null; // normal font prefix to preceed specific epithet (nr. <i>epithet</i>)
                if (label.getSpecificEpithet().contains(".") || label.getSpecificEpithet().contains("[")) {
                    if (label.getSpecificEpithet().startsWith("nr. ")) {
                        normal = new Chunk("nr. ");
                        normal.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                        species = new Chunk(label.getSpecificEpithet().trim().substring(4));
                        species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                    } else {
                        species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                    }
                } else {
                    species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                }
                String s = "";
                if (label.getSubspecificEpithet().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk subspecies = new Chunk(s + label.getSubspecificEpithet().trim());
                if (label.getSubspecificEpithet().contains(".")
                        || label.getSubspecificEpithet().contains("[")) {
                    subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                } else {
                    subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                }
                if (label.getInfraspecificRank().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk infraRank = new Chunk(s + label.getInfraspecificRank().trim());
                infraRank.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));

                if (label.getInfraspecificEpithet().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk infra = new Chunk(s + label.getInfraspecificEpithet().trim());
                infra.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                if (label.getUnNamedForm().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk unNamed = new Chunk(s + label.getUnNamedForm().trim());
                unNamed.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));

                name.add(genus);
                if (normal != null) {
                    name.add(normal);
                }
                name.add(species);
                name.add(subspecies);
                name.add(infraRank);
                name.add(infra);
                name.add(unNamed);
                cell.addElement(name);

                Paragraph authorship = new Paragraph();
                authorship.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                if (label.getAuthorship() != null && label.getAuthorship().length() > 0) {
                    Chunk c_authorship = new Chunk(label.getAuthorship());
                    authorship.add(c_authorship);
                }
                cell.addElement(authorship);
                //cell.addElement(new Paragraph(" "));
                if (label.getDrawerNumber() != null && label.getDrawerNumber().length() > 0) {
                    Paragraph drawerNumber = new Paragraph();
                    drawerNumber.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                    Chunk c_drawerNumber = new Chunk(label.getDrawerNumber());
                    drawerNumber.add(c_drawerNumber);
                    cell.addElement(drawerNumber);
                } else {
                    if (label.getCollection() != null && label.getCollection().length() > 0) {
                        Paragraph collection = new Paragraph();
                        collection.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                        Chunk c_collection = new Chunk(label.getCollection());
                        collection.add(c_collection);
                        cell.addElement(collection);
                    }
                }

                cell_barcode = new PdfPCell();
                cell_barcode.setBorderColor(Color.LIGHT_GRAY);
                cell_barcode.disableBorderSide(PdfPCell.LEFT);
                cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP);

                encoder = new LabelEncoder(label);
                image = encoder.getImage();
                image.setAlignment(Image.ALIGN_TOP);
                cell_barcode.addElement(image);

                cells.add(cellCounter, cell);
                cells_barcode.add(cellCounter, cell_barcode);

                cellCounter++;
                // If we have hit a full set of 12 labels, add them to the document
                // in two columns, filling left column first, then right
                if (cellCounter == 12) {
                    // add a page of 12 cells in columns of two.
                    for (int x = 0; x < 6; x++) {
                        if (cells.get(x) == null) {
                            PdfPCell c = new PdfPCell();
                            c.setBorder(0);
                            table.addCell(c);
                            table.addCell(c);
                        } else {
                            table.addCell(cells.get(x));
                            table.addCell(cells_barcode.get(x));
                        }
                        if (cells.get(x + 6) == null) {
                            PdfPCell c = new PdfPCell();
                            c.setBorder(0);
                            table.addCell(c);
                            table.addCell(c);
                        } else {
                            table.addCell(cells.get(x + 6));
                            table.addCell(cells_barcode.get(x + 6));
                        }
                    }
                    // Reset to begin next page
                    cellCounter = 0;
                    document.add(table);
                    table = new PdfPTable(4);
                    table.setWidthPercentage(100f);
                    table.setWidths(cellWidths);
                    for (int x = 0; x < 12; x++) {
                        cells.set(x, null);
                        cells_barcode.set(x, null);
                    }
                }
            } // end loop through toPrint (for a taxon)
            counter++;
        } // end while results has next (for all taxa requested)
          // get any remaining cells in pairs
        for (int x = 0; x < 6; x++) {
            if (cells.get(x) == null) {
                PdfPCell c = new PdfPCell();
                c.setBorder(0);
                table.addCell(c);
                table.addCell(c);
            } else {
                table.addCell(cells.get(x));
                table.addCell(cells_barcode.get(x));
            }
            if (cells.get(x + 6) == null) {
                PdfPCell c = new PdfPCell();
                c.setBorder(0);
                table.addCell(c);
                table.addCell(c);
            } else {
                table.addCell(cells.get(x + 6));
                table.addCell(cells_barcode.get(x + 6));
            }
        }
        // add any remaining cells
        document.add(table);
        try {
            document.close();
        } catch (Exception e) {
            throw new PrintFailedException("No labels to print." + e.getMessage());
        }
        // Check to see if there was content in the document.
        if (counter == 0) {
            result = false;
        } else {
            // Printed to pdf ok.
            result = true;
            // Increment number printed.
            i = taxa.iterator();
            while (i.hasNext()) {
                label = i.next();
                for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) {
                    label.setPrinted(label.getPrinted() + 1);
                }
                label.setNumberToPrint(0);
                try {
                    uls.attachDirty(label);
                } catch (SaveFailedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new PrintFailedException("File not found.");
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new PrintFailedException("Error buiding PDF document.");
    } catch (OutOfMemoryError e) {
        System.out.println("Out of memory error. " + e.getMessage());
        System.out.println("Failed.  Too many labels.");
        throw new PrintFailedException("Ran out of memory, too many labels at once.");
    }
    return result;
}

From source file:jm.Reporte.java

License:GNU General Public License

public void lista(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros) {
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {/*from   w ww. j a  v  a2s.  c  o m*/
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));

        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        ResultSetMetaData mdata = registros.getMetaData();
        int numCols = mdata.getColumnCount();
        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        int num = 1;
        try {
            while (registros.next()) {
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                for (int i = 1; i <= numCols; i++) {
                    tbl_det.addCell(
                            Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""),
                                    Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                }
                num++;
            }
            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void lista(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros,
        int lim) {
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {//from w ww.  j a  v  a2s  .com
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));
        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        int num = 1;
        int alineacion = Element.ALIGN_LEFT;
        try {
            while (registros.next()) {
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                for (int i = 1; i <= lim; i++) {
                    //alineacion = (i==lim) ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT;
                    tbl_det.addCell(
                            Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""),
                                    Font.TIMES_ROMAN, 8, Font.NORMAL, alineacion, 1));
                }
                num++;
            }
            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void lista(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros,
        char sumDesde) {
    int sumarDesde = Integer.parseInt("" + sumDesde);
    int num_sumas = cabTabla.length - sumarDesde;
    float sumas[] = new float[num_sumas];
    float valor = 0;
    int pos = 0;/*  w ww.j ava 2  s .  c  o m*/
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));

        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        ResultSetMetaData mdata = registros.getMetaData();
        int numCols = mdata.getColumnCount();
        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        int num = 1;
        try {
            while (registros.next()) {
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                pos = 0;
                for (int i = 1; i <= numCols; i++) {
                    if (i < sumarDesde) {
                        tbl_det.addCell(Addons.setCeldaPDF(
                                ((registros.getString(i) != null) ? registros.getString(i) : ""),
                                Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                    } else {
                        valor = (registros.getString(i) != null) ? registros.getFloat(i) : 0;
                        tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8,
                                Font.NORMAL, Element.ALIGN_RIGHT, 1));
                        sumas[pos] = Float.parseFloat(this.formatoNumero.format(sumas[pos])) + valor;
                        pos++;
                    }
                }
                num++;
            }

            tbl_det.addCell(Addons.setCeldaPDF("TOTALES:  ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                    Element.ALIGN_RIGHT, 0, 4, sumarDesde));
            for (int j = 0; j < sumas.length; j++) {
                tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(sumas[j]), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0));
            }

            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void sumLista(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros) {
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {// w  w  w.j  av  a  2  s .co m
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));
        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        ResultSetMetaData mdata = registros.getMetaData();
        int numCols = mdata.getColumnCount();
        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        int num = 1;
        //int num2 = 1;
        float suma_total = 0;
        float consumo = 0;
        int alineacion = Element.ALIGN_LEFT;
        try {
            while (registros.next()) {
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                //tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num2), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1));
                for (int i = 1; i <= numCols; i++) {
                    alineacion = (i == numCols) ? Element.ALIGN_RIGHT : Element.ALIGN_LEFT;
                    tbl_det.addCell(
                            Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""),
                                    Font.TIMES_ROMAN, 8, Font.NORMAL, alineacion, 1));
                }
                consumo = (registros.getString(numCols) != null) ? registros.getFloat(numCols) : 0;
                suma_total = Float.parseFloat(this.formatoNumero.format(suma_total)) + consumo;
                num++;
                //num2++;
            }
            tbl_det.addCell(Addons.setCeldaPDF("TOTAL:  " + Addons.truncar(suma_total), Font.TIMES_ROMAN, 10,
                    Font.NORMAL, Element.ALIGN_RIGHT, 0, 5, numCols + 2));

            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void listaAgrupada(HttpServletResponse response, String[] cabTabla, float[] anchoTabla,
        ResultSet registros) {/*from w ww.j a v  a  2s  .c o  m*/
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));
        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        ResultSetMetaData mdata = registros.getMetaData();
        int numCols = mdata.getColumnCount();
        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        int num = 1;
        int num2 = 1;
        String aux = "";
        String columna1 = "";
        try {
            while (registros.next()) {
                columna1 = (registros.getString(1) != null) ? registros.getString(1) : "";
                if (aux.compareTo(columna1) != 0) {
                    tbl_det.addCell(Addons.setCeldaPDF(columna1, Font.TIMES_ROMAN, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 3, numCols + 1));
                    aux = columna1;
                    num2 = 1;
                }
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num2), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                for (int i = 2; i <= numCols; i++) {
                    tbl_det.addCell(
                            Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""),
                                    Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                }
                num++;
                num2++;
            }
            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void activosCustorios(HttpServletResponse response, String[] cabTabla, float[] anchoTabla,
        ResultSet registros, DataBase objDB) {
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {//from www.java 2 s.c  o  m
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));
        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        ResultSetMetaData mdata = registros.getMetaData();
        int numCols = mdata.getColumnCount();
        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        int num = 1;
        int num2 = 1;
        String aux = "";
        String columna1 = "";
        String persona_recibe = "";
        String fecha = "";
        String id_activo = "";
        try {
            while (registros.next()) {
                columna1 = (registros.getString(1) != null) ? registros.getString(1) : "";
                if (aux.compareTo(columna1) != 0) {
                    tbl_det.addCell(Addons.setCeldaPDF(columna1, Font.TIMES_ROMAN, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 3, numCols + 2));
                    aux = columna1;
                    num2 = 1;
                }
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num2), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                for (int i = 2; i < numCols; i++) {
                    tbl_det.addCell(
                            Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""),
                                    Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                }
                id_activo = (registros.getString("id_activo") != null) ? registros.getString("id_activo") : "";
                try {
                    ResultSet rsCustodio = objDB.consulta(
                            "select persona_recibe, toDateSQL(max(fecha)) as fecha from tbl_activo_custodio as AC inner join tbl_activo_personalizacion as AP "
                                    + "on AC.id_activo_personalizacion=AP.id_activo_personalizacion where AC.eliminado=false and AC.id_activo="
                                    + id_activo
                                    + " group by persona_recibe,AP.id_activo_personalizacion order by AP.id_activo_personalizacion desc");
                    if (rsCustodio.next()) {
                        persona_recibe = (rsCustodio.getString("persona_recibe") != null)
                                ? rsCustodio.getString("persona_recibe")
                                : "";
                        fecha = (rsCustodio.getString("fecha") != null) ? rsCustodio.getString("fecha") : "";
                        rsCustodio.close();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                tbl_det.addCell(Addons.setCeldaPDF(persona_recibe, Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_LEFT, 1));
                tbl_det.addCell(
                        Addons.setCeldaPDF(fecha, Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                num++;
                num2++;
            }
            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void ventas(HttpServletResponse response, ResultSet registros, DataBase objDB, String iva_vigente) {
    String[] cabTabla = new String[] { "Nro.", "RUC", "RAZON SOCIAL", "Nro. FAC.", "F. EMI.", "F. PAGO", "IP",
            "SUBTOTAL", "DESC.", "SUB. 0", "IVA " + iva_vigente, "TOTAL", "DEUDA", "RETENCION" };
    float[] anchoTabla = new float[] { 20f, 55f, 90f, 60f, 45f, 40f, 60f, 35f, 30f, 35f, 35f, 35f, 35f, 35f };

    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {/*from www. j av a 2 s. co  m*/
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));
        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        ResultSetMetaData mdata = registros.getMetaData();
        int numCols = mdata.getColumnCount();
        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        int num = 1;
        int num2 = 1;
        String aux = "";
        String id_factura_venta = "-1";
        String columna2 = "";
        float suma_parcial[] = { 0, 0, 0, 0, 0, 0, 0 };
        float suma_total[] = { 0, 0, 0, 0, 0, 0, 0 };
        float valor[] = { 0, 0, 0, 0, 0, 0, 0 };
        int pos = 0;
        ResultSet retencion = null;

        try {
            while (registros.next()) {
                id_factura_venta = (registros.getString("id_factura_venta") != null)
                        ? registros.getString("id_factura_venta")
                        : "-1";
                columna2 = (registros.getString(2) != null) ? registros.getString(2) : "";
                pos = 0;
                if (aux.compareTo(columna2) != 0) {
                    if (num > 1) {
                        tbl_det.addCell(Addons.setCeldaPDF("SUBTOTALES:  ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                                Element.ALIGN_RIGHT, 0, 4, 7));
                        for (int j = 0; j < suma_parcial.length; j++) {
                            tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_parcial[j]),
                                    Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_RIGHT, 0));
                            suma_parcial[j] = 0;
                        }
                    }
                    tbl_det.addCell(Addons.setCeldaPDF(columna2, Font.TIMES_ROMAN, 8, Font.NORMAL,
                            Element.ALIGN_LEFT, 1, 3, numCols + 1));
                    aux = columna2;
                    num2 = 1;
                }
                //tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_CENTER, 1));
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num2), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                String ax_anulada = "";
                for (int i = 3; i <= numCols; i++) {
                    if (i <= 8) {
                        tbl_det.addCell(Addons.setCeldaPDF(
                                ((registros.getString(i) != null) ? registros.getString(i) : ""),
                                Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                    } else {
                        ax_anulada = (registros.getString("anulada") != null) ? registros.getString("anulada")
                                : "";
                        valor[pos] = (registros.getString(i) != null) ? registros.getFloat(i) : 0;
                        tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor[pos]), Font.TIMES_ROMAN, 8,
                                Font.NORMAL, Element.ALIGN_RIGHT, 1));
                        if (ax_anulada.compareTo("ANULADA") != 0) {
                            suma_parcial[pos] = Float.parseFloat(this.formatoNumero.format(suma_parcial[pos]))
                                    + valor[pos];
                            suma_total[pos] = Float.parseFloat(this.formatoNumero.format(suma_total[pos]))
                                    + valor[pos];
                        }
                        pos++;
                    }
                }

                valor[6] = 0;
                try {
                    retencion = objDB.consulta(
                            "select ret_impuesto_retenido from tbl_retencion_venta where anulado=false and id_factura_venta="
                                    + id_factura_venta + ";");
                    if (retencion.next()) {
                        valor[6] = (retencion.getString("ret_impuesto_retenido") != null)
                                ? retencion.getFloat("ret_impuesto_retenido")
                                : 0;
                        retencion.close();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor[6]), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1));
                suma_parcial[6] = Float.parseFloat(this.formatoNumero.format(suma_parcial[6])) + valor[6];
                suma_total[6] = Float.parseFloat(this.formatoNumero.format(suma_total[6])) + valor[6];

                num++;
                num2++;
            }
            tbl_det.addCell(Addons.setCeldaPDF("SUBTOTALES:  ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                    Element.ALIGN_RIGHT, 0, 4, 7));
            for (int j = 0; j < suma_parcial.length; j++) {
                tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_parcial[j]), Font.TIMES_ROMAN, 8,
                        Font.NORMAL, Element.ALIGN_RIGHT, 0));
            }
            tbl_det.addCell(Addons.setCeldaPDF("TOTALES:  ", Font.TIMES_ROMAN, 9, Font.NORMAL,
                    Element.ALIGN_RIGHT, 0, 4, 7));
            for (int j = 0; j < suma_total.length; j++) {
                tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(suma_total[j]), Font.TIMES_ROMAN, 8,
                        Font.NORMAL, Element.ALIGN_RIGHT, 0));
            }

            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}

From source file:jm.Reporte.java

License:GNU General Public License

public void compras(HttpServletResponse response, String[] cabTabla, float[] anchoTabla, ResultSet registros,
        DataBase objDB) {/*from w w  w. j  a  v  a 2s.  c o m*/
    //int sumarDesde = 6;
    //int num_sumas = cabTabla.length - sumarDesde;
    float sumas[] = new float[6];
    float valor = 0;
    /* inicio PDF */
    Rectangle orientacion = (this.vertical) ? PageSize.A4 : PageSize.A4.rotate();
    Document document = new Document(orientacion);// paso 1
    document.setMargins(0, 0, 50, 80); /*Izquierda, derecha, tope, pie */
    try {
        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); // paso 2
        writer.setPageEvent(new Reporte(this.vertical, this.logo, this.titulo, this.ruc, this.subtitulo,
                this.direccion, this.sucursal, this.rep_pie));

        document.open(); // paso 3

        /* todo el cuerpo del doc es el paso 4 */

        document.add(Addons.setCabecera(this.logo, this.titulo, this.ruc, this.subtitulo, this.direccion,
                this.sucursal));

        document.add(Addons.setCabeceraTabla(cabTabla, anchoTabla));

        PdfPTable tbl_det = new PdfPTable(anchoTabla);
        int num = 1;
        String id_factura_compra = "";
        try {
            while (registros.next()) {
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(num), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_CENTER, 1));
                for (int i = 2; i <= 6; i++) {
                    tbl_det.addCell(
                            Addons.setCeldaPDF(((registros.getString(i) != null) ? registros.getString(i) : ""),
                                    Font.TIMES_ROMAN, 8, Font.NORMAL, Element.ALIGN_LEFT, 1));
                }
                valor = (registros.getString("subtotal") != null) ? registros.getFloat("subtotal") : 0;
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1));
                sumas[0] = Float.parseFloat(this.formatoNumero.format(sumas[0])) + valor;

                valor = (registros.getString("descuento") != null) ? registros.getFloat("descuento") : 0;
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1));
                sumas[1] = Float.parseFloat(this.formatoNumero.format(sumas[1])) + valor;

                valor = (registros.getString("subtotal_0") != null) ? registros.getFloat("subtotal_0") : 0;
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1));
                sumas[2] = Float.parseFloat(this.formatoNumero.format(sumas[2])) + valor;

                valor = (registros.getString("iva_2") != null) ? registros.getFloat("iva_2") : 0;
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1));
                sumas[3] = Float.parseFloat(this.formatoNumero.format(sumas[3])) + valor;

                id_factura_compra = (registros.getString("id_factura_compra") != null)
                        ? registros.getString("id_factura_compra")
                        : "";
                valor = 0;
                try {
                    ResultSet rs = objDB.consulta(
                            "select ret_impuesto_retenido from tbl_retencion_compra where id_factura_compra="
                                    + id_factura_compra + " and documento='f'");
                    if (rs.next()) {
                        valor = (rs.getString("ret_impuesto_retenido") != null)
                                ? rs.getFloat("ret_impuesto_retenido")
                                : 0;
                        rs.close();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }

                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1));
                sumas[4] = Float.parseFloat(this.formatoNumero.format(sumas[4])) + valor;

                valor = (registros.getString("total_compra") != null) ? registros.getFloat("total_compra") : 0;
                tbl_det.addCell(Addons.setCeldaPDF(String.valueOf(valor), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 1));
                sumas[5] = Float.parseFloat(this.formatoNumero.format(sumas[5])) + valor;

                num++;
            }

            tbl_det.addCell(Addons.setCeldaPDF("TOTALES:  ", Font.TIMES_ROMAN, 8, Font.NORMAL,
                    Element.ALIGN_RIGHT, 0, 4, 6));
            for (int j = 0; j < sumas.length; j++) {
                tbl_det.addCell(Addons.setCeldaPDF(Addons.truncar(sumas[j]), Font.TIMES_ROMAN, 8, Font.NORMAL,
                        Element.ALIGN_RIGHT, 0));
            }

            registros.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        document.add(tbl_det);

    } catch (IllegalStateException ie) {
        ie.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    document.close(); // paso 5
    /* fin PDF */
}