Example usage for com.itextpdf.text BaseColor BaseColor

List of usage examples for com.itextpdf.text BaseColor BaseColor

Introduction

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

Prototype

public BaseColor(final float red, final float green, final float blue) 

Source Link

Document

Construct a BaseColor with float values.

Usage

From source file:FullPageTable.java

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document(PageSize.A4, 0, 0, 0, 0);
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();/*from w  w w.  j  a  v a 2  s.  c  o  m*/
    PdfPTable table = new PdfPTable(10);

    table.setWidthPercentage(100);
    table.setSpacingBefore(0f);
    table.setSpacingAfter(0f);

    // first row
    PdfPCell cell = new PdfPCell(new Phrase("DateRange"));
    cell.setColspan(10);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setPadding(10.0f);
    cell.setBackgroundColor(new BaseColor(140, 221, 8));
    table.addCell(cell);

    table.addCell("Calldate");
    table.addCell("Calltime");
    table.addCell("Source");
    table.addCell("DialedNo");
    table.addCell("Extension");
    table.addCell("Trunk");
    table.addCell("Duration");
    table.addCell("Calltype");
    table.addCell("Callcost");
    table.addCell("Site");

    for (int i = 0; i < 100; i++) {
        table.addCell("date" + i);
        table.addCell("time" + i);
        table.addCell("source" + i);
        table.addCell("destination" + i);
        table.addCell("extension" + i);
        table.addCell("trunk" + i);
        table.addCell("dur" + i);
        table.addCell("toc" + i);
        table.addCell("callcost" + i);
        table.addCell("Site" + i);
    }
    document.add(table);
    document.close();
}

From source file:beans.CronogramaPDF.java

