Example usage for com.itextpdf.text.html.simpleparser HTMLWorker HTMLWorker

List of usage examples for com.itextpdf.text.html.simpleparser HTMLWorker HTMLWorker

Introduction

In this page you can find the example usage for com.itextpdf.text.html.simpleparser HTMLWorker HTMLWorker.

Prototype

public HTMLWorker(final DocListener document) 

Source Link

Document

Creates a new instance of HTMLWorker

Usage

From source file:net.apocalypselabs.symat.CodeExport.java

License:Open Source License

private void savePdfFile(String html, String path) {
    try {//from   w ww  .ja va  2 s  .  com
        String k = html;
        try (OutputStream file = new FileOutputStream(new File(path))) {
            Document document = new Document();
            PdfWriter.getInstance(document, file);
            document.open();
            HTMLWorker htmlWorker = new HTMLWorker(document);
            StyleSheet styles = new StyleSheet();
            styles.loadStyle("com", "color", "green");
            styles.loadStyle("kwd", "color", "blue");
            styles.loadStyle("pln", "color", "black");
            styles.loadStyle("lit", "color", "#0099cc");
            styles.loadStyle("pun", "color", "black");
            styles.loadStyle("pun", "font-weight", "bold");
            htmlWorker.setStyleSheet(styles);
            htmlWorker.parse(new StringReader(k));
            document.close();
            savedMsg();
        }
    } catch (IOException | DocumentException e) {
        JOptionPane.showInternalMessageDialog(this, "Error saving: " + e.getMessage());
    }
}

From source file:org.apli.jbs.utilidades.DocsPDFJB.java

public String creaDocInfoIngreso(String sNombrePac, int nHab, int nEpi) throws Exception {
    String nombrePDF = "";
    if (sNombrePac.equals("") || nHab == 0 || nEpi == 0) {
        throw new Exception("Funcion.creaContratoIngresHosp: error de programacin, faltan datos");
    } else {//from   w  ww .j a  v  a  2  s .  com
        nombrePDF = "docs/contratosCreadosPac/infoPacIngreHosp-" + nEpi + ".pdf";
        ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext();
        File folder = new File(extCont.getRealPath("//resources//"));
        String urlImg = extCont.getRealPath("//utilidades//");
        try {
            urlImg = urlImg.replace("\\utilidades", "\\");
            Document document = new Document(PageSize.LETTER, 70, 70, 30, 30);
            PdfWriter.getInstance(document, new FileOutputStream(
                    new File(folder, "docs/contratosCreadosPac/infoPacIngreHosp-" + nEpi + ".pdf")));
            document.open();
            Phrase phrase = new Phrase(90);
            HTMLWorker htmlWorker = new HTMLWorker(document);
            String str = "<p align='center'><img align=\"center\" src='" + urlImg + new PlantillaJB().getLogo()
                    + "' width=\"430\" height=\"70\"></p>\n" + "<div style=\" line-height:95%\">\n";
            File myhtml = new File(folder, "docs/contratos/infoPacIngreHosp.html");
            FileInputStream fileinput = null;
            BufferedInputStream mybuffer = null;
            DataInputStream datainput = null;
            fileinput = new FileInputStream(myhtml);
            mybuffer = new BufferedInputStream(fileinput);
            datainput = new DataInputStream(mybuffer);
            Calendar c1 = GregorianCalendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy");
            int i = 0;
            while (datainput.available() != 0) {
                i++;
                String linea = datainput.readLine();

                if (linea.indexOf("NOMBREPAC") > 0) {
                    linea = linea.replace("NOMBREPAC", sNombrePac.toUpperCase());
                }
                if (linea.indexOf("<u>FECHA</u>") > 0) {
                    linea = linea.replace("<u>FECHA</u>", "<u>" + sdf.format(c1.getTime()) + "</u>");
                }
                if (linea.indexOf("NO-HAB") > 0) {
                    linea = linea.replace("NO-HAB", "" + nHab);
                }
                str += linea + " ";
            }
            str += "</div>";
            htmlWorker.parse(new StringReader(str));
            document.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }

    }
    return nombrePDF;
}

From source file:org.apli.jbs.utilidades.DocsPDFJB.java

