Example usage for com.itextpdf.text.pdf PdfWriter getInstance

List of usage examples for com.itextpdf.text.pdf PdfWriter getInstance

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfWriter getInstance.

Prototype


public static PdfWriter getInstance(final Document document, final OutputStream os) throws DocumentException 

Source Link

Document

Use this method to get an instance of the PdfWriter.

Usage

From source file:bean.ReportingBean.java

public void createPdf(String filename) throws DocumentException, IOException {
    //String escaped = HtmlUtil.escape(editorVal);
    //String escapedCss = HtmlUtil.escapeCSS(editorVal);

    //StringReader stringReader = new StringReader(editorVal);
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(filename));
    //PdfWriter.getInstance(document, new FileOutputStream(RESULT));
    //PdfWriter.getInstance(document, new FileOutputStream("JSF-PDF.pdf"));
    document.open();//w  w w. j  ava  2 s . c om
    document.add(new Paragraph("insert letter head"));
    document.add(new Paragraph("insert title"));
    document.add(new Paragraph("date:"));
    document.add(new Paragraph("date encoded:"));
    document.add(new Paragraph("date from" + "-" + "date to"));
    document.add(new Paragraph("time from" + "-" + "time to"));
    //document.add(new Paragraph("escaped" + "\n" + editorVal));
    //document.add(new Paragraph("escaped()" + "\n" + escaped));
    //document.add(new Paragraph("escapedCss()" + "\n" + escapedCss));
    document.close();
}

From source file:Beans.ArchAssistantBean.java