private void createPdf(String dest) throws IOException, DocumentException, SQLException {
    Parametrizacion p = new Parametrizacion();
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();/*  w ww  . j  a v a2  s  .  c om*/
    PdfPTable table = new PdfPTable(12);
    BaseColor color = new BaseColor(142, 170, 219);
    PdfPCell celda;
    Phrase texto;
    Font font = new Font(Font.FontFamily.TIMES_ROMAN, 7);
    Font font1 = new Font(Font.FontFamily.TIMES_ROMAN, 10);
    table.setWidthPercentage(100);

    Image img = Image.getInstance(p.getParametro("rutaImgServer") + "logo.png");
    celda = new PdfPCell(img, true);
    celda.setPadding(5);
    celda.setColspan(4);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(
            "\n\n\nFecha de creacin: " + dateFormat.format(Calendar.getInstance().getTime()), font1));
    celda.setColspan(8);
    // head.setBackgroundColor(BaseColor.CYAN);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("CRONOGRAMA DE MANTENIMIENTOS", font));
    celda.setColspan(112);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("N", font));
    celda.setColspan(1);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("CODIGO", font));
    celda.setColspan(1);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("FECHA SOLICITUD", font));
    celda.setColspan(1);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("EQUIPO", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("ACCIONES A REALIZAR", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    int i = 1;
    for (SolicitudDeMantenimiento sM : this.solicitudes) {
        if (!sM.getEstado().equals("Realizada")) {
            celda = new PdfPCell(new Phrase(i + "", font));
            celda.setColspan(1);
            table.addCell(celda);

            celda = new PdfPCell(new Phrase(sM.getCodigo(), font));
            celda.setColspan(1);
            table.addCell(celda);

            celda = new PdfPCell(new Phrase(sM.getFecha(), font));
            celda.setColspan(1);
            table.addCell(celda);

            celda = new PdfPCell(new Phrase(sM.getEquipo().getNombre(), font));
            celda.setColspan(3);
            table.addCell(celda);

            celda = new PdfPCell(new Phrase(sM.getDescripcionServicio(), font));
            celda.setColspan(3);
            table.addCell(celda);

            celda = new PdfPCell(new Phrase(sM.getDescripcionAcciones(), font));
            celda.setColspan(3);
            table.addCell(celda);
            i++;
        }

    }
    document.add(table);
    document.close();
}

From source file:beans.OrdenDeTrabajoPDF.java

private void createPdf(String dest) throws IOException, DocumentException {
    Parametrizacion p = new Parametrizacion();
    this.listaPartes = new JsonParser().parse(ot.getPartes()).getAsJsonArray();
    this.listaDescripcionesTrabajos = new JsonParser().parse(ot.getDescripcionesTrabajos()).getAsJsonArray();
    this.listaMateriales = new JsonParser().parse(ot.getMateriales()).getAsJsonArray();

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();/*  w  w w.j  a  va2 s .c om*/
    PdfPTable table = new PdfPTable(12);
    BaseColor color = new BaseColor(142, 170, 219);
    PdfPCell celda;
    Phrase texto;
    Font font = new Font(Font.FontFamily.TIMES_ROMAN, 10);
    table.setWidthPercentage(100);

    Image img = Image.getInstance(p.getParametro("rutaImgServer") + "logo.png");
    celda = new PdfPCell(img, true);
    celda.setPadding(5);
    celda.setColspan(4);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("ORDEN DE TRABAJO N:" + this.ot.getNumeroOrdenDeTrabajo()
            + "\nFECHA INICIO:" + this.ot.getFechaInicio() + "\nFECHA FIN:" + this.ot.getFechaFin()
            + "\nSOLICITUD N:" + this.ot.getSolicitudDeMantenimiento().getCodigo() + "", font));
    celda.setColspan(8);
    // head.setBackgroundColor(BaseColor.CYAN);
    table.addCell(celda);
    String tipoSolicitud = ot.getTipoSolicitud();
    if (tipoSolicitud.equals("Urgente")) {
        celda = new PdfPCell(new Phrase("TIPO DE SOLICITUD    NORMAL:      URGENTE: X", font));
        celda.setColspan(12);
        table.addCell(celda);
    } else {
        celda = new PdfPCell(new Phrase("TIPO DE SOLICITUD    NORMAL: X    URGENTE:", font));
        celda.setColspan(12);
        table.addCell(celda);
    }

    if (ot.isDptAdmyControl()) {
        celda = new PdfPCell(new Phrase(
                "DTO.ADMS. Y CONTROL DE LA PRODUCCION" + " GENERA ORDEN DE TRABAJO DE MTTO SI:X           NO:",
                font));
        celda.setColspan(12);
        table.addCell(celda);
    } else {
        celda = new PdfPCell(new Phrase(
                "DTO.ADMS. Y CONTROL DE LA PRODUCCION" + " GENERA ORDEN DE TRABAJO DE MTTO SI:            NO:X",
                font));
        celda.setColspan(12);
        table.addCell(celda);
    }

    celda = new PdfPCell(
            new Phrase("CODIGO EQUIPO: " + ot.getSolicitudDeMantenimiento().getEquipo().getCodigo(), font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(
            new Phrase("NOMBRE EQUIPO: " + ot.getSolicitudDeMantenimiento().getEquipo().getNombre(), font));
    celda.setColspan(9);
    table.addCell(celda);
    String tipoMantenimiento = "";
    for (String element : ot.getTiposDeMantenimiento()) {
        tipoMantenimiento += element + "\n";
    }

    celda = new PdfPCell(new Phrase("TIPO DE MANTENIMIENTO\n", font));
    celda.setColspan(12);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(tipoMantenimiento, font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("PARTE", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("ANOMALIA", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("CAUSA", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("POSIBLE SOLUCION", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    for (int i = 0; i < listaPartes.size(); i++) {

        celda = new PdfPCell(new Phrase(
                listaPartes.get(i).getAsJsonObject().get("parte").toString().replace("\"", ""), font));
        celda.setColspan(3);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaPartes.get(i).getAsJsonObject().get("anomalia").toString().replace("\"", ""), font));
        celda.setColspan(3);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaPartes.get(i).getAsJsonObject().get("causa").toString().replace("\"", ""), font));
        celda.setColspan(3);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaPartes.get(i).getAsJsonObject().get("solucion").toString().replace("\"", ""), font));
        celda.setColspan(3);
        table.addCell(celda);

    }

    celda = new PdfPCell(new Phrase("SOLICTADA POR: " + ot.getSolicitadaPor() + "\n\nFIRMA", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("REVISADA POR: " + ot.getRevisadaPor() + "\n\nFIRMA", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("AUTORIZADA POR: " + ot.getAutorizadaPor() + "\n\nFIRMA", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("N", font));
    celda.setColspan(1);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS TRABAJOS A REALIZAR", font));
    celda.setColspan(11);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    for (int i = 0; i < listaDescripcionesTrabajos.size(); i++) {

        celda = new PdfPCell(new Phrase((i + 1) + "", font));
        celda.setColspan(1);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaDescripcionesTrabajos.get(i).getAsJsonObject().get("trabajo").toString().replace("\"", ""),
                font));
        celda.setColspan(11);
        table.addCell(celda);

    }

    celda = new PdfPCell(new Phrase("MATERIALES", font));
    celda.setColspan(12);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("N", font));
    celda.setColspan(1);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("CANTIDAD", font));
    celda.setColspan(2);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN", font));
    celda.setColspan(3);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("REFERENCIA", font));
    celda.setColspan(2);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("VALOR UNI", font));
    celda.setColspan(2);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("VALOR TOTAL", font));
    celda.setColspan(2);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    for (int i = 0; i < listaMateriales.size(); i++) {
        celda = new PdfPCell(new Phrase("" + (1 + i), font));
        celda.setColspan(1);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaMateriales.get(i).getAsJsonObject().get("cantidad").toString().replace("\"", ""), font));
        celda.setColspan(2);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaMateriales.get(i).getAsJsonObject().get("descripcion").toString().replace("\"", ""),
                font));
        celda.setColspan(3);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaMateriales.get(i).getAsJsonObject().get("referencia").toString().replace("\"", ""), font));
        celda.setColspan(2);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaMateriales.get(i).getAsJsonObject().get("unitario").toString().replace("\"", ""), font));
        celda.setColspan(2);
        table.addCell(celda);

        celda = new PdfPCell(new Phrase(
                listaMateriales.get(i).getAsJsonObject().get("total").toString().replace("\"", ""), font));
        celda.setColspan(2);
        table.addCell(celda);
    }
    celda = new PdfPCell(new Phrase("COSTOS", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MANO DE OBRA: $" + ot.getCostoManoDeObra() + "", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("MATERIALES: $" + ot.getCostoMateriales() + "", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL: $" + ot.getCostoTotal() + "", font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TIEMPO EMPLEADO", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL HORAS MTO: " + ot.getTotalHorasMto() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL HORAS PARADA: " + ot.getTotalHorasParada() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS DAOS ENCONTRADOS", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + ot.getDescripcionDanos(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DE LOS TRABAJOS REALIZADOS", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + ot.getDescripcionTrabajosRealizados(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("OBSERVACIONES Y RECOMENDACIONES", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + ot.getObservaciones(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("EJECUTO: " + ot.getEjecutadoPor() + "\n\nFIRMA", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("RECIBI Y APROB: " + ot.getRecibidoAprobadoPor() + "\n\nFIRMA", font));
    celda.setColspan(6);
    table.addCell(celda);

    document.add(table);
    document.close();
}

From source file:beans.SolicitudDeMantenimientoPDF.java

public void createPdf(String dest) throws IOException, DocumentException {
    Parametrizacion p = new Parametrizacion();
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();//from  www  .j  a va2 s . c o m
    PdfPTable table = new PdfPTable(12);
    Font font = new Font(Font.FontFamily.TIMES_ROMAN, 10);
    PdfPCell celda;
    table.setWidthPercentage(100);

    Image img = Image.getInstance(p.getParametro("rutaImgServer") + "logo.png");
    celda = new PdfPCell(img, true);
    celda.setPadding(5);
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("CODIGO: " + sm.getCodigo() + "\nREVISION: " + sm.getRevision()
            + "\nSOLICITUD DE SERVICIO: " + sm.getSolicitudDeServicio() + "\nFECHA: " + sm.getFecha() + "",
            font));
    celda.setColspan(8);
    // head.setBackgroundColor(BaseColor.CYAN);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("SECCION", font));
    celda.setColspan(4);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MAQUINA", font));
    celda.setColspan(4);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("NOMBRE DEL OPERARIO", font));
    celda.setColspan(4);
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getEquipo().getUbicacion(), font));
    celda.setColspan(4);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("" + sm.getEquipo().getNombre(), font));
    celda.setColspan(4);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("" + sm.getEquipo().getOperario(), font));
    celda.setColspan(4);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    String reparacion = " ";
    String mtoMecanico = " ";
    String mtoPreventivo = " ";
    String mtoElectrico = " ";
    String mtoCorrectivo = " ";
    String otros = " ";
    if (sm.isReparacion()) {
        reparacion += " X";
    }
    if (sm.isMtoMecanico()) {
        mtoMecanico += " X";
    }
    if (sm.isMtoPreventivo()) {
        mtoPreventivo += " X";
    }
    if (sm.isMtoElectrico()) {
        mtoElectrico += " X";
    }
    if (sm.isMtoCorrectivo()) {
        mtoCorrectivo += " X";
    }
    if (sm.isOtros()) {
        otros += " X";
    }

    celda = new PdfPCell(new Phrase("REPARACION", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(reparacion, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. MECANICO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoMecanico, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. PREVENTIVO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoPreventivo, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. ELECTRICO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoElectrico, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("MTO. CORRECTIVO", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(mtoCorrectivo, font));
    celda.setColspan(1);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase("OTROS", font));
    celda.setColspan(3);
    table.addCell(celda);
    celda = new PdfPCell(new Phrase(otros, font));
    celda.setColspan(1);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DEL SERVICIO SOLICITADO", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getDescripcionServicio(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("DESCRIPCIN DE ACCIONES A REALIZAR", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getDescripcionAcciones(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("MATERIAL A EMPLEAR", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("" + sm.getMaterial(), font));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("GENERALIDADES", font));
    celda.setBackgroundColor(new BaseColor(142, 170, 219));
    celda.setColspan(12);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL HORAS PARADA: " + sm.getHorasParada() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("HORA SOLICITUD: " + sm.getHoraSolicitud() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("TOTAL HORAS MTO: " + sm.getHorasMTO() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("HORA ENTREGA: " + sm.getHoraEntrega() + "", font));
    celda.setColspan(6);
    table.addCell(celda);

    celda = new PdfPCell(new Phrase("SERVICIO SOLICITADO POR: " + sm.getSolicitadoPor() + "\n"
            + "SERVICIO REALIZADO POR: " + sm.getRealizadoPor() + "\n" + "RECIBO A CONFORMIDAD: "
            + sm.getRecibidoPor() + "\n\n\n FIRMA", font));
    celda.setColspan(12);
    table.addCell(celda);
    document.add(table);
    document.close();
}

From source file:cis_690_report.DynamicReporter.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed

    JFileChooser chooser = new JFileChooser();
    int option = chooser.showOpenDialog(null);
    if (option == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile() != null) {
            File3 = chooser.getSelectedFile().getAbsolutePath();
        }/*from ww w  .j a  v a2 s  .c  om*/

        try {
            br1 = new BufferedReader(new FileReader(f));
            BufferedReader b1 = new BufferedReader(new FileReader(f));
        } catch (FileNotFoundException ex) {

        }

        String line = "";

        bull1 = new String[number_of_rows - 1][];
        int k = 0;
        BufferedReader br3 = null;
        try {
            br3 = new BufferedReader(new FileReader(f));
        } catch (FileNotFoundException ex) {
        }
        try {
            while ((line = br3.readLine()) != null) {

                // use comma as separator
                String Bull[] = line.split(",");
                if (k != 0) {
                    System.out.println(Bull.length);
                    bull1[k - 1] = new String[Bull.length];
                    for (int j = 0; j < Bull.length; j++) {

                        bull1[k - 1][j] = Bull[j];

                    }
                }
                k++;
            }
        } catch (IOException ex) {
        }
        Document doc = new Document();
        PdfWriter docWriter = null;

        DecimalFormat df = new DecimalFormat("0.00");

        try {

            //special font sizes
            Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6);
            Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
            Font bfBold25 = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD);
            //file path

            docWriter = PdfWriter.getInstance(doc, new FileOutputStream(File3));

            //document header attributes
            doc.addAuthor("Shubh Chopra");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Shubh Chopra");
            doc.addTitle("BES");
            doc.setPageSize(PageSize.LETTER.rotate());

            //open document
            doc.open();
            //create a paragraph
            Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n");
            paragraph.setFont(bfBold25);
            paragraph.setAlignment(Element.ALIGN_CENTER);

            Image img = Image.getInstance("VETMED.png");

            img.scaleToFit(300f, 150f);
            doc.add(paragraph);
            PdfPTable table1 = new PdfPTable(2);
            table1.setWidthPercentage(100);
            PdfPCell cell = new PdfPCell(img);
            cell.setBorder(PdfPCell.NO_BORDER);
            table1.addCell(cell);

            String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64]
                    + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: "
                    + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n";

            table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT));
            doc.add(table1);

            //specify column widths
            int temp = dlm2.size();

            float[] columnWidths = new float[temp];
            for (int x = 0; x < columnWidths.length; x++) {
                columnWidths[x] = 2f;
            }

            //create PDF table with the given widths
            PdfPTable table = new PdfPTable(columnWidths);
            // set table width a percentage of the page width
            table.setWidthPercentage(90f);
            DynamicReporter re;
            re = new DynamicReporter();

            for (int i = 0; i < dlm2.size(); i++) {
                String[] parts = dlm2.get(i).toString().split(": ");
                String part2 = parts[1];

                re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12);
            }

            table.setHeaderRows(1);
            //insert an empty row

            //create section heading by cell merging

            //just some random data to fill 
            for (int x = 0; x < dlm3.size(); x++) {
                String str = dlm3.get(x).toString();

                System.out.println(str);
                String[] parts = str.split(":");

                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                for (int i = 0; i < dlm2.getSize(); i++)
                    for (int j = 0; j < header.length && j < bull1[row].length; j++) {
                        String str1 = dlm2.get(i).toString();
                        String[] p1 = str1.split(": ");
                        String p2 = p1[0];
                        if (p2.equals(header[j])) {
                            re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12);
                        }
                    }
                // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12);
            }

            doc.add(table);
            if (jCheckBox2.isSelected()) {
                DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                for (int i = 0; i < dlm3.size(); i++) {

                    String str = dlm3.get(i).toString();
                    System.out.println(str);
                    String[] parts = str.split(":");
                    String part1 = parts[0];
                    String part2 = parts[1];
                    System.out.println(part2);
                    int row = Integer.parseInt(part2) - 1;
                    float total = (float) 0.0;
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                        if (bull1[row][j].equals("")) {
                            continue;
                        } else {
                            total += Integer.parseInt(bull1[row][j]);
                        }

                    }
                    System.out.println(total);
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                        if (!bull1[row][j].equals("")) {

                            String[] Parts = header[j].split("_");
                            String Part2 = Parts[1];
                            dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1);
                        } else {
                            dataSet.setValue(0, "Percent", header[j]);

                        }
                    }

                }
                JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology",
                        "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false);

                if (dlm3.size() > 12) {
                    doc.newPage();
                }
                PdfContentByte contentByte = docWriter.getDirectContent();
                PdfTemplate template = contentByte.createTemplate(325, 250);
                PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                chart.draw(graphics2d, rectangle2d);

                graphics2d.dispose();
                contentByte.addTemplate(template, 0, 0);
            }
            if (jCheckBox1.isSelected()) {

                for (int i = 0; i < dlm3.size(); i++) {
                    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                    String str = dlm3.get(i).toString();
                    System.out.println(str);
                    String[] parts = str.split(":");
                    String part1 = parts[0];
                    String part2 = parts[1];
                    System.out.println(part2);
                    int row = Integer.parseInt(part2) - 1;
                    float total = (float) 0.0;
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                        if (bull1[row][j].equals("")) {
                            continue;
                        } else {
                            total += Integer.parseInt(bull1[row][j]);
                        }

                    }
                    System.out.println(total);
                    for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                        if (!bull1[row][j].equals("")) {

                            String[] Parts = header[j].split("_");
                            String Part2 = Parts[1];
                            dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2);
                        } else {
                            dataSet.setValue(0, "Percent", header[j]);

                        }
                    }
                    JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1,
                            "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false);
                    if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) {
                        doc.newPage();
                    }
                    PdfContentByte contentByte = docWriter.getDirectContent();
                    PdfTemplate template = contentByte.createTemplate(325, 250);
                    PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                    Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                    chart.draw(graphics2d, rectangle2d);

                    graphics2d.dispose();
                    contentByte.addTemplate(template, 0, 0);

                    doc.newPage();
                }
            }

        } catch (DocumentException dex) {
            dex.printStackTrace();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (doc != null) {
                //close the document
                doc.close();
            }
            if (docWriter != null) {
                //close the writer
                docWriter.close();
            }

        }
    }
    // TODO add your handling code here:

}