public String creaContratoIngresHosp(String sNombrePac, String sNombreResp, int nEpi)
        throws FileNotFoundException, Exception {
    String nombrePDF = "";
    if (sNombrePac.equals("") || sNombreResp.equals("") || nEpi == 0) {
        throw new Exception("DocsPDFJB.creaContratoIngresHosp: error de programacin, faltan datos");
    } else {/*from w w w . j  av  a 2 s.  c o  m*/
        nombrePDF = "docs/contratosCreadosPac/ContrtPacIngreHosp-" + nEpi + ".pdf";
        ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext();
        File folder = new File(extCont.getRealPath("//resources//"));
        String urlImg = extCont.getRealPath("//utilidades//");
        try {
            urlImg = urlImg.replace("\\utilidades", "\\");

            Document document = new Document(PageSize.LETTER, 70, 70, 30, 30);
            PdfWriter.getInstance(document, new FileOutputStream(
                    new File(folder, "docs/contratosCreadosPac/ContrtPacIngreHosp-" + nEpi + ".pdf")));

            document.open();
            Phrase phrase = new Phrase(90);
            HTMLWorker htmlWorker = new HTMLWorker(document);
            String str = "<p align='center'><img align=\"center\" src='" + urlImg + new PlantillaJB().getLogo()
                    + "' width=\"400\" height=\"119\"></p>\n" + "<div style=\" line-height:100%\">\n";

            File myhtml = new File(folder, "docs/contratos/ContrtPacIngreHosp.html");
            FileInputStream fileinput = null;
            BufferedInputStream mybuffer = null;
            DataInputStream datainput = null;
            fileinput = new FileInputStream(myhtml);
            mybuffer = new BufferedInputStream(fileinput);
            datainput = new DataInputStream(mybuffer);
            Calendar c1 = GregorianCalendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy");
            List<String> meses = new ArrayList<String>();
            meses.add("ENERO");
            meses.add("FEBRERO");
            meses.add("MARZO");
            meses.add("ABRIL");
            meses.add("MAYO");
            meses.add("JUNIO");
            meses.add("JULIO");
            meses.add("AGOSTO");
            meses.add("SEPTIEMBRE");
            meses.add("OCTUBRE");
            meses.add("NOVIEMBRE");
            meses.add("DICIEMBRE");

            int i = 0;
            while (datainput.available() != 0) {
                i++;
                String linea = datainput.readLine();

                if (linea.indexOf("NOMBREPAC") > 0) {
                    linea = linea.replace("NOMBREPAC", sNombrePac.toUpperCase());
                }
                if (linea.indexOf("NOMBRERESP") > 0) {
                    linea = linea.replace("NOMBRERESP", sNombreResp.toUpperCase());
                }
                if (linea.indexOf("FECHA-DIA") > 0) {
                    linea = linea.replace("FECHA-DIA", "" + c1.get(Calendar.DAY_OF_MONTH));
                }
                if (linea.indexOf("FECHA-MES") > 0) {
                    linea = linea.replace("FECHA-MES", "" + meses.get(c1.get(Calendar.MONTH)));
                }
                if (linea.indexOf("FECHA-AO") > 0) {
                    linea = linea.replace("FECHA-AO", "" + c1.get(Calendar.YEAR));
                }
                str += linea + " ";

            }
            str += "</div>";

            htmlWorker.parse(new StringReader(str));
            document.close();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }

    }
    return nombrePDF;
}

From source file:org.apli.jbs.utilidades.DocsPDFJB.java

