Example usage for com.itextpdf.text Document close

List of usage examples for com.itextpdf.text Document close

Introduction

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

Prototype

boolean close

To view the source code for com.itextpdf.text Document close.

Click Source Link

Document

Has the document already been closed?

Usage

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

public void createPdfVak() {
    Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext()
            .getRequestParameterMap();//from  w w  w .  jav a2s .c  o  m
    String KlasId = params.get("klasId2");
    String VakId = params.get("vakId");
    int klasId = Integer.parseInt(KlasId);
    int id = Integer.parseInt(VakId);
    Document document = new Document();
    Vak vak = service.getVak(id);
    List<Test> testen = vak.getTestList();
    Klas klas = service.getKlas(klasId);

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

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

        document.open();

        Font font = FontFactory.getFont("Calibri");
        Font fontbold = FontFactory.getFont("Calibri", Font.BOLD);

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

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

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

        for (Test test : testen) {
            List<Score> scores = test.getScoreList();
            for (Score score : scores) {
                Student student = score.getStudentId();
                PdfPCell cellTest = new PdfPCell(new Paragraph(test.getBeschrijving(), font));
                PdfPCell cellStudent = new PdfPCell(new Paragraph(student.getVoornaam(), font));
                PdfPCell cellScore = new PdfPCell(new Paragraph(score.getScore().toString()));

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

        document.add(new Phrase("Klas: ", font));
        document.add(new Phrase(klas.getNummer(), font));
        document.add(new Phrase("  Vak: ", font));
        document.add(new Phrase(vak.getNaam(), font));
        document.add(table);

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

    }
}

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

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

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

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

        document.open();

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

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

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

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

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

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

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

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

    }

}

From source file:be.thomasmore.service.CreatePDFServiceImp.java

@Override
public void createPDF(List<Score> scores) {
    try {//w  ww.j  a  va2 s.  co  m
        OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        document.add(new Paragraph("Scores"));
        document.add(new Paragraph(new Date().toString()));

        document.addAuthor("Projectgroep 4");
        document.addCreator("Projectgroep 4");
        document.addTitle("ScoreTracker");

        //Create Paragraph
        Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));

        //New line
        paragraph.add(new Paragraph(" "));
        paragraph.add("Scores");
        paragraph.add(new Paragraph(" "));
        document.add(paragraph);

        //Create a table in PDF
        PdfPTable pdftabel = new PdfPTable(4);
        PdfPCell cell1 = new PdfPCell(new Phrase("Student"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Vak"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Test"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        cell1 = new PdfPCell(new Phrase("Score"));
        cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
        pdftabel.addCell(cell1);

        pdftabel.setHeaderRows(1);

        for (Score score : scores) {
            pdftabel.addCell(score.getStudent().getNaam());
            pdftabel.addCell(score.getTest().getVak().getNaam());
            pdftabel.addCell(score.getTest().getNaam());
            int resultaat = score.getScore();
            pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal());
        }

        document.add(pdftabel);
        document.addCreationDate();
        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:be.thomasmore.service.CreatePDFServiceImp.java

@Override
public void createPDFVoorStudent(ArrayList<ArrayList<Score>> puntenlijst, List<Double> gemiddeldelijst,
        Double totaalGemiddelde) {
    try {/*from  w  w  w .j  a  v  a2  s . co  m*/
        OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf"));

        Document document = new Document();
        PdfWriter.getInstance(document, file);

        document.open();
        document.add(new Paragraph("Scores"));
        document.add(new Paragraph(puntenlijst.get(0).get(0).getStudent().getNaam()));
        document.add(new Paragraph(new Date().toString()));

        document.addAuthor("Projectgroep 4");
        document.addCreator("Projectgroep 4");
        document.addTitle("ScoreTracker");

        //Create Paragraph
        Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));

        //New line
        paragraph.add(new Paragraph(" "));
        paragraph.add("Scores");
        paragraph.add(new Paragraph(" "));
        document.add(paragraph);

        for (int i = 0; i < puntenlijst.size(); i++) {
            //Create a table in PDF
            PdfPTable pdftabel = new PdfPTable(2);
            //vak invullen
            paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
            paragraph.add(new Paragraph(puntenlijst.get(i).get(0).getTest().getVak().getNaam()));
            document.add(paragraph);

            PdfPCell cell1 = new PdfPCell(new Phrase("Test"));
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            pdftabel.addCell(cell1);

            cell1 = new PdfPCell(new Phrase("Score"));
            cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
            pdftabel.addCell(cell1);

            pdftabel.setHeaderRows(1);

            for (Score score : puntenlijst.get(i)) {
                pdftabel.addCell(score.getTest().getNaam());
                int resultaat = score.getScore();
                pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal());
            }

            document.add(pdftabel);

            //gemmidelde per vak invoeren
            paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
            paragraph.add(new Paragraph("Gemiddelde: " + gemiddeldelijst.get(i).toString()));
            document.add(paragraph);
        }
        paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
        paragraph.add(new Paragraph("Algemeen gemiddelde: " + totaalGemiddelde));
        document.add(paragraph);
        document.addCreationDate();
        document.close();
        file.close();

    } catch (Exception e) {

        e.printStackTrace();
    }
}