From source file:cis_690_report.DynamicReporter.java

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed

    // TODO add your handling code here:
    // build a controller
    SwingController controller = new SwingController();

    // Build a SwingViewFactory configured with the controller
    SwingViewBuilder factory = new SwingViewBuilder(controller);

    // Use the factory to build a JPanel that is pre-configured
    //with a complete, active Viewer UI.
    JPanel viewerComponentPanel = factory.buildViewerPanel();

    // add copy keyboard command
    ComponentKeyBinding.install(controller, viewerComponentPanel);

    // add interactive mouse link annotation support via callback
    controller.getDocumentViewController().setAnnotationCallback(
            new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController()));

    // Create a JFrame to display the panel in
    JFrame window = new JFrame("Using the Viewer Component");
    window.getContentPane().add(viewerComponentPanel);
    window.pack();// w w  w.  j a v a  2  s  .c  o  m
    window.setVisible(true);

    String Path;
    Path = "C:/Users/Shubh Chopra/Documents/reporter.pdf";

    try {
        br1 = new BufferedReader(new FileReader(f));
        BufferedReader b1 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {

    }

    String line = "";

    bull1 = new String[number_of_rows - 1][];
    int k = 0;
    BufferedReader br3 = null;
    try {
        br3 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {
    }
    try {
        while ((line = br3.readLine()) != null) {

            // use comma as separator
            String Bull[] = line.split(",");
            if (k != 0) {
                System.out.println(Bull.length);
                bull1[k - 1] = new String[Bull.length];
                for (int j = 0; j < Bull.length; j++) {

                    bull1[k - 1][j] = Bull[j];

                }
            }
            k++;
        }
    } catch (IOException ex) {
    }
    Document doc = new Document();
    PdfWriter docWriter = null;

    DecimalFormat df = new DecimalFormat("0.00");

    try {

        //special font sizes
        Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6);
        Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);

        //file path

        docWriter = PdfWriter.getInstance(doc, new FileOutputStream(Path));

        //document header attributes
        doc.addAuthor("Shubh Chopra");
        doc.addCreationDate();
        doc.addProducer();
        doc.addCreator("Shubh Chopra");
        doc.addTitle("BES");
        doc.setPageSize(PageSize.LETTER.rotate());

        //open document
        doc.open();
        //create a paragraph
        Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n");
        paragraph.setFont(bfBold20);
        paragraph.setAlignment(Element.ALIGN_CENTER);

        Image img = Image.getInstance("VETMED.png");

        img.scaleToFit(300f, 150f);
        doc.add(paragraph);
        PdfPTable table1 = new PdfPTable(2);
        table1.setWidthPercentage(100);
        PdfPCell cell = new PdfPCell(img);
        cell.setBorder(PdfPCell.NO_BORDER);
        table1.addCell(cell);

        String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64]
                + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: "
                + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n";

        table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT));
        doc.add(table1);

        //specify column widths
        int temp = dlm2.size();

        float[] columnWidths = new float[temp];
        for (int x = 0; x < columnWidths.length; x++) {
            columnWidths[x] = 2f;
        }

        //create PDF table with the given widths
        PdfPTable table = new PdfPTable(columnWidths);
        // set table width a percentage of the page width
        table.setWidthPercentage(90f);
        DynamicReporter re;
        re = new DynamicReporter();

        for (int i = 0; i < dlm2.size(); i++) {
            String[] parts = dlm2.get(i).toString().split(": ");
            String part2 = parts[1];

            re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12);
        }

        table.setHeaderRows(1);
        //insert an empty row

        //create section heading by cell merging

        //just some random data to fill 

        for (int x = 0; x < dlm3.size(); x++) {
            String str = dlm3.get(x).toString();

            System.out.println(str);
            String[] parts = str.split(":");

            String part2 = parts[1];
            System.out.println(part2);
            int row = Integer.parseInt(part2) - 1;
            for (int i = 0; i < dlm2.getSize(); i++)
                for (int j = 0; j < header.length && j < bull1[row].length; j++) {
                    String str1 = dlm2.get(i).toString();
                    String[] p1 = str1.split(": ");
                    String p2 = p1[0];
                    if (p2.equals(header[j])) {
                        re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12);
                    }
                }
            // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12);
        }

        doc.add(table);
        if (jCheckBox2.isSelected()) {
            DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
            for (int i = 0; i < dlm3.size(); i++) {

                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }

            }
            JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology",
                    "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false);

            if (dlm3.size() > 12) {
                doc.newPage();
            }
            PdfContentByte contentByte = docWriter.getDirectContent();
            PdfTemplate template = contentByte.createTemplate(325, 250);
            PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
            Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

            chart.draw(graphics2d, rectangle2d);

            graphics2d.dispose();
            contentByte.addTemplate(template, 0, 0);
        }
        if (jCheckBox1.isSelected()) {

            for (int i = 0; i < dlm3.size(); i++) {
                DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }
                JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1,
                        "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false);
                if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) {
                    doc.newPage();
                }
                PdfContentByte contentByte = docWriter.getDirectContent();
                PdfTemplate template = contentByte.createTemplate(325, 250);
                PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                chart.draw(graphics2d, rectangle2d);

                graphics2d.dispose();
                contentByte.addTemplate(template, 0, 0);

                doc.newPage();
            }
        }

    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (doc != null) {
            //close the document
            doc.close();
        }
        if (docWriter != null) {
            //close the writer
            docWriter.close();
        }

    }
    controller.openDocument(Path);
}