public String creaContratoPaquete(String sNombrePac, String sTutor, int nFolioPaquete, float nAnticipo,
        float nPrecioCesaria, float nBloqueo, String sNombrePaq, String sTipoHab, int nTipoPaquete,
        List<DetallePaquete> carritoServicios) throws FileNotFoundException, Exception {
    String nombrePDF = "";
    if (sNombrePac.equals("") || nFolioPaquete == 0) {
        throw new Exception("Funcion.creaContratoIngresHosp: error de programacin, faltan datos");
    } else {//from  w ww .j a  v  a  2s  . co  m
        nombrePDF = "docs/contratosCreadosPac/ContratoPaquete-" + nFolioPaquete + ".pdf";
        ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext();
        File folder = new File(extCont.getRealPath("/resources/"));
        String urlImg = extCont.getRealPath("/utilidades/");
        try {
            //urlImg = urlImg.replace("/utilidades", "/");
            urlImg = urlImg.replace("\\utilidades", "\\");
            System.out.println(urlImg);

            Document document = new Document(PageSize.LETTER, 70, 70, 30, 30);
            PdfWriter.getInstance(document, new FileOutputStream(
                    new File(folder, "docs/contratosCreadosPac/ContratoPaquete-" + nFolioPaquete + ".pdf")));

            document.open();
            Phrase phrase = new Phrase(90);

            HTMLWorker htmlWorker = new HTMLWorker(document);
            String str = "<p align='center'><img align=\"center\" src='" + urlImg + new PlantillaJB().getLogo()
                    + "' width=\"400\" height=\"119\"></p>\n"
                    + "<div style=\" line-height:90%;font-size:10.0pt;\">\n";
            File myhtml = new File(folder, "docs/contratos/ContratoPaqueteEmbarazo.html");

            switch (nTipoPaquete) {
            case TipoPaquete.MATERNIDAD:
                myhtml = new File(folder, "docs/contratos/ContratoPaqueteEmbarazo.html");
                break;
            case TipoPaquete.PEDIATRICO:
                myhtml = new File(folder, "docs/contratos/ContratoPaquetePediatrico.html");
                break;
            case TipoPaquete.QUIRURGICO:
                myhtml = new File(folder, "docs/contratos/ContratoPaqueteOtros.html");
                break;
            default:
                myhtml = new File(folder, "docs/contratos/ContratoPaqueteOtros.html");
                break;
            }

            FileInputStream fileinput = null;
            BufferedInputStream mybuffer = null;
            DataInputStream datainput = null;
            fileinput = new FileInputStream(myhtml);
            mybuffer = new BufferedInputStream(fileinput);
            datainput = new DataInputStream(mybuffer);
            Calendar c1 = GregorianCalendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy");
            List<String> meses = new ArrayList<String>();
            meses.add("ENERO");
            meses.add("FEBRERO");
            meses.add("MARZO");
            meses.add("ABRIL");
            meses.add("MAYO");
            meses.add("JUNIO");
            meses.add("JULIO");
            meses.add("AGOSTO");
            meses.add("SEPTIEMBRE");
            meses.add("OCTUBRE");
            meses.add("NOVIEMBRE");
            meses.add("DICIEMBRE");

            String sTablaServicios = "<ul>\n";

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

                sTablaServicios += "<li>";
                sTablaServicios += (i + 1) + ".- "
                        + carritoServicios.get(i).getConceptoIngreso().getDescripcion();
                sTablaServicios += "</li>\n";

            }
            sTablaServicios += "\n</ul>";
            System.out.println("servicios " + sTablaServicios);
            int i = 0;
            while (datainput.available() != 0) {
                i++;
                String linea = datainput.readLine();

                if (linea.indexOf("NOMBREPAC") > 0) {
                    linea = linea.replace("NOMBREPAC", sNombrePac);
                }
                if (linea.indexOf("NOMBRETUTOR") > 0) {
                    linea = linea.replace("NOMBRETUTOR", sTutor);
                }
                if (linea.indexOf("ANNTTICCIPPO") > 0) {
                    linea = linea.replace("ANNTTICCIPPO", "" + nAnticipo);
                }
                if (linea.indexOf("PRECIOCESAREA") > 0) {
                    linea = linea.replace("PRECIOCESAREA", "" + nPrecioCesaria);
                }
                if (linea.indexOf("FECHA-DIA") > 0) {
                    linea = linea.replace("FECHA-DIA", "" + c1.get(Calendar.DAY_OF_MONTH));
                }
                if (linea.indexOf("FECHA-MES") > 0) {
                    linea = linea.replace("FECHA-MES", "" + meses.get(c1.get(Calendar.MONTH)));
                }
                if (linea.indexOf("FECHA-ANIO") > 0) {
                    linea = linea.replace("FECHA-ANIO", "" + c1.get(Calendar.YEAR));
                }
                if (linea.indexOf("NOMBREPAQUETE") > 0) {
                    linea = linea.replace("NOMBREPAQUETE", sNombrePaq);
                }
                //agregar linea en el html
                if (linea.indexOf("LISTASERVICIOSPAQUETE") > 0) {
                    linea = linea.replace("LISTASERVICIOSPAQUETE", sTablaServicios);
                }
                str += linea + " ";

            }
            str += "</div>";

            htmlWorker.parse(new StringReader(str));

            if (nTipoPaquete == TipoPaquete.MATERNIDAD) {
                document.newPage();
                str = "";
                str += "<p align='center'><img align=\"center\" src='" + urlImg + new PlantillaJB().getLogo()
                        + "' width=\"400\" height=\"119\"></p>\n"
                        + "<div style=\" line-height:110%;font-size:9.0pt;\">\n";
                File myhtml2 = new File(folder, "docs/contratos/InfoPaqMat.html");
                FileInputStream fileinput2 = null;
                BufferedInputStream mybuffer2 = null;
                DataInputStream datainput2 = null;
                fileinput2 = new FileInputStream(myhtml2);
                mybuffer2 = new BufferedInputStream(fileinput2);
                datainput2 = new DataInputStream(mybuffer2);

                while (datainput2.available() != 0) {
                    String linea = datainput2.readLine();
                    if (linea.indexOf("NOMBREPAC") > 0) {
                        linea = linea.replace("NOMBREPAC", sNombrePac);
                    }
                    if (linea.indexOf("ANNTTICCIPPO") > 0) {
                        linea = linea.replace("ANNTTICCIPPO", "" + nAnticipo);
                    }
                    if (linea.indexOf("FECHACOMPLETA") > 0) {
                        linea = linea.replace("FECHACOMPLETA", "" + sdf.format(new Date()));
                    }
                    if (linea.indexOf("NOMBREPAQUETE") > 0) {
                        linea = linea.replace("NOMBREPAQUETE", sNombrePaq);
                    }
                    if (linea.indexOf("TTIIPPOOHHAABB") > 0) {
                        linea = linea.replace("TTIIPPOOHHAABB", "" + sTipoHab);
                    }
                    if (linea.contains("BBLLOOQQUUEEOO")) {
                        linea = linea.replace("BBLLOOQQUUEEOO", "" + nBloqueo);
                    }
                    str += linea + " ";
                }
                str += "</div>";
                htmlWorker.parse(new StringReader(str));

            }
            document.close();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }

    }
    return nombrePDF;
}

