Example usage for com.itextpdf.text PageSize LETTER

List of usage examples for com.itextpdf.text PageSize LETTER

Introduction

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

Prototype

Rectangle LETTER

To view the source code for com.itextpdf.text PageSize LETTER.

Click Source Link

Document

This is the letter format

Usage

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 .ja v  a2  s . c  om
        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  w  w  . j av a  2  s  .c  o 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) {/* w  ww .ja  va  2s.co m*/
        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 {//  w  w  w . j  a  va2s.  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 ww.j av a 2s  .c o 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 {//from   w w  w.  j ava2s . c  om
        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 ww  w.  j av a  2s  .  c om
        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:org.cidte.sii.negocio.PDFWriter.java

public void writePDF(ArrayList<Writable> list, String directorio, String nombre, java.awt.Image image)
        throws DocumentException, FileNotFoundException, BadElementException, IOException {

    Document doc = new Document();
    PdfWriter docWriter;//from w ww .j a  v a  2s .c  o  m

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

    // file path
    String path = directorio + nombre + ".pdf";
    docWriter = PdfWriter.getInstance(doc, new FileOutputStream(new File(path)));

    // document header attributes
    doc.addAuthor("sii");
    doc.addCreationDate();
    doc.addProducer();
    doc.addCreator("sii");
    doc.addTitle(nombre);
    doc.setPageSize(PageSize.LETTER);

    // open document
    doc.open();

    Image img = Image.getInstance(image, null);
    img.setAlignment(Element.ALIGN_LEFT);
    doc.add(img);

    // create a paragraph
    Paragraph paragraph = new Paragraph("iText  is a library that allows you to create and "
            + "manipulate PDF documents. It enables developers looking to enhance web and other "
            + "applications with dynamic PDF document generation and/or manipulation.");

    // create PDF table with the given widths
    PdfPTable table = new PdfPTable(list.get(0).getNames().length);
    // set table width a percentage of the page width
    table.setWidthPercentage(100);
    table.setSpacingBefore(10f); // Space before table
    table.setSpacingAfter(10f); // Space after table

    // insert column headings
    String[] headings = list.get(0).getNames();
    for (String heading : headings) {
        insertCell(table, heading, Element.ALIGN_CENTER, 1, bfBold12);
    }
    table.setHeaderRows(1);

    // insert the data
    for (int i = 0; i < list.size(); i++) {
        Writable w = list.get(i);
        Object[] arr = w.getAsArray();
        for (int j = 0; j < arr.length; j++) {
            // arr[j]
            insertCell(table, arr[j].toString(), Element.ALIGN_LEFT, 1, bf12);
        }
    }

    // insert an empty row
    // insertCell(table, "", Element.ALIGN_LEFT, 4, bfBold12);
    // add the PDF table to the paragraph
    paragraph.add(table);
    // add the paragraph to the document
    doc.add(paragraph);

    // close the document
    doc.close();

    // close the writer
    docWriter.close();

}

From source file:org.dspace.disseminate.CitationDocument.java

/**
 * Creates a/*  w  w  w .  j  ava2 s .  c  o  m*/
 * cited document from the given bitstream of the given item. This
 * requires that bitstream is contained in item.
 * <p>
 * The Process for adding a cover page is as follows:
 * <ol>
 *  <li> Load source file into PdfReader and create a
 *     Document to put our cover page into.</li>
 *  <li> Create cover page and add content to it.</li>
 *  <li> Concatenate the coverpage and the source
 *     document.</li>
 * </p>
 *
 * @param bitstream The source bitstream being cited. This must be a PDF.
 * @param cMeta The citation information used to generate the coverpage.
 * @return The temporary File that is the finished, cited document.
 * @throws com.itextpdf.text.DocumentException
 * @throws java.io.FileNotFoundException
 * @throws SQLException
 * @throws org.dspace.authorize.AuthorizeException
 */
private File makeCitedDocument(Bitstream bitstream, CitationMeta cMeta)
        throws DocumentException, IOException, SQLException, AuthorizeException {
    //Read the source bitstream
    PdfReader source = new PdfReader(bitstream.retrieve());

    Document citedDoc = new Document(PageSize.LETTER);

    File coverTemp = File.createTempFile(bitstream.getName(), ".cover.pdf");

    //Need a writer instance to make changed to the document.
    PdfWriter writer = PdfWriter.getInstance(citedDoc, new FileOutputStream(coverTemp));

    //Call helper function to add content to the coverpage.
    this.generateCoverPage(citedDoc, writer, cMeta);

    //Create reader from finished cover page.
    PdfReader cover = new PdfReader(new FileInputStream(coverTemp));

    //Get page labels from source document
    String[] labels = PdfPageLabels.getPageLabels(source);

    //Concatenate the finished cover page with the source document.
    File citedTemp = File.createTempFile(bitstream.getName(), ".cited.pdf");
    OutputStream citedOut = new FileOutputStream(citedTemp);
    PdfConcatenate concat = new PdfConcatenate(citedOut);
    concat.open();

    //Is the citation-page the first page or last-page?
    if (isCitationFirstPage()) {
        //citation as cover page
        concat.addPages(cover);
        concat.addPages(source);
    } else {
        //citation as tail page
        concat.addPages(source);
        concat.addPages(cover);
    }

    //Put all of our labels in from the orignal document.
    if (labels != null) {
        PdfPageLabels citedPageLabels = new PdfPageLabels();
        log.debug("Printing arbitrary page labels.");

        for (int i = 0; i < labels.length; i++) {
            citedPageLabels.addPageLabel(i + 1, PdfPageLabels.EMPTY, labels[i]);
            log.debug("Label for page: " + (i + 1) + " -> " + labels[i]);
        }
        citedPageLabels.addPageLabel(labels.length + 1, PdfPageLabels.EMPTY, "Citation Page");
        concat.getWriter().setPageLabels(citedPageLabels);
    }

    //Close it up
    concat.close();

    //Close the cover-page
    writer.close();
    coverTemp.delete();

    citedTemp.deleteOnExit();
    return citedTemp;
}

From source file:org.fhaes.neofhchart.PDFExportOptionsDialog.java

License:Open Source License

/**
 * Handles when actions are performed on the dialog.
 *//* w w  w.j  a  va  2 s.  c o m*/
@Override
public void actionPerformed(ActionEvent evt) {

    if (evt.getActionCommand().equals("OK")) {
        // Perform the export operation
        boolean completedSuccessfully = doExportToPDF();

        if (completedSuccessfully) {
            MainWindow.getInstance().getFeedbackMessagePanel().updateFeedbackMessage(FeedbackMessageType.INFO,
                    FeedbackDisplayProtocol.AUTO_HIDE,
                    FeedbackDictionary.NEOFHCHART_PDF_EXPORT_MESSAGE.toString());
        } else {
            MainWindow.getInstance().getFeedbackMessagePanel().updateFeedbackMessage(FeedbackMessageType.ERROR,
                    FeedbackDisplayProtocol.MANUAL_HIDE,
                    "An error occured while attempting to export chart as PDF.");
        }

        this.dispose();
    } else if (evt.getActionCommand().equals("Cancel")) {
        // Close the dialog
        this.dispose();
    } else if (evt.getActionCommand().equals("PaperSize")) {
        // Update the paper size label
        if (this.cboPaperSize.getSelectedItem() instanceof Rectangle) {
            Object value = this.cboPaperSize.getSelectedItem();
            if (value.equals(PageSize.A5)) {
                this.lblSize.setText("148 x 210mm  /  5.83 x 8.27\"");
            } else if (value.equals(PageSize.A4)) {
                this.lblSize.setText("210 x 297mm  /  8.27 x 11.7\"");
            } else if (value.equals(PageSize.A3)) {
                this.lblSize.setText("297 x 420mm  /  11.7 x 16.5\"");
            } else if (value.equals(PageSize.A2)) {
                this.lblSize.setText("420 x 594mm  /  16.5 x 23.4\"");
            } else if (value.equals(PageSize.A1)) {
                this.lblSize.setText("594 x 841mm  /  23.4 x 33.1\"");
            } else if (value.equals(PageSize.A0)) {
                this.lblSize.setText("841 x 1189mm  /  33.1 x 46.8\"");
            } else if (value.equals(PageSize.LETTER)) {
                this.lblSize.setText("215.9 x 279.4mm  /  8.5 x 11\"");
            } else if (value.equals(PageSize.LEGAL)) {
                this.lblSize.setText("215.9 x 355.6mm  /  8.5 x 14\"");
            } else if (value.equals(PageSize.EXECUTIVE)) {
                this.lblSize.setText("184 x 267mm  /  7.25 x 10.5\"");
            } else {
                this.lblSize.setText("");
            }

            radLandscape.setEnabled(true);
            radPortrait.setEnabled(true);
        } else {
            this.lblSize.setText("");
            radLandscape.setEnabled(false);
            radPortrait.setEnabled(false);
        }
    }
}