From source file:be.zenodotus.creatie.GeneratePDF.java

License:Open Source License

public String vakantieAfdruk(Context context, String name, int jaar) {
    this.context = context;
    PdfWriter w = null;/*w w w  .  j  a  va2  s  . c o  m*/
    Document d = new Document(PageSize.A4.rotate(), 5, 5, 10, 10);
    d.setPageCount(3);
    String fileName = name;
    String file = name;
    GregorianCalendar datum = new GregorianCalendar();
    datum.set(GregorianCalendar.YEAR, jaar);

    String[] maanden = { "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus",
            "September", "Oktober", "November", "December" };
    int[] dagen = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    VerlofDao dao = new VerlofDao(context);
    FeestdagDao feestdagDao = new FeestdagDao(context);
    WerkdagDao werkdagDao = new WerkdagDao(context);
    File folder = new File(context.getFilesDir(), "pdfs");
    folder.mkdirs();
    if (datum.isLeapYear(jaar)) {
        dagen[1] = 29;
    }
    File temp = null;
    temp = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
            "Jacqueline" + jaar + ".pdf");
    fileName = temp.toString();
    try {
        dao.open();
        ArrayList<Verlof> verloflijst = dao.getAlleVerlovenPerJaar(jaar);
        w = PdfWriter.getInstance(d, new FileOutputStream(temp));
        d.open();
        d.addAuthor("Jacqueline Vandenbroecke");
        d.addCreationDate();
        d.addCreator("Verlofplanner");
        d.addTitle("Vakantie " + jaar + " van Jacqueline Vandenbroecke");
        Font standaard = FontFactory.getFont(FontFactory.HELVETICA, 8);
        Font standaardBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD);
        Paragraph gegeven = new Paragraph("Jacqueline Vandenbroecke Verlof " + jaar + "\n", standaardBold);
        gegeven.setAlignment(Paragraph.ALIGN_CENTER);
        d.add(gegeven);

        for (int paginas = 0; paginas < 2; paginas++) {
            int aantal = 0;
            if (paginas == 1) {
                d.newPage();
                aantal = 6;
            }
            PdfPTable table = new PdfPTable(6);
            for (int i = aantal; i < (aantal + 6); i++) {
                PdfPCell cell = new PdfPCell(new Paragraph(maanden[i], standaardBold));
                cell.setBorder(1);
                table.addCell(cell);
            }
            int dag = 1;
            int k = aantal;
            for (int i = aantal; i < (aantal + 6); i++) {
                for (int j = 0; j < 32; j++) {
                    if (k > ((aantal + 6) - 1)) {
                        k = aantal;
                        dag++;
                    }
                    if (dag > dagen[k]) {
                        PdfPCell cell = new PdfPCell(new Paragraph("", standaard));
                        table.addCell(cell);
                        k++;
                    } else {
                        SimpleDateFormat formatterDag = new SimpleDateFormat("dd");
                        SimpleDateFormat formatterWeek = new SimpleDateFormat("EEE");
                        datum.set(jaar, k, dag);
                        PdfPTable dagTabel = new PdfPTable(4);
                        PdfPCell cellDag = new PdfPCell(
                                new Paragraph(formatterDag.format(datum.getTime()), standaard));
                        PdfPCell cellWeek = new PdfPCell(
                                new Paragraph(formatterWeek.format(datum.getTime()), standaard));
                        ArrayList<Verlof> verlof = new ArrayList<Verlof>();
                        for (int z = 0; z < verloflijst.size(); z++) {
                            if (((verloflijst.get(z).getDag() + 1) == dag)
                                    && (verloflijst.get(z).getMaand() == k)) {
                                verlof.add(verloflijst.get(z));

                            }
                        }
                        feestdagDao.open();
                        Feestdag feestdag = feestdagDao.getFeestdag(jaar, datum.get(GregorianCalendar.MONTH),
                                datum.get(GregorianCalendar.DATE));
                        feestdagDao.close();
                        werkdagDao.open();
                        java.util.List<Werkdag> weekend = werkdagDao.getWeekend();
                        werkdagDao.close();
                        String Verlof = "";
                        String uur = "";
                        if (verlof.size() > 0) {
                            if (verlof.size() > 1) {
                                Verlof = verlof.get(0).getVerlofsoort() + "\n" + verlof.get(1).getVerlofsoort();
                                uur = verlof.get(0).getUrental() + "\n" + verlof.get(1).getUrental();
                            } else {
                                Verlof = verlof.get(0).getVerlofsoort();
                                uur = verlof.get(0).getUrental();
                            }

                        }
                        PdfPCell cellVerlof = new PdfPCell(new Paragraph(Verlof, standaard));
                        PdfPCell uren = new PdfPCell(new Paragraph(uur, standaard));
                        if (verlof.size() > 0) {
                            BaseColor kleur = new BaseColor(Color.GRAY);
                            cellVerlof.setBackgroundColor(kleur);
                            uren.setBackgroundColor(kleur);
                            cellDag.setBackgroundColor(kleur);
                            cellWeek.setBackgroundColor(kleur);
                        }
                        for (int z = 0; z < weekend.size(); z++) {
                            if ((formatterWeek.format(datum.getTime())).equals(weekend.get(z).getDag())) {
                                BaseColor kleur = new BaseColor(Color.LTGRAY);
                                cellVerlof.setBackgroundColor(kleur);
                                uren.setBackgroundColor(kleur);
                                cellDag.setBackgroundColor(kleur);
                                cellWeek.setBackgroundColor(kleur);
                            }
                        }
                        if (feestdag != null) {
                            BaseColor kleur = new BaseColor(Color.GREEN);
                            uren.setBackgroundColor(kleur);
                            cellVerlof.setBackgroundColor(kleur);
                            uren.setBackgroundColor(kleur);
                            cellDag.setBackgroundColor(kleur);
                            cellWeek.setBackgroundColor(kleur);
                        }
                        dagTabel.addCell(cellDag);
                        dagTabel.addCell(cellWeek);
                        dagTabel.addCell(cellVerlof);
                        dagTabel.addCell(uren);
                        table.addCell(dagTabel);
                        k++;
                    }
                }

            }
            d.add(table);
            dao.close();
        }
    } catch (Exception ex) {

        ex.printStackTrace();

    } finally {
        d.close();
        w.close();
    }
    return fileName;
}

From source file:bean.RecommendationBean.java

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

    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(file));
    document.open();//from  ww  w  .  jav a2  s .c  o m
    document.add(new Paragraph("insert letter head"));
    document.add(new Paragraph("Recommendation Report"));
    document.add(new Paragraph("date:" + "CURRENT DATE"));
    document.add(new Paragraph("date encoded:" + reportDateEncoded));
    document.add(new Paragraph(selectedProspect.getLastName() + "," + selectedProspect.getFirstName()
            + selectedProspect.getMiddleName()));
    //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: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 a  v a  2s.  com*/
    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;//from w  w w.j  a  v a  2 s  .  c  o  m
    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();// w  w w  . ja v  a 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();/*w w  w  .ja  v a  2s . com*/
    }

    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();
    }
}