From source file:org.apli.jbs.utilidades.DocsPDFJB.java

public String creaPaseSalida(String sNombrePac, String sTipoPac, String entregaCtrlTv, String sEntregaCtrolServ,
        String sDocumentacion, String folioUltimo, int nHab, int nEpi, Date dFechaSalida,
        ServicioPrestado oServiciosPrestados[]) throws FileNotFoundException, Exception {

    String nombrePDF = "";
    if (sNombrePac.equals("") || sTipoPac.equals("") || entregaCtrlTv.equals("") || sEntregaCtrolServ.equals("")
            || sDocumentacion.equals("") || folioUltimo.equals("") || nHab == 0 || nEpi == 0
            || dFechaSalida == null) {//from   w w  w.ja  v a 2 s  .  com
        throw new Exception("Funcion.creaContratoIngresHosp: error de programacin, faltan datos");
    } else {
        nombrePDF = "docs/contratosCreadosPac/paseSalida-" + nEpi + ".pdf";
        ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext();
        File folder = new File(extCont.getRealPath("//resources//"));
        String urlImg = extCont.getRealPath("//utilidades//");

        try {
            urlImg = urlImg.replace("\\utilidades", "\\");
            Document document = new Document(PageSize.LETTER, 70, 70, 25, 25);
            PdfWriter.getInstance(document, new FileOutputStream(
                    new File(folder, "docs/contratosCreadosPac/paseSalida-" + nEpi + ".pdf")));

            document.open();
            Phrase phrase = new Phrase(60);
            HTMLWorker htmlWorker = new HTMLWorker(document);
            String str = "<body>";

            File myhtml = new File(folder, "docs/contratos/paseSalidaHosp.html");
            FileInputStream fileinput = null;
            BufferedInputStream mybuffer = null;
            DataInputStream datainput = null;
            fileinput = new FileInputStream(myhtml);
            mybuffer = new BufferedInputStream(fileinput);
            datainput = new DataInputStream(mybuffer);
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy");
            SimpleDateFormat sdf2 = new SimpleDateFormat("h:mm:ss");
            int i = 0;
            while (datainput.available() != 0) {
                i++;
                String linea = datainput.readLine();

                if (linea.indexOf("IMAGEN") > 0) {
                    linea = linea.replace("IMAGEN", urlImg + new PlantillaJB().getLogo());
                }
                if (linea.indexOf("NOMBREPAC") > 0) {
                    linea = linea.replace("NOMBREPAC", sNombrePac);
                }
                if (linea.indexOf("EMPRESAPARTICULAR") > 0) {
                    linea = linea.replace("EMPRESAPARTICULAR", sTipoPac);
                }
                if (linea.indexOf("NOHAB") > 0) {
                    linea = linea.replace("NOHAB", "" + nHab);
                }
                if (linea.indexOf("FECHACOMPL") > 0) {
                    linea = linea.replace("FECHACOMPL", sdf.format(dFechaSalida));
                }
                if (linea.indexOf("FECHAHORA") > 0) {
                    linea = linea.replace("FECHAHORA", sdf2.format(dFechaSalida));
                }
                if (linea.indexOf("FOLIO") > 0) {
                    linea = linea.replace("FOLIO", folioUltimo);
                }
                if (linea.indexOf("CONTROLTV") > 0) {
                    linea = linea.replace("CONTROLTV", entregaCtrlTv);
                }
                if (linea.indexOf("CONTROLCLIMA") > 0) {
                    linea = linea.replace("CONTROLCLIMA", sEntregaCtrolServ);
                }
                if (linea.indexOf("RESULTADOESTUDIOS") > 0) {
                    linea = linea.replace("RESULTADOESTUDIOS", sDocumentacion);
                }
                if (oServiciosPrestados == null) {

                    if (linea.indexOf("LISTASERVICIOSPRESTADOS") > 0) {
                        linea = linea.replace("LISTASERVICIOSPRESTADOS", "");
                    }

                } else {
                    String sListaServicios = construyeListaServiciosPrestados(oServiciosPrestados);

                    if (linea.indexOf("LISTASERVICIOSPRESTADOS") > 0) {
                        linea = linea.replace("LISTASERVICIOSPRESTADOS", sListaServicios);
                    }
                }

                str += linea + " ";

            }
            str += "</body>";

            htmlWorker.parse(new StringReader(str));
            document.close();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
    return nombrePDF;
}

From source file:org.apli.jbs.utilidades.DocsPDFJB.java

public String creaSolicitudInterconsulta(List<ConceptoIngreso> servicios, int epi, String pac, int hab,
        String tratante, String capturista) throws FileNotFoundException, Exception {

    String nombrePDF = "";
    if (servicios.isEmpty() || epi == 0 || pac.equals("") || tratante.equals("") || capturista.equals("")) {
        throw new Exception("Funcion.creaSolicitudInterconsulta: error de programacin, faltan datos");
    } else {//from www.  ja v  a  2 s .co  m
        nombrePDF = "docs/contratosCreadosPac/solicitudInterconsulta-" + epi + ".pdf";
        ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext();
        File folder = new File(extCont.getRealPath("//resources//"));
        String urlImg = extCont.getRealPath("//utilidades//");

        try {
            urlImg = urlImg.replace("\\utilidades", "\\");
            Document document = new Document(PageSize.LETTER, 70, 70, 25, 25);
            PdfWriter.getInstance(document, new FileOutputStream(
                    new File(folder, "docs/contratosCreadosPac/solicitudInterconsulta-" + epi + ".pdf")));
            document.open();
            Phrase phrase = new Phrase(60);
            HTMLWorker htmlWorker = new HTMLWorker(document);

            for (int j = 0; j < servicios.size(); j++) {
                String str = "<body>";
                File myhtml = new File(folder, "docs/contratos/solicitudInterconsulta.html");
                FileInputStream fileinput = null;
                BufferedInputStream mybuffer = null;
                DataInputStream datainput = null;
                fileinput = new FileInputStream(myhtml);
                mybuffer = new BufferedInputStream(fileinput);
                datainput = new DataInputStream(mybuffer);
                SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy");
                SimpleDateFormat sdf2 = new SimpleDateFormat("HH:mm:ss");
                int i = 0;
                while (datainput.available() != 0) {
                    i++;
                    String linea = datainput.readLine();

                    if (linea.indexOf("IMAGEN") > 0) {
                        linea = linea.replace("IMAGEN", urlImg + new PlantillaJB().getLogo());
                    }
                    if (linea.indexOf("NOMBREPAC") > 0) {
                        linea = linea.replace("NOMBREPAC", pac);
                    }
                    if (linea.indexOf("NOHAB") > 0) {
                        linea = linea.replace("NOHAB", ("" + ((hab == 0) ? "Consulta Externa" : hab)));
                    }
                    if (linea.indexOf("FECHACOMPLETA") > 0) {
                        linea = linea.replace("FECHACOMPLETA",
                                sdf.format(servicios.get(j).getConServ().getFechaInterconsulta()));
                    }
                    if (linea.indexOf("FECHAHORA") > 0) {
                        linea = linea.replace("FECHAHORA",
                                sdf2.format(servicios.get(j).getConServ().getFechaInterconsulta()));
                    }
                    if (linea.indexOf("FOLIOSERV") > 0) {
                        linea = linea.replace("FOLIOSERV", servicios.get(j).getConServ().getFolioServ());
                    }
                    if (linea.indexOf("NOMBREMEDINTE") > 0) {
                        linea = linea.replace("NOMBREMEDINTE",
                                "" + servicios.get(j).getConServ().getMedicoHonorarios().getNombreCompleto());
                    }
                    if (linea.indexOf("NOMBRECONC") > 0) {
                        linea = linea.replace("NOMBRECONC", servicios.get(j).getDescripcion());
                    }
                    if (linea.indexOf("NOMBREMEDTRA") > 0) {
                        linea = linea.replace("NOMBREMEDTRA", "" + tratante);
                    }
                    if (linea.indexOf("NOMBRECAP") > 0) {
                        linea = linea.replace("NOMBRECAP", "" + capturista);
                    }

                    str += linea + " ";

                }
                str += "</body>";
                String str2 = str;
                str2 += "<br><br><br>";
                str2 += str;
                htmlWorker.parse(new StringReader(str2));
                if ((servicios.size() - 1) != i) {
                    document.newPage();
                }

            }
            document.close();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
    return nombrePDF;
}

From source file:org.apli.jbs.utilidades.DocsPDFJB.java

public String creaComprobanteProceQuirurgico(List<ServicioPrestado> servicios, int epi, String pac, int hab,
        String tratante) throws FileNotFoundException, Exception {

    String nombrePDF = "";
    if (servicios.isEmpty() || epi == 0 || pac.equals("") || hab == 0 || tratante.equals("")) {
        throw new Exception("Funcion.creaSolicitudInterconsulta: error de programacin, faltan datos");
    } else {/* w w  w.j  av a2  s . co  m*/
        nombrePDF = "docs/contratosCreadosPac/comprobanteProceQuirurgico-" + epi + ".pdf";
        ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext();
        File folder = new File(extCont.getRealPath("//resources//"));
        String urlImg = extCont.getRealPath("//utilidades//");
        try {
            urlImg = urlImg.replace("\\utilidades", "\\");
            Document document = new Document(PageSize.LETTER, 70, 70, 25, 25);
            PdfWriter.getInstance(document, new FileOutputStream(
                    new File(folder, "docs/contratosCreadosPac/comprobanteProceQuirurgico-" + epi + ".pdf")));
            document.open();
            Phrase phrase = new Phrase(60);
            HTMLWorker htmlWorker = new HTMLWorker(document);

            for (int j = 0; j < servicios.size(); j++) {
                String str = "<body>";
                File myhtml = new File(folder, "docs/contratos/comprobanteProceQuirurgico.html");
                FileInputStream fileinput = null;
                BufferedInputStream mybuffer = null;
                DataInputStream datainput = null;
                fileinput = new FileInputStream(myhtml);
                mybuffer = new BufferedInputStream(fileinput);
                datainput = new DataInputStream(mybuffer);
                SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy h:mm:ss");
                SimpleDateFormat sdf2 = new SimpleDateFormat("h:mm:ss");
                int i = 0;
                long tiempoInicial = servicios.get(j).getServProcQx().getProcedimientoRealizado().getIni()
                        .getTime();
                long tiempoFinal = servicios.get(j).getServProcQx().getProcedimientoRealizado().getFin()
                        .getTime();
                long resta = tiempoFinal - tiempoInicial;

                while (datainput.available() != 0) {
                    i++;
                    String linea = datainput.readLine();

                    if (linea.indexOf("IMAGEN") > 0) {
                        linea = linea.replace("IMAGEN", urlImg + new PlantillaJB().getLogo());
                    }
                    if (linea.indexOf("NOMBREPAC") > 0) {
                        linea = linea.replace("NOMBREPAC", pac);
                    }
                    if (linea.indexOf("NOHAB") > 0) {
                        linea = linea.replace("NOHAB", "" + hab);
                    }
                    if (linea.indexOf("FECHAINICIO") > 0) {
                        linea = linea.replace("FECHAINICIO", sdf
                                .format(servicios.get(j).getServProcQx().getProcedimientoRealizado().getIni()));
                    }
                    if (linea.indexOf("FECHAFIN") > 0) {
                        linea = linea.replace("FECHAFIN", sdf
                                .format(servicios.get(j).getServProcQx().getProcedimientoRealizado().getFin()));
                    }
                    if (linea.indexOf("FOLIOSERV") > 0) {
                        linea = linea.replace("FOLIOSERV", servicios.get(j).getIdFolio());
                    }
                    if (linea.indexOf("PPRROOCCEE") > 0) {
                        linea = linea.replace("PPRROOCCEE", servicios.get(j).getServProcQx()
                                .getProcedimientoRealizado().getTipoProcQx().getDescripcion());
                    }
                    if (linea.indexOf("DDUURRAACCIIOONN") > 0) {
                        linea = linea.replace("DDUURRAACCIIOONN", "" + sdf2.format(new Date(resta)));
                    }
                    if (linea.indexOf("MEDENF") > 0) {
                        linea = linea.replace("MEDENF", "" + servicios.get(j).getMedico().getNombreCompleto());
                    }
                    if (linea.indexOf("NOMBREMEDTRA") > 0) {
                        linea = linea.replace("NOMBREMEDTRA", "" + tratante);
                    }
                    if (linea.indexOf("RROOLLF") > 0) {
                        linea = linea.replace("RROOLLF", "" + servicios.get(j).getServProcQx().getDescripRol());
                    }

                    str += linea + " ";

                }
                str += "</body>";
                String str2 = str;
                str2 += "<br><br><br>";
                str2 += str;
                htmlWorker.parse(new StringReader(str2));
                if ((servicios.size() - 1) != i) {
                    document.newPage();
                }

            }
            document.close();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }
    return nombrePDF;
}

From source file:org.apli.jbs.utilidades.DocsPDFJB.java

public String creaEncuestaHospitalYCheckList(int nEpi, String sNombrePac, boolean encuesta, boolean checklist,
        int nHab, Date dFechaIngreso, Date dFechaEgreso) throws FileNotFoundException, Exception {

    String nombrePDF = "";
    if (sNombrePac.equals("") || nEpi == 0) {
        throw new Exception("Funcion.creaContratoIngresHosp: error de programacin, faltan datos");
    } else {//w  w  w .  j  a  v a  2 s  .  c o m
        if (encuesta || checklist) {

            nombrePDF = "docs/contratosCreadosPac/encuestaHospitalYCheckList-" + nEpi + ".pdf";
            ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext();
            File folder = new File(extCont.getRealPath("//resources//"));
            String urlImg = extCont.getRealPath("//utilidades//");

            try {
                urlImg = urlImg.replace("\\utilidades", "\\");
                Document document = new Document(PageSize.LETTER, 70, 70, 25, 25);
                PdfWriter.getInstance(document, new FileOutputStream(new File(folder,
                        "docs/contratosCreadosPac/encuestaHospitalYCheckList-" + nEpi + ".pdf")));
                SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy");
                HTMLWorker htmlWorker = new HTMLWorker(document);
                document.open();
                String str = "";

                if (encuesta) {

                    str += "<p align='center'><img align=\"center\" src='" + urlImg
                            + new PlantillaJB().getLogo() + "' width=\"400\" height=\"119\"></p>\n"
                            + "<div style=\" line-height:110%\">\n";

                    File myhtml = new File(folder, "docs/contratos/encuestaHospital.html");
                    FileInputStream fileinput = null;
                    BufferedInputStream mybuffer = null;
                    DataInputStream datainput = null;
                    fileinput = new FileInputStream(myhtml);
                    mybuffer = new BufferedInputStream(fileinput);
                    datainput = new DataInputStream(mybuffer);

                    while (datainput.available() != 0) {
                        String linea = datainput.readLine();
                        if (linea.indexOf("NOMBREPAC") > 0) {
                            linea = linea.replace("NOMBREPAC", sNombrePac);
                        }
                        if (linea.indexOf("FECHACOMPL") > 0) {
                            linea = linea.replace("FECHACOMPL", sdf.format(new Date()));
                        }
                        str += linea + " ";
                    }
                    str += "</div>";

                    htmlWorker.parse(new StringReader(str));
                    if (checklist) {
                        document.newPage();
                    }

                }
                if (checklist) {

                    str = "";
                    str += "<p align='center'><img align=\"center\" src='" + urlImg
                            + new PlantillaJB().getLogo() + "' width=\"400\" height=\"119\"></p>\n"
                            + "<div style=\" line-height:110%\">\n";

                    File myhtml = new File(folder, "docs/contratos/checkListExpedienteClinico.html");
                    FileInputStream fileinput = null;
                    BufferedInputStream mybuffer = null;
                    DataInputStream datainput = null;
                    fileinput = new FileInputStream(myhtml);
                    mybuffer = new BufferedInputStream(fileinput);
                    datainput = new DataInputStream(mybuffer);

                    while (datainput.available() != 0) {
                        String linea = datainput.readLine();

                        if (linea.indexOf("NOMBREPAC") > 0) {
                            linea = linea.replace("NOMBREPAC", sNombrePac);
                        }
                        if (linea.indexOf("NOHAB") > 0) {
                            linea = linea.replace("NOHAB", "" + nHab);
                        }
                        if (linea.indexOf("FECHAINGRESO") > 0) {
                            linea = linea.replace("FECHAINGRESO", sdf.format(dFechaIngreso));
                        }
                        if (linea.indexOf("FECHAEGRESO") > 0) {
                            linea = linea.replace("FECHAEGRESO", sdf.format(dFechaEgreso));
                        }
                        str += linea + " ";
                    }
                    str += "</div>";
                    htmlWorker.parse(new StringReader(str));

                }
                document.close();

            } catch (IOException e) {
                e.printStackTrace();
            } catch (DocumentException e) {
                e.printStackTrace();
            }
        }
    }
    return nombrePDF;
}

From source file:org.apli.jbs.utilidades.DocsPDFJB.java

public String creaPagare(String sNombreRes, float nCantidadPagar, String sCantidadPagar, float nInteres,
        String sFechaPago, int nEpi) throws Exception {
    String nombrePDF = "";
    System.out.println(sNombreRes + " - " + nCantidadPagar + " - " + sCantidadPagar + " - " + nInteres + " - "
            + sFechaPago + " - " + nEpi);
    if (sNombreRes.equals("") || nCantidadPagar == 0 || sCantidadPagar.equals("") || nInteres == 0
            || sFechaPago.equals("") || nEpi == 0) {
        throw new Exception("Funcion.creaContratoIngresHosp: error de programacin, faltan datos");
    } else {/*from w  ww .jav  a2 s. co  m*/
        nombrePDF = "docs/contratosCreadosPac/pagare-" + nEpi + ".pdf";
        ExternalContext extCont = FacesContext.getCurrentInstance().getExternalContext();
        File folder = new File(extCont.getRealPath("//resources//"));
        String urlImg = extCont.getRealPath("/");
        try {
            //urlImg = urlImg.replace("\\utilidades", "\\");

            Document document = new Document(PageSize.LETTER, 70, 70, 30, 30);
            PdfWriter.getInstance(document,
                    new FileOutputStream(new File(folder, "docs/contratosCreadosPac/pagare-" + nEpi + ".pdf")));

            document.open();
            Phrase phrase = new Phrase(90);
            HTMLWorker htmlWorker = new HTMLWorker(document);
            String str = "<p align='center'><img align=\"center\" src='" + urlImg + new PlantillaJB().getLogo()
                    + "' width=\"430\" height=\"70\"></p>\n" + "<div style=\" line-height:95%\">\n";
            File myhtml = new File(folder, "docs/contratos/pagare.html");
            FileInputStream fileinput = null;
            BufferedInputStream mybuffer = null;
            DataInputStream datainput = null;
            fileinput = new FileInputStream(myhtml);
            mybuffer = new BufferedInputStream(fileinput);
            datainput = new DataInputStream(mybuffer);
            Calendar c1 = GregorianCalendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MMMMM-yyyy");

            int i = 0;
            while (datainput.available() != 0) {
                i++;
                String linea = datainput.readLine();

                if (linea.indexOf("NOMBRERES") > 0) {
                    linea = linea.replace("NOMBRERES", sNombreRes);
                }
                if (linea.indexOf("DIAPAGO") > 0) {
                    linea = linea.replace("DIAPAGO", sFechaPago);
                }
                if (linea.indexOf("CANTIDADPAGO") > 0) {
                    linea = linea.replace("CANTIDADPAGO", "" + nCantidadPagar);
                }
                if (linea.indexOf("LETRAPAGO") > 0) {
                    linea = linea.replace("LETRAPAGO", "" + sCantidadPagar);
                }
                if (linea.indexOf("INTERESPAGO") > 0) {
                    linea = linea.replace("INTERESPAGO", "" + nInteres);
                }
                str += linea + " ";

            }
            str += "</div>";

            htmlWorker.parse(new StringReader(str));
            document.close();

        } catch (IOException e) {
            e.printStackTrace();
        } catch (DocumentException e) {
            e.printStackTrace();
        }

    }
    return nombrePDF;
}

From source file:PDF.PDF.java

/**
 *
 * @param fname this is the filename passed in from the jsp
 * @param k this is all the details from the order to be passed to pdf
 * @exception FileNotFoundException this will catch an error if the file to
 * be or written to is not found OutputStream file outputs the given file to
 * bytes PdfWriter writer creates a pdf version of the given file (file) to
 * the given format (doc) HTMLWorker htmlWorker converts the data from the
 * String (k) to the PDF format doc.close() closes access the document
 * file.close() closes access to the file
        /*w w  w . j a v  a  2 s  .com*/
 */
public PDF(String fname, String k) throws FileNotFoundException {
    filename = "Order" + fname + ".pdf";
    try {
        f = new File(filename);
        OutputStream file = new FileOutputStream(f);
        Document doc = new Document(PageSize.A4);
        PdfWriter writer = PdfWriter.getInstance(doc, file);
        doc.open();
        HTMLWorker htmlWorker = new HTMLWorker(doc);
        htmlWorker.parse(new StringReader(k));
        doc.close();
        file.close();
    } catch (IOException | DocumentException e) {
        System.err.println("IOExcetpion");
    }
}