Example usage for com.itextpdf.text Phrase Phrase

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

Introduction

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

Prototype

public Phrase(final float leading, final String string) 

Source Link

Document

Constructs a Phrase with a certain leading and a certain String.

Usage

From source file:be.thomasmore.controller.PdfController.java

public void createPdfStudent() {
    Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext()
            .getRequestParameterMap();//from  ww  w. j a  v a 2s  . com
    String StudentId = params.get("studentId");
    int id = Integer.parseInt(StudentId);
    Document document = new Document();
    Student student = service.getStudent(id);
    List<Score> scores = student.getScoreList();
    Klas klas = student.getKlasId();

    HttpServletResponse res = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext()
            .getResponse();
    res.setHeader("Content-Disposition",
            "attachement; filename=" + student.getNaam() + student.getVoornaam() + "-resultaten.pdf");
    res.setContentType("application/pdf");

    try {
        PdfWriter.getInstance(document, res.getOutputStream());

        document.open();

        Font font = FontFactory.getFont("Calibri");

        PdfPTable table = new PdfPTable(3); // 3 columns.

        PdfPCell cell1 = new PdfPCell(new Paragraph("Vak", font));
        PdfPCell cell2 = new PdfPCell(new Paragraph("Test", font));
        PdfPCell cell3 = new PdfPCell(new Paragraph("Score", font));

        table.addCell(cell1);
        table.addCell(cell2);
        table.addCell(cell3);

        for (Score score : scores) {
            Test test = score.getTestId();
            PdfPCell cellVak = new PdfPCell(new Paragraph(test.getVakId().getNaam(), font));
            PdfPCell cellTest = new PdfPCell(new Paragraph(test.getBeschrijving(), font));
            PdfPCell cellScore = new PdfPCell(new Paragraph(score.getScore().toString()));

            table.addCell(cellVak);
            table.addCell(cellTest);
            table.addCell(cellScore);
        }

        document.add(new Phrase("Student: ", font));
        document.add(new Phrase((student.getNaam() + " " + student.getVoornaam()), font));
        document.add(new Phrase("Klas: ", font));
        document.add(new Phrase(klas.getNummer(), font));
        document.add(table);

        document.close();
    } catch (Exception e) {

    }

}

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();/*from w  ww  . ja  v  a 2 s . com*/
    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();//from  w  ww .  ja  va  2  s .c  o  m
    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();/*w  w  w. jav a  2s.  co  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:bouttime.report.award.AwardInventoryReport.java

License:Open Source License

private static PdfPTable getDataTable(int[] awardCounts, int maxAward) throws DocumentException {
    Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);

    // create and add the table
    PdfPTable datatable = new PdfPTable(2);
    int colWidths[] = { 90, 10 }; // percentage
    datatable.setWidths(colWidths);//  ww w.  j av a 2 s  .  c o m
    datatable.setWidthPercentage(100);
    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

    for (int i = 0; i < maxAward; i++) {
        if ((i % 2) == 0) {
            datatable.getDefaultCell().setGrayFill(0.9f);
        } else {
            datatable.getDefaultCell().setGrayFill(1);
        }

        String place = null;
        switch (i) {
        case 0:
            place = "1st Place";
            break;
        case 1:
            place = "2nd Place";
            break;
        case 2:
            place = "3rd Place";
            break;
        case 3:
            place = "4th Place";
            break;
        case 4:
            place = "5th Place";
            break;
        case 5:
            place = "6th Place";
            break;
        case 6:
            place = "7th Place";
            break;
        default:
            logger.warn("unexpected place value : " + i);
            place = "???";
            break;
        }

        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        datatable.addCell(new Phrase(place, detailFont));

        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(new Phrase(Integer.toString(awardCounts[i]), detailFont));
    }

    datatable.setSpacingBefore(5f);
    datatable.setSpacingAfter(15f);

    return datatable;
}

From source file:bouttime.report.award.AwardReport.java

License:Open Source License

/**
 * Generate an award report./*from  w w  w .j a v a 2 s .co m*/
 * @param dao Dao object to use to retrieve data.
 * @param session Session to generate the report for.
 * @param group Group to generate report for.  This takes precedence, so
 * if not null, then the report will be generated for this group.
 * @return True if the report was generated.
 */