From source file:cis_690_report.DynamicReporter.java

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed

    // TODO add your handling code here:
    // build a controller
    SwingController controller = new SwingController();

    // Build a SwingViewFactory configured with the controller
    SwingViewBuilder factory = new SwingViewBuilder(controller);

    // Use the factory to build a JPanel that is pre-configured
    //with a complete, active Viewer UI.
    JPanel viewerComponentPanel = factory.buildViewerPanel();

    // add copy keyboard command
    ComponentKeyBinding.install(controller, viewerComponentPanel);

    // add interactive mouse link annotation support via callback
    controller.getDocumentViewController().setAnnotationCallback(
            new org.icepdf.ri.common.MyAnnotationCallback(controller.getDocumentViewController()));

    // Create a JFrame to display the panel in
    JFrame window = new JFrame("Using the Viewer Component");
    window.getContentPane().add(viewerComponentPanel);
    window.pack();//from   w  w w.ja  v  a2s .  c om
    window.setVisible(true);

    String Path;
    Path = "C:/Users/Shubh Chopra/Documents/reporter.pdf";

    try {
        br1 = new BufferedReader(new FileReader(f));
        BufferedReader b1 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {

    }

    String line = "";

    bull1 = new String[number_of_rows - 1][];
    int k = 0;
    BufferedReader br3 = null;
    try {
        br3 = new BufferedReader(new FileReader(f));
    } catch (FileNotFoundException ex) {
    }
    try {
        while ((line = br3.readLine()) != null) {

            // use comma as separator
            String Bull[] = line.split(",");
            if (k != 0) {
                System.out.println(Bull.length);
                bull1[k - 1] = new String[Bull.length];
                for (int j = 0; j < Bull.length; j++) {

                    bull1[k - 1][j] = Bull[j];

                }
            }
            k++;
        }
    } catch (IOException ex) {
    }
    Document doc = new Document();
    PdfWriter docWriter = null;

    DecimalFormat df = new DecimalFormat("0.00");

    try {

        //special font sizes
        Font bfBold12 = new Font(Font.FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0));
        Font bf12 = new Font(Font.FontFamily.TIMES_ROMAN, 6);
        Font bfBold20 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);

        //file path

        docWriter = PdfWriter.getInstance(doc, new FileOutputStream(Path));

        //document header attributes
        doc.addAuthor("Shubh Chopra");
        doc.addCreationDate();
        doc.addProducer();
        doc.addCreator("Shubh Chopra");
        doc.addTitle("BES");
        doc.setPageSize(PageSize.LETTER.rotate());

        //open document
        doc.open();
        //create a paragraph
        Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n");
        paragraph.setFont(bfBold20);
        paragraph.setAlignment(Element.ALIGN_CENTER);

        Image img = Image.getInstance("VETMED.png");

        img.scaleToFit(300f, 150f);
        doc.add(paragraph);
        PdfPTable table1 = new PdfPTable(2);
        table1.setWidthPercentage(100);
        PdfPCell cell = new PdfPCell(img);
        cell.setBorder(PdfPCell.NO_BORDER);
        table1.addCell(cell);

        String temp1 = "\tOwner: " + bull1[1][62] + " " + bull1[1][63] + "\n\n\tRanch: " + bull1[1][64]
                + "\n\n\tAddress: " + bull1[1][55] + "\n\n\tCity: " + bull1[1][57] + "\n\n\tState: "
                + bull1[1][60] + "\tZip: " + bull1[1][61] + "\n\n\tPhone: " + bull1[1][59] + "\n\n";

        table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT));
        doc.add(table1);

        //specify column widths
        int temp = dlm2.size();

        float[] columnWidths = new float[temp];
        for (int x = 0; x < columnWidths.length; x++) {
            columnWidths[x] = 2f;
        }

        //create PDF table with the given widths
        PdfPTable table = new PdfPTable(columnWidths);
        // set table width a percentage of the page width
        table.setWidthPercentage(90f);
        DynamicReporter re;
        re = new DynamicReporter();

        for (int i = 0; i < dlm2.size(); i++) {
            String[] parts = dlm2.get(i).toString().split(": ");
            String part2 = parts[1];

            re.insertCell(table, newhead[Integer.parseInt(part2)], Element.ALIGN_CENTER, 1, bfBold12);
        }

        table.setHeaderRows(1);
        //insert an empty row

        //create section heading by cell merging

        //just some random data to fill 

        for (int x = 0; x < dlm3.size(); x++) {
            String str = dlm3.get(x).toString();

            System.out.println(str);
            String[] parts = str.split(":");

            String part2 = parts[1];
            System.out.println(part2);
            int row = Integer.parseInt(part2) - 1;
            for (int i = 0; i < dlm2.getSize(); i++)
                for (int j = 0; j < header.length && j < bull1[row].length; j++) {
                    String str1 = dlm2.get(i).toString();
                    String[] p1 = str1.split(": ");
                    String p2 = p1[0];
                    if (p2.equals(header[j])) {
                        re.insertCell(table, bull1[row][j], Element.ALIGN_CENTER, 1, bf12);
                    }
                }
            // re.insertCell(table, bull1[x][7] , Element.ALIGN_CENTER, 1, bf12);
        }

        doc.add(table);
        if (jCheckBox2.isSelected()) {
            DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
            for (int i = 0; i < dlm3.size(); i++) {

                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, Part2, part1);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }

            }
            JFreeChart chart = ChartFactory.createBarChart("Multi Bull Morphology Chart ", "Morphology",
                    "Percent", dataSet, PlotOrientation.VERTICAL, true, true, false);

            if (dlm3.size() > 12) {
                doc.newPage();
            }
            PdfContentByte contentByte = docWriter.getDirectContent();
            PdfTemplate template = contentByte.createTemplate(325, 250);
            PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
            Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

            chart.draw(graphics2d, rectangle2d);

            graphics2d.dispose();
            contentByte.addTemplate(template, 0, 0);
        }
        if (jCheckBox1.isSelected()) {

            for (int i = 0; i < dlm3.size(); i++) {
                DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
                String str = dlm3.get(i).toString();
                System.out.println(str);
                String[] parts = str.split(":");
                String part1 = parts[0];
                String part2 = parts[1];
                System.out.println(part2);
                int row = Integer.parseInt(part2) - 1;
                float total = (float) 0.0;
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {

                    if (bull1[row][j].equals("")) {
                        continue;
                    } else {
                        total += Integer.parseInt(bull1[row][j]);
                    }

                }
                System.out.println(total);
                for (int j = 77; j < header.length && j < bull1[row].length; j++) {
                    if (!bull1[row][j].equals("")) {

                        String[] Parts = header[j].split("_");
                        String Part2 = Parts[1];
                        dataSet.setValue((Integer.parseInt(bull1[row][j]) * 100) / total, "Percent", Part2);
                    } else {
                        dataSet.setValue(0, "Percent", header[j]);

                    }
                }
                JFreeChart chart = ChartFactory.createBarChart("Single Bull Morphology Chart " + part1,
                        "Morphology", "Percent", dataSet, PlotOrientation.VERTICAL, false, true, false);
                if ((dlm3.size() > 12 && i == 0) || jCheckBox2.isSelected()) {
                    doc.newPage();
                }
                PdfContentByte contentByte = docWriter.getDirectContent();
                PdfTemplate template = contentByte.createTemplate(325, 250);
                PdfGraphics2D graphics2d = new PdfGraphics2D(template, 325, 250);
                Rectangle2D rectangle2d = new Rectangle2D.Double(0, 0, 325, 250);

                chart.draw(graphics2d, rectangle2d);

                graphics2d.dispose();
                contentByte.addTemplate(template, 0, 0);

                doc.newPage();
            }
        }

    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (FileNotFoundException ex) {
        Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (doc != null) {
            //close the document
            doc.close();
        }
        if (docWriter != null) {
            //close the writer
            docWriter.close();
        }

    }
    controller.openDocument(Path);
}