public void GenerarReporteQAW(Proyecto pro) throws FileNotFoundException, DocumentException, IOException {

    Rationaleqaw ratq, ratq4;/* w w w  .j a va  2 s  .  c  om*/
    String paso = pro.getProAvance();
    Paragraph parrafo;
    int anexo = 1;
    GuardarArchivo arch = new GuardarArchivo();
    List<File> archivos = null;
    FileOutputStream archivo = new FileOutputStream(System.getProperty("user.home") + File.separator
            + "Downloads" + File.separator + "InformeQAW" + pro.getProNombre() + ".pdf");
    String razonamiento;
    Document documento = new Document();
    PdfWriter.getInstance(documento, archivo);
    List<Atributocalidad> listaAtributos = ListarAtr();
    List<Atributocalidad> atrEscogidos;

    documento.open();
    documento.addHeader("ArchAssistant", "ArchAssistant");
    //documento.setMargins(2, 2, 4, 4);
    parrafo = new Paragraph("INFORME QAW ", chapterFont);
    parrafo.setAlignment(1);
    documento.add(parrafo);
    parrafo = new Paragraph("Proyecto " + pro.getProNombre(), chapterFont);
    parrafo.setAlignment(1);
    documento.add(parrafo);
    parrafo = new Paragraph("ArchAssistant\n\n", blueFontArchAssistant);
    parrafo.setAlignment(1);
    documento.add(parrafo);
    documento.add(new Paragraph("\n\n" + pro.getProDescripcion(), paragraphFont));
    parrafo = new Paragraph("Autor: " + pro.getTblUsuarioidUsuario().getUsuNombre(), blueFont);
    parrafo.setAlignment(2);
    documento.add(parrafo);
    for (int i = 1; i <= 8; i++) {
        ratq = obtenerRationaleQAW(pro.getProID(), "qaw" + String.valueOf(i));
        ratq4 = obtenerRationaleQAW(pro.getProID(), "qaw4");

        documento.add(new Paragraph("QAW paso " + i + "\n", categoryFont));
        if (ratq != null) {
            archivos = arch.listarArchivos(ratq.getRatQawArchivo());
            razonamiento = ratq.getRatQawDescripcion();
            if (razonamiento != null) {
                if (ratq.getRatQawPaso().equals("qaw4")) {
                    ratq4 = ratq;
                    atrEscogidos = ObtenerAtributosEscogidos(ratq);
                    documento.add(new Paragraph("Atributos de Calidad:\n", subcategoryFont));
                    for (Atributocalidad atr : listaAtributos) {
                        for (Atributocalidad atrEsc : atrEscogidos) {
                            if (atr.getAcID() == atrEsc.getAcID()) {
                                documento.add(new Paragraph(atr.getAcNombre(), blueFont));
                            }
                        }
                    }
                    int indiceAtribs = 0;
                    if (razonamiento != null || razonamiento != "") {
                        indiceAtribs = razonamiento.indexOf("~|~|") + 4;
                    }
                    documento.add(new Paragraph("Justificacin de las decisiones", smallBold));
                    documento.add(new Paragraph(razonamiento.substring(indiceAtribs) + "\n", paragraphFont));
                } else {
                    if (ratq.getRatQawPaso().equals("qaw5")) {
                        documento.add(new Paragraph("Escenarios generados en la lluvia de ideas:\n",
                                subcategoryFont));
                        atrEscogidos = ObtenerAtributosEscogidos(ratq4);
                        for (Atributocalidad atr : atrEscogidos) {
                            documento.add(new Paragraph("\n" + atr.getAcNombre() + "\n\n", smallBold));
                            PdfPTable tabla = new PdfPTable(4);

                            tabla.addCell("Nombre");
                            tabla.addCell("Estimulo");
                            tabla.addCell("Ambiente");
                            tabla.addCell("Respuesta");

                            List<Escenario> listaEsc = ListEscenarios(pro);

                            for (Escenario esce : listaEsc) {
                                if (esce.getTblAtributoCalidadacID().getAcID() == atr.getAcID()) {
                                    tabla.addCell(esce.getEscNombre());
                                    tabla.addCell(esce.getEscEstimulo());
                                    tabla.addCell(esce.getEscAmbiente());
                                    tabla.addCell(esce.getEscRespuesta());
                                }
                            }
                            documento.add(tabla);
                        }
                    }
                    if (ratq.getRatQawPaso().equals("qaw6")) {
                        documento.add(new Paragraph("Escenarios consolodados:\n", subcategoryFont));
                        atrEscogidos = ObtenerAtributosEscogidos(ratq4);
                        for (Atributocalidad atr : atrEscogidos) {
                            documento.add(new Paragraph("\n" + atr.getAcNombre() + "\n\n", smallBold));
                            PdfPTable tabla = new PdfPTable(4);
                            tabla.addCell("Nombre");
                            tabla.addCell("Estimulo");
                            tabla.addCell("Ambiente");
                            tabla.addCell("Respuesta");

                            List<Escenario> listaEsc = ListEscenarios(pro);

                            for (Escenario esce : listaEsc) {
                                if (esce.getTblAtributoCalidadacID().getAcID() == atr.getAcID()) {
                                    tabla.addCell(esce.getEscNombre());
                                    tabla.addCell(esce.getEscEstimulo());
                                    tabla.addCell(esce.getEscAmbiente());
                                    tabla.addCell(esce.getEscRespuesta());
                                }
                            }
                            documento.add(tabla);
                        }
                    }
                    if (ratq.getRatQawPaso().equals("qaw7")) {
                        documento.add(new Paragraph("Escenarios priorizados:\n\n", subcategoryFont));

                        PdfPTable tabla = new PdfPTable(6);
                        tabla.addCell("Nombre");
                        tabla.addCell("Estimulo");
                        tabla.addCell("Ambiente");
                        tabla.addCell("Respuesta");
                        tabla.addCell("Atributo");
                        tabla.addCell("Voto");

                        List<Escenario> listaEsc = ListEscenarios(pro);

                        Collections.sort(listaEsc, new Comparator() {
                            @Override
                            public int compare(Object o1, Object o2) {
                                Escenario esc1, esc2;
                                esc1 = (Escenario) o1;
                                esc2 = (Escenario) o2;
                                return new Integer(esc1.getEscPrioridad())
                                        .compareTo(new Integer(esc2.getEscPrioridad()));

                            }
                        });

                        for (Escenario esce : listaEsc) {
                            tabla.addCell(esce.getEscNombre());
                            tabla.addCell(esce.getEscEstimulo());
                            tabla.addCell(esce.getEscAmbiente());
                            tabla.addCell(esce.getEscRespuesta());
                            tabla.addCell(esce.getTblAtributoCalidadacID().getAcNombre());
                            tabla.addCell(String.valueOf(esce.getEscPrioridad()));

                        }
                        documento.add(tabla);
                    }
                    if (ratq.getRatQawPaso().equals("qaw8")) {
                        documento.add(new Paragraph("Escenarios Refinados:\n\n", subcategoryFont));

                        PdfPTable tabla = new PdfPTable(9);
                        tabla.addCell("Nombre");
                        tabla.addCell("Estimulo");
                        tabla.addCell("Fuente");
                        tabla.addCell("Ambiente");
                        tabla.addCell("Artefacto");
                        tabla.addCell("Respuesta");
                        tabla.addCell("Medida");
                        tabla.addCell("Atributo");
                        tabla.addCell("Prioridad");

                        List<Escenario> listaEsc = ListEscenarios(pro);

                        Collections.sort(listaEsc, new Comparator() {
                            @Override
                            public int compare(Object o1, Object o2) {
                                Escenario esc1, esc2;
                                esc1 = (Escenario) o1;
                                esc2 = (Escenario) o2;
                                return new Integer(esc1.getEscPrioridad())
                                        .compareTo(new Integer(esc2.getEscPrioridad()));

                            }
                        });

                        for (Escenario esce : listaEsc) {
                            tabla.addCell(esce.getEscNombre());
                            tabla.addCell(esce.getEscEstimulo());
                            tabla.addCell(esce.getEscFuente());
                            tabla.addCell(esce.getEscAmbiente());
                            tabla.addCell(esce.getEscArtefacto());
                            tabla.addCell(esce.getEscRespuesta());
                            tabla.addCell(esce.getEscMedidaRespuesta());
                            tabla.addCell(esce.getTblAtributoCalidadacID().getAcNombre());
                            tabla.addCell(String.valueOf(esce.getEscPrioridad()));

                        }
                        documento.add(tabla);
                    }
                    documento.add(new Paragraph("Justificacin de las decisiones", smallBold));
                    documento.add(new Paragraph(razonamiento + "\n", paragraphFont));
                }
            }
            if (archivos != null) {
                documento.add(new Paragraph("Archivos anexos:\n", smallBold));
                for (File archi : archivos) {
                    documento.add(new Paragraph("Anexo" + anexo + ": " + archi.getName(), blueFont));
                    anexo++;
                }
            }
        } else {
            documento.add(new Paragraph("No se registr informacin para este paso\n\n", paragraphFont));
        }
    }
    documento.close();
    archivo.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();//from w ww. java  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, 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.ManagedBeanReportes.java

public void inventario() throws DocumentException, IOException {
    FacesContext facexcontext = FacesContext.getCurrentInstance();
    ValueExpression vex = facexcontext.getApplication().getExpressionFactory()
            .createValueExpression(facexcontext.getELContext(), "#{managedBeanLogin}", ManagedBeanLogin.class);
    ManagedBeanLogin beanLogin = (ManagedBeanLogin) vex.getValue(facexcontext.getELContext());

    FacesContext context = FacesContext.getCurrentInstance();

    Document document = new Document(PageSize.A4, 25, 25, 75, 25);//int marginLeft,   int marginRight,   int marginTop,   int marginBottom

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    writer.setPageEvent(new ManagedBeanReportes.Watermark(""));
    if (!document.isOpen()) {
        document.open();/*from  w w w.j  a  va 2  s . c o  m*/
    }

    try {

        ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
        //String imageUrl1 = extContext.getRealPath("//resources//images/logo0002.png");
        //Image welladigital = Image.getInstance(imageUrl1);
        //welladigital.setAbsolutePosition(377f, 760f);
        //welladigital.scalePercent(40);
        //document.add(welladigital);

        //crear tabla PARA NOMBRE DEL AO
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setTotalWidth(450f);
        // table.setTotalWidth(540f);
        table.setLockedWidth(true);
        float[] headerWidths = { 120, 20, 310 };
        table.setWidths(headerWidths);
        table.getDefaultCell();

        SimpleDateFormat formato = new SimpleDateFormat("EEEE dd MMMM YYYY");
        StringBuilder cadena = new StringBuilder(formato.format(fecha_inicio));

        Chunk underline = new Chunk("FECHA DE INVENTARIO:" + cadena.toString().toUpperCase(), bigFont12);
        underline.setUnderline(0.2f, -2f); //0.1 thick, -2 y-location
        PdfPCell table5 = new PdfPCell(new Paragraph(underline));
        table5.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
        table5.setColspan(3);
        table5.setBorder(Rectangle.NO_BORDER);
        table.addCell(table5);

        document.add(table);

        document.add(new Paragraph("\n", pequeFont));

        PdfPCell table2 = new PdfPCell();

        table2 = new PdfPCell(
                new Paragraph(beanLogin.getObjetoEmpleado().getTienda().getNombreTienda(), pequeFont));
        table2.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
        table2.setColspan(3);
        table2.setBorder(Rectangle.NO_BORDER);
        table = new PdfPTable(3);
        table.setWidthPercentage(100);
        table.setTotalWidth(450f);
        table.setLockedWidth(true);
        table.setWidths(headerWidths);
        table.getDefaultCell();
        table.addCell(table2);
        document.add(table);

        document.add(new Paragraph("\n", pequeFont));

        document.add(traerSubtabla(beanLogin.getObjetoEmpleado().getTienda()));
        formato = new SimpleDateFormat("yyyy-MM-dd");
        cadena = new StringBuilder(formato.format(fecha_inicio));

        //document.add(traerSubtabla02(cadena.toString()));
        document.add(new Paragraph("\n", pequeFont));
        ExternalContext ctx = FacesContext.getCurrentInstance().getExternalContext();
        String ctxPath = ((ServletContext) ctx.getContext()).getContextPath();
        document.close();
        formato = new SimpleDateFormat("dd_MM_yyyy");
        cadena = new StringBuilder(formato.format(fecha_inicio));
        String fileName = cadena.toString();

        writePDFToResponse(context.getExternalContext(), baos, fileName);
        context.responseComplete();

    } catch (Exception de) {
        de.printStackTrace();
    }
}

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 v  a 2s. co 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();//from   w w w  . j a  v  a 2 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:bemyguest.controller.ValidationResevation.java

@FXML
private void handleButtonValiderAction(ActionEvent event) throws FileNotFoundException, DocumentException {
    Resrevation e = tab_reservation.getSelectionModel().getSelectedItem();
    if (e == null) {

        Alert alert = new Alert(Alert.AlertType.WARNING);
        alert.setTitle("Warning Dialog");
        alert.setHeaderText(null);/*w w w .j ava 2s . c om*/
        alert.setContentText("selectionner un demande de  reservation a traiter svp!");

        alert.showAndWait();
        LoadData();
        setCellTable();
    }

    else {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
        alert.setTitle("Confiramtion");
        alert.setHeaderText(null);
        alert.setContentText("vous etes sur d'accepter cette demande de reservation");
        Optional<ButtonType> answer = alert.showAndWait();

        if (answer.get() == ButtonType.OK) {
            ResevationDAO dao = new ResevationDAO();
            if (dao.ajouter_Reservation(e)) {

                LoadData();
                setCellTable();

                alert.setTitle("Success Dialog");
                alert.setHeaderText(null);
                alert.setContentText("Demandes accepter avec success");

                alert.showAndWait();

                try {

                    Document d = new Document(PageSize.A4.rotate());
                    PdfWriter.getInstance(d, new FileOutputStream(e.getUser().getNom() + "Facture.pdf"));
                    d.open();

                    d.add(new Paragraph("BeMyGuest Facture :",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
                    d.add(new Paragraph(new Date().toString()));
                    d.add(new Paragraph(
                            "-------------------------------------------------------------------------------------------------------------"));
                    d.add(new Paragraph("             "));
                    d.add(new Paragraph("             "));
                    PdfPTable pdt = new PdfPTable(7);
                    PdfPCell cell = new PdfPCell(new Paragraph("Composant de facture"));
                    cell.setColspan(7);
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell.setBackgroundColor(BaseColor.RED);
                    pdt.addCell(cell);

                    pdt.addCell(new Paragraph("Nom:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Prenom:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Date Debut:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Date Fin:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("nbre chambre:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("nbre personne:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph("Prix:",
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getUserDemandant().getNom(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getUserDemandant().getPrenom(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getDateDebut().toString(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(e.getDateFin().toString(),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(e.getDateDebut().toString());

                    int nb = e.getPropriete().getNbrChambre();

                    float pr = e.getPropriete().getPrix();
                    int nbp = e.getPropriete().getNbrVoyageur();
                    pdt.addCell(new Paragraph(Integer.toString(nb),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(Integer.toString(nbp),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));
                    pdt.addCell(new Paragraph(Float.toString(pr),
                            FontFactory.getFont(FontFactory.TIMES_BOLD, 8, Font.BOLD, BaseColor.BLACK)));

                    pdt.addCell(Float.toString(pr));

                    d.add(pdt);
                    d.close();
                } catch (Exception b) {

                    JOptionPane.showMessageDialog(null, b);
                }
            } else {
                alert.setTitle("Error Dialog");
                alert.setHeaderText(null);
                alert.setContentText("Cette Propriete Reserver pendant cette date ");

                alert.showAndWait();

                LoadData();
                setCellTable();
            }
        }

        else {
            LoadData();
            setCellTable();
        }
    }

}

From source file:bencoding.pdf.ConvertersProxy.java

License:Open Source License

@Kroll.method
public TiBlob convertImageToPDF(TiBlob blob, @Kroll.argument(optional = true) Object resolution)
        throws Exception {
    TiBlob result = null;/*from  w  ww.  ja  v a 2s.c o  m*/
    Bitmap bitmap = null;
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    TiDrawableReference ref = TiDrawableReference.fromBlob(getActivity(), blob);
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, outputStream);
        document.open();
        bitmap = ref.getBitmap();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] bitmapdata = stream.toByteArray();
        Image image1 = Image.getInstance(bitmapdata);
        document.add(image1);
        document.close();
        byte[] bytes = outputStream.toByteArray();
        result = TiBlob.blobFromData(bytes);
        return result;

    } catch (FileNotFoundException e) {
        e.printStackTrace();
        Log.i(PdfModule.MODULE_FULL_NAME, e.toString());
    } catch (DocumentException e) {
        Log.i(PdfModule.MODULE_FULL_NAME, e.toString());
        e.printStackTrace();
    } finally {
        if (bitmap != null) {
            bitmap.recycle();
            bitmap = null;
        }
        outputStream = null;
        ref = null;
        document = null;
    }

    return result;
}

From source file:bestdeal.util.genererPdf.java

public static void main(String[] args) {
    // - Paramtres de connexion  la base de donnes
    Connection connection;/*w w w . j a  va 2  s  . com*/
    String[][] data = new String[][] { { " ", " ", " ", " ", " " }, { " ", " ", " ", " ", " " },
            { " ", " ", " ", " ", " " }, };

    try {
        String requete = "select c.nom,c.prenom,c.email,k.nom,k.prenom,k.telephone,k.adresse,k.email,d.id_deal,d.nom_deal,v.quantite,v.prix_unitaire from client c INNER JOIN voucher v on v.id_client=c.id_client INNER JOIN deal d on v.id_deal=d.id_deal INNER JOIN vendeur k on d.id_vendeur=k.id_vendeur";
        connection = MyConnection.getInstance();
        mypdf = new Document(PageSize.A4, 50, 50, 50, 50);
        File di = new File("C:/Voucher");
        File fl[] = di.listFiles();
        try {
            OutputStream file = new FileOutputStream(new File("C:/Voucher\\Voucher.pdf"));
            PdfWriter.getInstance(mypdf, file);

            mypdf.open();
            Statement stm;

            mypdf.addAuthor("Best Deal");
            mypdf.addSubject("Voucher ");
            mypdf.add(new Paragraph("Socite BestDeal"));
            mypdf.add(new Paragraph("Adresse La Chotrana ESPRIT "));
            mypdf.add(new Paragraph("TEL : xx xxx xxx"));
            mypdf.add(new Paragraph("FAX : xx xxx xxx"));
            mypdf.add(new Paragraph(
                    "                                                                                                       "
                            + new Date().toString()));
            mypdf.add(new Paragraph("  "));
            mypdf.add(new Paragraph("                                   " + "Voucher N'01",
                    FontFactory.getFont(FontFactory.HELVETICA, 21, Font.BOLDITALIC)));
            mypdf.add(new Paragraph("  "));

            mypdf.add(new Paragraph("CLIENT :",
                    FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));
            try {
                stm = connection.createStatement();
                ResultSet rs = stm.executeQuery(requete);

                while (rs.next()) {
                    // add a country to the document as a Chunk
                    //mypdf.add(new Chunk(rs.getString("quantite")));
                    Phrase p = new Phrase("Nom:   ");
                    Phrase p2 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa = new Paragraph();
                    pa.add(p);
                    pa.add(p2);
                    mypdf.add(pa);

                    Phrase p3 = new Phrase("Prenom:  ");
                    Phrase p4 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa1 = new Paragraph();
                    pa1.add(p3);
                    pa1.add(p4);
                    mypdf.add(pa1);

                    Phrase p5 = new Phrase("Adresse:  ");
                    Phrase p6 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa2 = new Paragraph();
                    pa2.add(p5);
                    pa2.add(p6);
                    mypdf.add(pa2);

                    Phrase p7 = new Phrase("Tlphone:  ");
                    Phrase p8 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa3 = new Paragraph();
                    pa3.add(p7);
                    pa3.add(p8);
                    mypdf.add(pa3);

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

                    mypdf.add(new Paragraph("Vendeur :",
                            FontFactory.getFont(FontFactory.TIMES_ROMAN, 13, Font.BOLDITALIC)));

                    Phrase p9 = new Phrase("Nom:  ");
                    Phrase p10 = new Phrase(new Chunk(rs.getString("nom")));
                    Paragraph pa4 = new Paragraph();
                    pa4.add(p9);
                    pa4.add(p10);
                    mypdf.add(pa4);

                    Phrase p11 = new Phrase("Prnom:  ");
                    Phrase p12 = new Phrase(new Chunk(rs.getString("prenom")));
                    Paragraph pa5 = new Paragraph();
                    pa5.add(p11);
                    pa5.add(p12);
                    mypdf.add(pa5);

                    Phrase p13 = new Phrase("Tlphone:  ");
                    Phrase p14 = new Phrase(new Chunk(rs.getString("telephone")));
                    Paragraph pa6 = new Paragraph();
                    pa6.add(p13);
                    pa6.add(p14);
                    mypdf.add(pa6);

                    Phrase p15 = new Phrase("Adresse:  ");
                    Phrase p16 = new Phrase(new Chunk(rs.getString("adresse")));
                    Paragraph pa7 = new Paragraph();
                    pa7.add(p15);
                    pa7.add(p16);
                    mypdf.add(pa7);

                    Phrase p17 = new Phrase("Email:  ");
                    Phrase p18 = new Phrase(new Chunk(rs.getString("email")));
                    Paragraph pa8 = new Paragraph();
                    pa8.add(p17);
                    pa8.add(p18);
                    mypdf.add(pa8);

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

                    for (int i = 0; i < rs.getRow(); i++) {
                        for (int j = 0; j < data[i].length - 1; j++) {
                            data[i][j] = rs.getString(j + 9);
                            // if (j==3)
                            //     data[i][4]= Float.parseFloat(data[i][3])*Integer.parseInt(data[i][2])+"";
                        }
                    }

                    for (int i = 0; i < rs.getRow(); i++) {
                        float s = Integer.parseInt(data[i][2].trim()) * Float.parseFloat(data[i][3].trim());
                        data[i][4] = s + "";
                    }

                    //mypdf.add(new Phrase("nom"));
                    //mypdf.add(new  Chunk(rs.getString("nom")));
                    //mypdf.add( new Paragraph("nom:", new Chunk(rs.getString("nom"))));
                    //mypdf.add(new Chunk(" "));
                    //Chunk id = new Chunk(rs.getString("id"));
                    // with a background color
                    //id.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f);
                    // and a text rise
                    //id.setTextRise(6);
                    //  mypdf.add(id);
                    mypdf.add(Chunk.NEWLINE);
                }

            } catch (SQLException ex) {
                Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
            }
            // mypdf.add(new Paragraph("Nom "));
            //  mypdf.add(new Paragraph("Prenom "));
            // mypdf.add(new Paragraph("Adresse "));
            //mypdf.add(new Paragraph("Tlphone "));

            // mypdf.add(new Paragraph("Nom "));
            // mypdf.add(new Paragraph("Nom de la socit "));
            //  mypdf.add(new Paragraph("Adresse "));
            // mypdf.add(new Paragraph("Tlphone "));
            // mypdf.add(new Paragraph("  "));

            String[] headers = new String[] { "  Id_deal", "   Nom Deal", "   Quantit", "    Prix unitaire",
                    "   Prix total" };
            PdfPTable table = new PdfPTable(headers.length);
            for (int i = 0; i < headers.length; i++) {
                String header = headers[i];
                PdfPCell cell = new PdfPCell();
                cell.setGrayFill(0.9f);
                cell.setPhrase(new Phrase(header.toUpperCase()));
                table.addCell(cell);
            }
            table.completeRow();
            for (int i = 0; i < data.length; i++) {
                for (int j = 0; j < data[i].length; j++) {
                    String datum = data[i][j];
                    PdfPCell cell = new PdfPCell();
                    cell.setPhrase(new Phrase(datum.toUpperCase()));
                    table.addCell(cell);
                }
                table.completeRow();
            }

            mypdf.add(table);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(genererPdf.class.getName()).log(Level.SEVERE, null, ex);
        }

        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(" "));
        mypdf.add(new Paragraph(
                "Pour toute question concernant cette facture,veuillez contacter Nom,numro de tlphone,adresse de messagerie ",
                FontFactory.getFont(null, 9, Font.NORMAL)));
        mypdf.add(new Paragraph(
                "                                                      Merci pour votre confiance",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 14, Font.BOLDITALIC)));
        mypdf.add(new Paragraph("      "));
        mypdf.add(new Paragraph("  "));
        mypdf.add(new Paragraph("  "));

        mypdf.close();

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

From source file:biblioteca.BibliotecaFXMLController.java

@FXML /// Arquivo - PDF - Tabela Alunos
public void pdf() throws FileNotFoundException, DocumentException, IOException, SQLException {
    Document doc = null;/*from  w w  w.j  a v a  2  s. co  m*/
    OutputStream os = null;
    try {
        contest conn = new contest();
        //cria o documento tamanho A4, margens de 2,54cm
        doc = new Document(PageSize.A4);
        //cria a stream de sada
        os = new FileOutputStream("TabelaA.pdf");
        //associa a stream de sada ao
        PdfWriter.getInstance(doc, os);
        //abre o documento
        doc.open();
        //adiciona o texto ao PDF 
        PdfPTable tabelaA = new PdfPTable(new float[] { 0.2f, 0.7f, 0.7f, 0.9f, 0.7f });
        PdfPCell header = new PdfPCell(new Paragraph("Tabela de Alunos"));
        header.setColspan(5);
        tabelaA.addCell(header);
        tabelaA.addCell("ID");
        tabelaA.addCell("Matrcula");
        tabelaA.addCell("Nome");
        tabelaA.addCell("C.P.F");
        tabelaA.addCell("Telefone");
        Statement stA = conn.conectar1().createStatement();
        ResultSet rsa = stA.executeQuery("SELECT idAluno,matriculaAluno,nomeAluno,nCPF,Telefone FROM `Aluno`;");
        while (rsa.next()) {
            Aluno a = new Aluno(0, 0, "", "", "");
            a.setIdaluno(rsa.getInt("idAluno"));
            a.setMatricula(rsa.getInt("matriculaAluno"));
            a.setNoAluno(rsa.getString("nomeAluno"));
            a.setCpf(rsa.getString("nCPF"));
            a.setTelefone(rsa.getString("Telefone"));

            tabelaA.addCell(String.valueOf(a.getIdaluno()));
            tabelaA.addCell(String.valueOf(a.getMatricula()));
            tabelaA.addCell(a.getNoAluno());
            tabelaA.addCell(a.getCpf());
            tabelaA.addCell(a.getTelefone());

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