private static boolean doReport(Dao dao, String session, Group group) {
    if (!dao.isOpen()) {
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Award Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        PdfPCell headerCell = new PdfPCell();
        headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        headerCell.setPadding(3);
        headerCell.setBorderWidth(2);

        List<Group> groups;
        if (group != null) {
            groups = new ArrayList<Group>();
            groups.add(group);
        } else if (session != null) {
            groups = dao.getGroupsBySession(session);
        } else {
            groups = dao.getAllGroups();
        }

        for (Group g : groups) {

            // create and add the table
            PdfPTable datatable = new PdfPTable(4);
            int colWidths[] = { 30, 30, 30, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            // The header has the group name
            headerCell.setPhrase(new Phrase(g.toString(), headerFont));
            headerCell.setColspan(4);
            datatable.addCell(headerCell);

            datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            List<Wrestler> wList = getSortedAwardList(g);

            int i = 0;
            for (Wrestler w : wList) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getTeamName(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                Integer place = w.getPlace();
                String placeStr = (place == null) ? "" : place.toString();
                datatable.addCell(new Phrase(placeStr, detailFont));
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.boutsequence.BoutSequenceReport.java

License:Open Source License

private static PdfPTable addBoutSequences(List<Wrestler> wList, String session) throws DocumentException {
    // create and add the table
    Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
    Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);
    PdfPCell headerCell = new PdfPCell();
    headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    headerCell.setPadding(3);/*from  w  w  w  .j  a  v a2 s .c  o m*/
    headerCell.setBorderWidth(2);
    PdfPTable datatable = new PdfPTable(3);
    int colWidths[] = { 5, 25, 70 }; // percentage
    datatable.setWidths(colWidths);
    datatable.setWidthPercentage(100);
    datatable.getDefaultCell().setPadding(3);
    datatable.getDefaultCell().setBorderWidth(2);
    datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

    headerCell.setPhrase(new Phrase("Mat", headerFont));
    datatable.addCell(headerCell);

    headerCell.setPhrase(new Phrase("Name", headerFont));
    datatable.addCell(headerCell);

    headerCell.setPhrase(new Phrase("Bout Sequence", headerFont));
    datatable.addCell(headerCell);

    datatable.setHeaderRows(1); // this is the end of the table header

    datatable.getDefaultCell().setBorderWidth(1);
    datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

    Collections.sort(wList, new WrestlerMatNameSort());

    int i = 0;
    for (Wrestler w : wList) {
        if (w.getGroup() == null) {
            logger.debug(String.format("Wrestler [%s] is not in a group, skipping.", w.getShortName()));
            continue;
        }

        if ((session != null) && !session.equalsIgnoreCase(w.getGroup().getSession())) {
            logger.debug(String.format("Wrestler [%s] is in a group but not in session %s, skipping.",
                    w.getShortName(), session));
            continue;
        }

        if ((i++ % 2) == 0) {
            datatable.getDefaultCell().setGrayFill(0.9f);
        } else {
            datatable.getDefaultCell().setGrayFill(1);
        }

        List<Bout> bList = BoutSequence.calculate(w);
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
        datatable.addCell(new Phrase(w.getGroup().getMat(), detailFont));
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        datatable.addCell(new Phrase(String.format("%s %s", w.getFirstName(), w.getLastName()), detailFont));
        datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
        String boutSequenceString = getBoutSequenceString(bList);
        datatable.addCell(new Phrase(boutSequenceString, detailFont));
    }

    datatable.setSpacingBefore(5f);
    datatable.setSpacingAfter(15f);
    return (i > 0 ? datatable : null);
}

From source file:bouttime.report.team.TeamReport.java

License:Open Source License

/**
 * Generate a detail report of the teams in the tournament.
 * This report includes the teams and all of the wrestlers on the team.
 * @param dao Dao object to use to retrieve data.
 * @return True if the report was generated.
 *///from   w w  w. ja  v  a 2 s  .  com
public static boolean doDetail(Dao dao) {
    if (!dao.isOpen()) {
        return false;
    }

    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        Paragraph p1 = new Paragraph(new Paragraph(
                String.format("%s    %s %s, %s", dao.getName(), dao.getMonth(), dao.getDay(), dao.getYear()),
                FontFactory.getFont(FontFactory.HELVETICA, 10)));
        document.add(p1);

        Paragraph p2 = new Paragraph(
                new Paragraph("Team Detail Report", FontFactory.getFont(FontFactory.HELVETICA, 14)));
        p2.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(p2);

        Font headerFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);
        PdfPCell headerCell = new PdfPCell();
        headerCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        headerCell.setPadding(3);
        headerCell.setBorderWidth(2);

        List<String> teams = dao.getTeams();

        for (String t : teams) {

            List<Wrestler> wrestlers = dao.getWrestlersByTeam(t);
            int count = wrestlers.size();

            // create and add the table
            PdfPTable datatable = new PdfPTable(5);
            int colWidths[] = { 30, 30, 20, 10, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            // The header has the team name and the number of entries
            headerCell.setPhrase(new Phrase(t, headerFont));
            headerCell.setColspan(3);
            datatable.addCell(headerCell);

            headerCell.setPhrase(new Phrase(String.format("Entries : %d", count), headerFont));
            headerCell.setColspan(2);
            datatable.addCell(headerCell);

            datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            int i = 0;
            for (Wrestler w : wrestlers) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getClassification(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                datatable.addCell(new Phrase(w.getAgeDivision(), detailFont));
                datatable.addCell(new Phrase(w.getWeightClass(), detailFont));
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:bouttime.report.weighin.WeighInReport.java

License:Open Source License

/**
 * Generate a report of the entries in the tournament for weigh-in.
 * @param sections List of sections for the report.  Each section will start
 *     on a new page.//from w  w  w .j  a v  a2  s  .c o  m
 * @param headerString String to be used for the header of each page of the report.
 * @return True if the report was generated.
 */
public static boolean doReport(List<List<Wrestler>> sections, String headerString) {
    // step 1: creation of a document-object
    Document document = new Document();

    try {

        // step 2: creation of the writer
        FileOutputStream fos = createOutputFile();
        if (fos == null) {
            return false;
        }
        PdfWriter.getInstance(document, fos);

        // step 3: we open the document
        document.open();

        // step 4: create and add content

        // create and add the header
        if (headerString != null) {
            Paragraph p1 = new Paragraph(
                    new Paragraph(headerString, FontFactory.getFont(FontFactory.HELVETICA, 10)));
            document.add(p1);
        }

        Font detailFont = new Font(Font.FontFamily.TIMES_ROMAN, 10);

        for (List<Wrestler> wrestlers : sections) {
            // create and add the table
            PdfPTable datatable = new PdfPTable(7);
            int colWidths[] = { 20, 20, 20, 10, 10, 10, 10 }; // percentage
            datatable.setWidths(colWidths);
            datatable.setWidthPercentage(100);
            datatable.getDefaultCell().setPadding(3);
            datatable.getDefaultCell().setBorderWidth(2);
            datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);

            //datatable.setHeaderRows(1); // this is the end of the table header

            datatable.getDefaultCell().setBorderWidth(1);
            datatable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);

            int i = 0;
            for (Wrestler w : wrestlers) {
                if ((i++ % 2) == 0) {
                    datatable.getDefaultCell().setGrayFill(0.9f);
                } else {
                    datatable.getDefaultCell().setGrayFill(1);
                }

                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT);
                datatable.addCell(new Phrase(w.getLastName(), detailFont));
                datatable.addCell(new Phrase(w.getFirstName(), detailFont));
                datatable.addCell(new Phrase(w.getTeamName(), detailFont));
                datatable.addCell(new Phrase(w.getClassification(), detailFont));
                datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
                datatable.addCell(new Phrase(w.getAgeDivision(), detailFont));
                datatable.addCell(new Phrase(w.getWeightClass(), detailFont));
                datatable.addCell(new Phrase()); // actual weight
            }

            datatable.setSpacingBefore(5f);
            datatable.setSpacingAfter(15f);
            document.add(datatable);
            document.newPage();
        }

    } catch (DocumentException de) {
        logger.error("Document Exception", de);
        return false;
    }

    // step 5: we close the document
    document.close();

    return true;
}

From source file:BUS.ExportPDF.java

public boolean ExportTKDT(ArrayList<String[]> al, String year)
        throws BadElementException, IOException, DocumentException {

    // To i tng ti liu
    Document document = new Document(PageSize.A4, 50, 50, 50, 50);

    File fontFile = new File("src\\Helper\\arialuni.ttf");
    BaseFont unicode = BaseFont.createFont(fontFile.getAbsolutePath(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    Font f = new Font(unicode, 12);

    try {/*from   ww w .  j a  v  a2  s  .  c o m*/
        // To i tng PdfWriter
        Date d = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss");

        String s = "ThongKeDoanhThu_" + ft.format(d) + ".pdf";
        PdfWriter.getInstance(document, new FileOutputStream(s));

        // M file  thc hin ghi
        document.open();

        Paragraph title1 = new Paragraph("CO's BAKERY", FontFactory.getFont(FontFactory.HELVETICA, 18,
                Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17)));
        document.add(title1);

        //Logo Group
        Image image1 = Image.getInstance("src\\Library\\cao.png");
        document.add(new Paragraph());
        document.add(image1);

        //Nam can bao cao
        Paragraph title2 = new Paragraph(year, FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLDITALIC,
                new CMYKColor(0, 255, 255, 17)));
        document.add(title2);

        //Chart
        Image image = Image.getInstance("src\\Library\\barChart3D.jpeg");
        image.scaleToFit(500, 400);
        document.add(new Paragraph());
        document.add(image);

        //Data
        PdfPTable t = new PdfPTable(4);
        t.setSpacingBefore(25);
        t.setSpacingAfter(25);

        PdfPCell c1 = new PdfPCell(new Phrase("Thng", f));
        t.addCell(c1);
        PdfPCell c2 = new PdfPCell(new Phrase("Doanh thu", f));
        t.addCell(c2);
        PdfPCell c3 = new PdfPCell(new Phrase("Ti?n n", f));
        t.addCell(c3);
        PdfPCell c4 = new PdfPCell(new Phrase("Li", f));
        t.addCell(c4);

        for (int i = 0; i < al.size(); i++) {
            Object ob = i + 1;
            t.addCell(ob.toString());
            t.addCell(al.get(i)[0]);
            t.addCell(al.get(i)[1]);
            t.addCell(al.get(i)[2]);
        }
        document.add(t);

        // ?ng File
        document.close();
        System.out.println("Write file succes!");
    } catch (FileNotFoundException | DocumentException e) {
        return false;
    }
    return true;
}