From source file:cis_690_report.Reporter.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    File1 = jTextField1.getText();
    JFileChooser chooser = new JFileChooser();
    int option = chooser.showOpenDialog(null);
    if (option == JFileChooser.APPROVE_OPTION) {
        if (chooser.getSelectedFile() != null) {
            File3 = chooser.getSelectedFile().getAbsolutePath();
        }//  w w  w.j  a va  2s.  c o  m
        File file = new File(File1);

        try {
            br1 = new BufferedReader(new FileReader(file));
            b1 = new BufferedReader(new FileReader(file));
        } catch (FileNotFoundException ex) {

        }
        int number_of_rows1 = 0;
        String line = "";
        String cvsSplitBy = ",";
        try {
            while ((line = br1.readLine()) != null) {

                // use comma as separator
                number_of_rows1++;
            }

        } catch (IOException ex) {
            Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
        }

        bull1 = new String[number_of_rows1][];
        int k = 0;
        BufferedReader br2 = null;
        try {
            br2 = new BufferedReader(new FileReader(file));
        } catch (FileNotFoundException ex) {
        }
        try {
            while ((line = br2.readLine()) != null) {

                // use comma as separator
                String Bull[] = line.split(",");
                System.out.println(Bull.length);
                bull1[k] = new String[93];
                if (Bull.length < 10) {
                    for (int j = 0; j < 92; j++) {
                        bull1[k][j] = "";
                        //System.out.println(Bull[j]);
                    }
                } else {
                    for (int j = 0; j < Bull.length; j++) {
                        bull1[k][j] = Bull[j];
                        //System.out.println(Bull[j]);
                    }
                }
                k++;
            }
        } catch (IOException ex) {
        }
        Document doc = new Document();
        PdfWriter docWriter = null;

        DecimalFormat df = new DecimalFormat("0.00");

        try {

            //special font sizes
            Font bfBold12 = new Font(FontFamily.TIMES_ROMAN, 8, Font.BOLD, new BaseColor(0, 0, 0));
            Font bf12 = new Font(FontFamily.TIMES_ROMAN, 6);
            Font bfBold20 = new Font(FontFamily.TIMES_ROMAN, 12, Font.BOLD);

            //file path

            docWriter = PdfWriter.getInstance(doc, new FileOutputStream(File3));

            //document header attributes
            doc.addAuthor("Shubh Chopra");
            doc.addCreationDate();
            doc.addProducer();
            doc.addCreator("Shubh Chopra");
            doc.addTitle("BES");
            doc.setPageSize(PageSize.LETTER.rotate());

            //open document
            doc.open();
            //create a paragraph
            Paragraph paragraph = new Paragraph("BULL EVALUATION\n\n");
            paragraph.setFont(bfBold20);
            paragraph.setAlignment(Element.ALIGN_CENTER);

            Image img = Image.getInstance("VETMED.png");

            img.scaleToFit(300f, 150f);
            doc.add(paragraph);
            PdfPTable table1 = new PdfPTable(2);
            table1.setWidthPercentage(100);
            PdfPCell cell = new PdfPCell(img);
            cell.setBorder(PdfPCell.NO_BORDER);
            table1.addCell(cell);

            String temp1 = "\tOwner: " + bull1[1][78] + " " + bull1[1][79] + "\n\n\tRanch: " + bull1[1][80]
                    + "\n\n\tAddress: " + bull1[1][71] + "\n\n\tCity: " + bull1[1][73] + "\n\n\tState: "
                    + bull1[1][76] + "\tZip: " + bull1[1][77] + "\n\n\tPhone: " + bull1[1][75] + "\n\n";

            table1.addCell(getCell(temp1, PdfPCell.ALIGN_LEFT));
            doc.add(table1);

            boolean[] checkboxs = { jCheckBox1.isSelected(), jCheckBox2.isSelected(), jCheckBox3.isSelected(),
                    jCheckBox4.isSelected(), jCheckBox5.isSelected(), jCheckBox6.isSelected(),
                    jCheckBox7.isSelected(), jCheckBox8.isSelected(), jCheckBox9.isSelected(),
                    jCheckBox10.isSelected(), jCheckBox11.isSelected(), jCheckBox12.isSelected(),
                    jCheckBox13.isSelected() };
            //specify column widths
            int temp = 0;
            for (int x = 0; x < checkboxs.length; x++) {
                if (checkboxs[x] == true) {
                    temp++;
                }
            }
            float[] columnWidths = new float[temp + 5];
            for (int x = 0; x < columnWidths.length; x++) {
                if (x < 5)
                    columnWidths[x] = 1f;
                else if (jCheckBox1.isSelected() && x == 5)
                    columnWidths[x] = 2f;
                else if (jCheckBox2.isSelected() && jCheckBox3.isSelected() && x == 7)
                    columnWidths[x] = 2f;
                else if (!jCheckBox2.isSelected() && jCheckBox3.isSelected() && x == 6)
                    columnWidths[x] = 2f;
                else if (jCheckBox4.isSelected() && x == columnWidths.length - 2)
                    columnWidths[x] = 2f;
                else if (jCheckBox5.isSelected() && x == columnWidths.length - 1)
                    columnWidths[x] = 2f;
                else
                    columnWidths[x] = 1f;
            }

            //create PDF table with the given widths
            PdfPTable table = new PdfPTable(columnWidths);
            // set table width a percentage of the page width
            table.setWidthPercentage(90f);
            Reporter re;
            re = new Reporter();
            //insert column headings
            re.insertCell(table, "ID-Tag", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-Tatto", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-RFID", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-Brand", Element.ALIGN_CENTER, 1, bfBold12);
            re.insertCell(table, "ID-Other", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox1.isSelected())
                re.insertCell(table, "Age", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox2.isSelected())
                re.insertCell(table, "Scrotal", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox3.isSelected())
                re.insertCell(table, "Motility", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox6.isSelected())
                re.insertCell(table, "Normal", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox7.isSelected())
                re.insertCell(table, "M2", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox8.isSelected())
                re.insertCell(table, "M3", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox9.isSelected())
                re.insertCell(table, "M4", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox10.isSelected())
                re.insertCell(table, "M5", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox11.isSelected())
                re.insertCell(table, "M6", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox12.isSelected())
                re.insertCell(table, "M7", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox13.isSelected())
                re.insertCell(table, "M8", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox4.isSelected())
                re.insertCell(table, "Comments", Element.ALIGN_CENTER, 1, bfBold12);
            if (jCheckBox5.isSelected())
                re.insertCell(table, "Classification", Element.ALIGN_CENTER, 1, bfBold12);

            table.setHeaderRows(1);

            //insert an empty row

            //create section heading by cell merging

            //just some random data to fill 
            for (int x = 1; x < number_of_rows1; x++) {

                re.insertCell(table, bull1[x][7], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][8], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][6], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][2], Element.ALIGN_CENTER, 1, bf12);
                re.insertCell(table, bull1[x][9], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox1.isSelected())
                    re.insertCell(table, bull1[x][0], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox2.isSelected())
                    re.insertCell(table, bull1[x][70], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox3.isSelected())
                    re.insertCell(table, bull1[x][61], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox6.isSelected())
                    re.insertCell(table, bull1[x][43], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox7.isSelected())
                    re.insertCell(table, bull1[x][45], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox8.isSelected())
                    re.insertCell(table, bull1[x][47], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox9.isSelected())
                    re.insertCell(table, bull1[x][49], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox10.isSelected())
                    re.insertCell(table, bull1[x][51], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox11.isSelected())
                    re.insertCell(table, bull1[x][53], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox12.isSelected())
                    re.insertCell(table, bull1[x][55], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox13.isSelected())
                    re.insertCell(table, bull1[x][57], Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox4.isSelected())
                    re.insertCell(table, "", Element.ALIGN_CENTER, 1, bf12);
                if (jCheckBox5.isSelected())
                    re.insertCell(table, bull1[x][35], Element.ALIGN_CENTER, 1, bf12);
            }
            doc.add(table);

        } catch (DocumentException dex) {
            dex.printStackTrace();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Reporter.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            if (doc != null) {
                //close the document
                doc.close();
            }
            if (docWriter != null) {
                //close the writer
                docWriter.close();
            }
        }
        // TODO add your handling code here:
    } //GEN-LAST:event_jButton1ActionPerformed
}

From source file:client.welcome0.java

private void genRepButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genRepButton1ActionPerformed

    Document doc = new Document();
    PdfWriter docWriter = null;//from   ww  w. j a va 2  s .com
    int repID = ThreadLocalRandom.current().nextInt(10000, 99999 + 1);
    DecimalFormat df = new DecimalFormat("0.00");
    //Date d = Calendar.getInstance().getTime();
    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    Date date = new Date();
    String fileName = null;
    job_title = JobTitleChoice.getSelectedItem();
    try {

        //special font sizes
        com.itextpdf.text.Font bfBold12 = new com.itextpdf.text.Font(
                com.itextpdf.text.Font.FontFamily.TIMES_ROMAN, 12, com.itextpdf.text.Font.BOLD,
                new BaseColor(0, 0, 0));
        com.itextpdf.text.Font bf12 = new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.TIMES_ROMAN,
                12);

        //file path
        String dt = dateFormat.format(date);
        sFileName = "Report No- " + repID + " Workers Report- " + dt + " Job Title " + job_title + " .pdf";
        String path = "src/WorkerReports/" + sFileName;
        docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path));

        DateFormat dateFormat3 = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        String d = dateFormat3.format(Calendar.getInstance().getTime());

        //document header attributes
        doc.addCreationDate();
        doc.setPageSize(PageSize.LETTER);

        //open document
        doc.open();
        //create a paragraph

        com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance("src/Images/logo for pdf.png");
        com.itextpdf.text.Font font1 = new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.HELVETICA,
                25, com.itextpdf.text.Font.BOLD);
        Paragraph paragraph = new Paragraph();
        Paragraph paragraph2 = new Paragraph("This report was generated by " + loginGUI.username + " at " + d
                + "\nYou can see Yatzig's workers by the job title you chose");
        image.setAlignment(com.itextpdf.text.Image.RIGHT);
        doc.add(image);

        //specify column widths
        float[] columnWidths = { 3f, 3f, 3f, 4f, 3f, 3f, 5f, 3f };
        //create PDF table with the given widths
        PdfPTable table = new PdfPTable(columnWidths);
        // set table width a percentage of the page width
        table.setWidthPercentage(100f);

        //insert column headings
        insertCell(table, "Worker ID", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "First Name", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Last Name", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Phone", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Address", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Birth Date", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Email", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Job Title", Element.ALIGN_CENTER, 1, bfBold12);
        table.setHeaderRows(1);

        //insert an empty row
        /* insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);*/
        //create section heading by cell merging
        /* insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);*/
        /*double orderTotal, total = 0;*/

        String add1, add2, add3, add4, add5, add6, add7, add8;

        if (job_title.equals("All"))
            try {

                String sql = "select worker_id,first_name,last_name,worker_phone,worker_add,birth_date,email,job_title from workers order by job_title ";
                pst = conn.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    add1 = rs.getString("worker_id");
                    add2 = rs.getString("first_name");
                    add3 = rs.getString("last_name");
                    add4 = rs.getString("worker_phone");
                    add5 = rs.getString("worker_add");
                    add6 = dateFormat.format(rs.getDate("birth_date"));
                    add7 = rs.getString("email");
                    add8 = rs.getString("job_title");
                    insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add6, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add7, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add8, Element.ALIGN_CENTER, 1, bf12);

                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }

        else
            try {

                String sql = "select worker_id,first_name,last_name,worker_phone,worker_add,birth_date,email,job_title from workers where job_title='"
                        + job_title + "' ";
                pst = conn.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    add1 = rs.getString("worker_id");
                    add2 = rs.getString("first_name");
                    add3 = rs.getString("last_name");
                    add4 = rs.getString("worker_phone");
                    add5 = rs.getString("worker_add");
                    add6 = dateFormat.format(rs.getDate("birth_date"));
                    add7 = rs.getString("email");
                    add8 = rs.getString("job_title");
                    insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add6, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add7, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add8, Element.ALIGN_CENTER, 1, bf12);
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }

        //add the PDF table to the paragraph 
        paragraph2.add(table);

        // add the paragraph to the document
        doc.add(new Paragraph("\nWorkers Report " + dt + "\n", font1));
        doc.add(paragraph2);
    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (doc != null) {
            //close the document
            doc.close();
            JOptionPane.showMessageDialog(null, "Report No " + repID + " Generated!");
        }
        if (docWriter != null) {
            //close the writer
            docWriter.close();
        }
    }
    saveToDB(job_title, date, repID);

}

From source file:client.welcome1.java

private void genrateItemRepButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_genrateItemRepButtonActionPerformed
    Document doc = new Document();
    PdfWriter docWriter = null;/*from   ww w  . j  a v  a 2s.  com*/
    int repID = ThreadLocalRandom.current().nextInt(10000, 99999 + 1);
    DecimalFormat df = new DecimalFormat("0.00");
    //Date d = Calendar.getInstance().getTime();
    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    Date date = new Date();

    try {

        //special font sizes
        com.itextpdf.text.Font bfBold12 = new com.itextpdf.text.Font(FontFamily.TIMES_ROMAN, 12,
                com.itextpdf.text.Font.BOLD, new BaseColor(0, 0, 0));
        com.itextpdf.text.Font bf12 = new com.itextpdf.text.Font(FontFamily.TIMES_ROMAN, 12);

        //file path
        String dt = dateFormat.format(date);
        sFileName = "Report No- " + repID + " Items Report- " + dt + " Status " + itemRepChoice + " .pdf";
        String path = "src/ItemsReports/" + sFileName;
        docWriter = PdfWriter.getInstance(doc, new FileOutputStream(path));

        DateFormat dateFormat3 = new SimpleDateFormat("dd/MM/yyyy HH:mm");
        String d = dateFormat3.format(Calendar.getInstance().getTime());

        //document header attributes
        doc.addCreationDate();
        doc.setPageSize(PageSize.LETTER);

        //open document
        doc.open();

        //create a paragraph
        Image image = Image.getInstance("src/Images/logo for pdf.png");
        Font font1 = new Font(Font.FontFamily.HELVETICA, 25, Font.BOLD);
        Paragraph paragraph = new Paragraph();
        Paragraph paragraph2 = new Paragraph("This report was generated by " + loginGUI.username + " at " + d
                + "\nYou can see " + itemRepChoice + " Items");
        image.setAlignment(Image.RIGHT);
        doc.add(image);

        //specify column widths
        float[] columnWidths = { 2f, 2f, 2f, 3f, 2f, 2f, 2f };
        //create PDF table with the given widths
        PdfPTable table = new PdfPTable(columnWidths);
        // set table width a percentage of the page width
        table.setWidthPercentage(100f);

        //insert column headings
        insertCell(table, "Item ID", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Item Name", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Quantity", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Min Quantity Level", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Warehouse", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Row", Element.ALIGN_CENTER, 1, bfBold12);
        insertCell(table, "Shelf", Element.ALIGN_CENTER, 1, bfBold12);
        table.setHeaderRows(1);

        //insert an empty row
        /* insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);*/
        //create section heading by cell merging
        /* insertCell(table, "New York Orders ...", Element.ALIGN_LEFT, 4, bfBold12);*/
        /*double orderTotal, total = 0;*/

        String add1, add2, add3, add4, add5, add6, add7;

        if (itemRepChoice.equals("All")) {
            try {

                String sql = "select item_id,item_name,quantity,min_quantity_level,warehouse,row,shelf from items";
                pst = conn.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    add1 = rs.getString("item_id");
                    add2 = rs.getString("item_name");
                    add3 = rs.getString("quantity");
                    add4 = rs.getString("min_quantity_level");
                    add5 = rs.getString("warehouse");
                    add6 = rs.getString("row");
                    add7 = rs.getString("shelf");
                    insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add6, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add7, Element.ALIGN_CENTER, 1, bf12);
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        } else if (itemRepChoice.equals("Warehouse")) {
            String wh = wareHouschoice.getSelectedItem();
            try {

                String sql = "select item_id,item_name,quantity,min_quantity_level,warehouse,row,shelf from items where warehouse='"
                        + wh + "'";
                pst = conn.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    add1 = rs.getString("item_id");
                    add2 = rs.getString("item_name");
                    add3 = rs.getString("quantity");
                    add4 = rs.getString("min_quantity_level");
                    add5 = rs.getString("warehouse");
                    add6 = rs.getString("row");
                    add7 = rs.getString("shelf");
                    insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add6, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add7, Element.ALIGN_CENTER, 1, bf12);
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        } else if (itemRepChoice.equals("Min Level")) {
            String wh = wareHouschoice.getSelectedItem();
            try {

                String sql = "select item_id,item_name,quantity,min_quantity_level,warehouse,row,shelf from items where min_quantity_level>=quantity";
                pst = conn.prepareStatement(sql);
                rs = pst.executeQuery();
                while (rs.next()) {
                    add1 = rs.getString("item_id");
                    add2 = rs.getString("item_name");
                    add3 = rs.getString("quantity");
                    add4 = rs.getString("min_quantity_level");
                    add5 = rs.getString("warehouse");
                    add6 = rs.getString("row");
                    add7 = rs.getString("shelf");
                    insertCell(table, add1, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add2, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add3, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add4, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add5, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add6, Element.ALIGN_CENTER, 1, bf12);
                    insertCell(table, add7, Element.ALIGN_CENTER, 1, bf12);
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e);

            }
        }

        //add the PDF table to the paragraph 
        paragraph2.add(table);

        // add the paragraph to the document
        doc.add(new Paragraph("\nItems Status Report " + dt + "\n", font1));
        doc.add(paragraph2);
    } catch (DocumentException dex) {
        dex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (doc != null) {
            //close the document
            doc.close();
            JOptionPane.showMessageDialog(null, "Report No " + repID + " Generated!");
        }
        if (docWriter != null) {
            //close the writer
            docWriter.close();
        }
    }
    saveToDB(itemRepChoice, date, repID);
}