Example usage for com.itextpdf.text Paragraph Paragraph

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

Introduction

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

Prototype

public Paragraph(float leading, String string) 

Source Link

Document

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

Usage

From source file:Beans.ArchAssistantBean.java

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

    Rationaleqaw ratq, ratq4;//  w  w w . j a  v a  2s  . 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.ManagedBeanReportes.java

public PdfPTable traerSubtabla(Tienda t) throws DocumentException {
    PdfPTable tabla_PesajeDetalle = new PdfPTable(4);
    tabla_PesajeDetalle.setWidthPercentage(100);
    tabla_PesajeDetalle.setTotalWidth(450f);
    tabla_PesajeDetalle.setLockedWidth(true);

    tabla_PesajeDetalle.setWidths(anchocol03);
    tabla_PesajeDetalle.getDefaultCell();

    PdfPCell Cell_Headers = new PdfPCell(new Paragraph("PRODUCTO", titulopequeFont));
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);

    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("UBICACIONES", titulopequeFont));
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("MINIMO", titulopequeFont));
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    Cell_Headers = new PdfPCell(new Paragraph("STOCK TOTAL", titulopequeFont));
    Cell_Headers.setBackgroundColor(BaseColor.LIGHT_GRAY);
    Cell_Headers.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    Cell_Headers.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    tabla_PesajeDetalle.addCell(Cell_Headers);

    for (StockProductoTiendaOrigen det : stockProductoTiendaOrigenFacade.lista_stock_tienda(t)) {
        tabla_PesajeDetalle.addCell(traerCelda(det.getProducto().getNombreProducto()));
        String ubicaciones_ = "";
        for (DetalleAlmacenProductos p : detalleAlmacenProductosFacade.lista_para_stock_tienda(t,
                det.getProducto())) {//from  w  ww.  j  a va 2s .  c o  m
            if (p.getUbicacionFisica().getIdUbicacionFisica() > 1) {
                ubicaciones_ = p.getUbicacionFisica().getNombreUbicacionFisica() + ";" + ubicaciones_;
            }
        }
        tabla_PesajeDetalle.addCell(traerCelda(ubicaciones_));
        tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidadMinimaStock())));
        tabla_PesajeDetalle.addCell(traerCelda(String.valueOf(det.getCantidad())));
    }
    return tabla_PesajeDetalle;
}

From source file:beans.ManagedBeanReportes.java

public PdfPCell traerCelda(String data) {
    PdfPCell resultado = new PdfPCell(new Paragraph(data, titulopequeFont));
    resultado.setHorizontalAlignment(Paragraph.ALIGN_CENTER);
    resultado.setVerticalAlignment(Paragraph.ALIGN_MIDDLE);
    return resultado;
}

From source file:bemyguest.controller.ValidationResevation.java

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

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

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

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

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

                LoadData();
                setCellTable();

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

                alert.showAndWait();

                try {

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

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

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

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

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

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

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

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

                alert.showAndWait();

                LoadData();
                setCellTable();
            }
        }

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

}

From source file:biblioteca.reportes.PdfCreator.java

License:Open Source License

/**
 * createPdf es una funcin estatica que funciona como plantilla para generar
 * reportes dinamicos, segn la necesidad del usuario.
 * @param path La direccin del archivo donde se guardar el pdf
 * @param titulo El Ttulo que llevar el pdf
 * @param encabezado Un texto que se mostrar bajo el ttulo
 * @param tabla La tabla de resultados que mostrar el pdf
 *//*from   w w  w. j  av a  2 s  .  co m*/
static public void createPdf(String path, String titulo, String encabezado, PdfPTable tabla) {
    Document document = new Document();
    // step 2
    try {
        PdfWriter.getInstance(document, new FileOutputStream(path));
        Font myFontTitle = new Font();
        myFontTitle.setFamily("Arial");
        myFontTitle.setStyle(Font.BOLD);
        myFontTitle.setSize(14);
        Font Univallef = new Font();
        Univallef.setColor(BaseColor.RED);
        Univallef.setFamily("Arial");
        Univallef.setSize(18);
        Image header = Image
                .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png"));
        header.setAlignment(Image.ALIGN_CENTER);
        header.scaleToFit(50, 75);
        Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef);
        Univalle.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph pTitulo = new Paragraph(titulo, myFontTitle);
        pTitulo.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle);
        biblioteca.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph developers = new Paragraph(
                "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle);
        developers.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph Fecha = new Paragraph("Fecha y Hora del Reporte: " + fecha, myFontTitle);
        document.open();
        // step 4
        document.add(header);
        document.add(new Paragraph("\r\n"));
        document.add(Univalle);
        document.add(new Paragraph("\r\n"));
        document.add(pTitulo);
        document.add(new Paragraph("\r\n"));
        document.add(biblioteca);
        document.add(new Paragraph("\r\n"));
        document.add(developers);
        document.add(new Paragraph("\r\n"));
        document.add(Fecha);
        document.add(new Paragraph("\r\n"));
        document.add(new Paragraph(encabezado + (tabla.getRows().size() - 1)));
        document.add(new Paragraph("\r\n"));
        document.add(tabla);
        // step 5
        document.close();
    } catch (DocumentException de) {
        System.err.println(de);
    } catch (IOException ioex) {
        System.err.println(ioex);
    }
}

From source file:biblioteca.reportes.PdfCreator.java

License:Open Source License

static public void createArrayListPdf(String path, String titulo, String encabezado,
        ArrayList<PdfPTable> tablas) {
    Document document = new Document();
    ArrayList<String> NombreTablas = new DaoReportesEstadisticas().getNombreTablas();
    //step 2/*  w ww  . j a  v  a 2 s . c om*/
    try {
        PdfWriter.getInstance(document, new FileOutputStream(path));
        Font myFontTitle = new Font();
        myFontTitle.setFamily("Arial");
        myFontTitle.setStyle(Font.BOLD);
        myFontTitle.setSize(12);
        Font Univallef = new Font();
        Univallef.setColor(BaseColor.RED);
        Univallef.setFamily("Arial");
        Univallef.setSize(18);
        Image header = Image
                .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png"));
        header.setAlignment(Image.ALIGN_CENTER);
        header.scaleToFit(50, 75);
        Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef);
        Univalle.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph pTitulo = new Paragraph(titulo, myFontTitle);
        pTitulo.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle);
        biblioteca.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph developers = new Paragraph(
                "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle);
        developers.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle);
        document.open();
        // step 4
        document.add(header);
        document.add(new Paragraph("\r\n"));
        document.add(Univalle);
        document.add(new Paragraph("\r\n"));
        document.add(pTitulo);
        document.add(new Paragraph("\r\n"));
        document.add(biblioteca);
        document.add(new Paragraph("\r\n"));
        document.add(developers);
        document.add(new Paragraph("\r\n"));
        document.add(Fecha);
        document.add(new Paragraph("\r\n"));
        for (int i = 0; i < tablas.size(); i++) {
            document.add(new Paragraph(NombreTablas.get(i)));
            document.add(new Paragraph(encabezado + (tablas.get(i).getRows().size() - 1)));
            document.add(new Paragraph("\r\n"));
            document.add(tablas.get(i));
        }
        // step 5
        document.close();
    } catch (DocumentException de) {
        System.err.println(de);
    } catch (IOException ioex) {
        System.err.println(ioex);
    }
}

From source file:biblioteca.reportes.PdfCreator.java

License:Open Source License

static public void createDinamicPdf(String path, String titulo, String encabezado,
        ArrayList<Element> contenido) {
    Document document = new Document();
    //step 2//from   w ww  .ja v  a  2  s.c om
    try {
        PdfWriter.getInstance(document, new FileOutputStream(path));
        Font myFontTitle = new Font();
        myFontTitle.setFamily("Arial");
        myFontTitle.setStyle(Font.BOLD);
        myFontTitle.setSize(12);
        Font Univallef = new Font();
        Univallef.setColor(BaseColor.RED);
        Univallef.setFamily("Arial");
        Univallef.setSize(18);
        Image header = Image
                .getInstance(PdfCreator.class.getResource("/biblioteca/gui/resources/minilogo.png"));
        header.setAlignment(Image.ALIGN_CENTER);
        header.scaleToFit(50, 75);
        Paragraph Univalle = new Paragraph("Universidad del Valle", Univallef);
        Univalle.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph pTitulo = new Paragraph(titulo, myFontTitle);
        pTitulo.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph biblioteca = new Paragraph("Biblioteca Digital EISC", myFontTitle);
        biblioteca.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph developers = new Paragraph(
                "Desarrollado por:\n Mara Cristina Bustos \n Alejandro Valds Villada", myFontTitle);
        developers.setAlignment(Paragraph.ALIGN_CENTER);
        Paragraph Fecha = new Paragraph("Fecha y Hora de Reporte: " + fecha, myFontTitle);
        //Paragraph Introduccion = new Paragraph("Reporte de usuarios registrados");
        document.open();
        // step 4
        document.add(header);
        document.add(new Paragraph("\r\n"));
        document.add(Univalle);
        document.add(new Paragraph("\r\n"));
        document.add(pTitulo);
        document.add(new Paragraph("\r\n"));
        document.add(biblioteca);
        document.add(new Paragraph("\r\n"));
        document.add(developers);
        document.add(new Paragraph("\r\n"));
        document.add(Fecha);
        document.add(new Paragraph("\r\n"));
        // document.add(Introduccion);
        document.add(new Paragraph("\r\n"));
        for (int i = 0; i < contenido.size(); i++) {
            document.add(contenido.get(i).getClass().equals(new PdfPTable(2).getClass())
                    ? (PdfPTable) contenido.get(i)
                    : contenido.get(i));
        }
        // step 5
        document.close();
    } catch (DocumentException de) {
        System.err.println(de);
    } catch (IOException ioex) {
        System.err.println(ioex);
    }
}

From source file:billerfx.FXMLBillController.java

File generatePDF() {
    File fi = null;//  ww  w.ja  v a  2 s .  c om
    try {
        Stage gg = ((Stage) imv.getParent().getScene().getWindow());
        fi = File.createTempFile("billerfx_" + gg.getTitle(), ".pdf");
        fi.deleteOnExit();

        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream(fi));
        Rectangle r = new RectangleReadOnly(207, 575);
        document.setPageSize(r);
        document.setMargins(15, 15, 0, 0);
        document.open();
        Font fontbold = FontFactory.getFont("Times-Roman", 10, Font.NORMAL);
        Font fontbold2 = FontFactory.getFont("Times-Roman", 9, Font.NORMAL);

        String[] ll = Database.getCurrentSettings();
        String ss = "-----------------------------------------------------\n";
        ss += ll[0] + "\nAddress: " + ll[1] + "\nPhone: " + ll[2] + "\n";
        String kk = Calendar.getInstance().get(Calendar.AM_PM) == Calendar.AM ? "AM"
                : (Calendar.getInstance().get(Calendar.AM_PM) == Calendar.PM ? "PM" : "");
        ss += Calendar.getInstance().get(Calendar.DATE) + "/" + (1 + Calendar.getInstance().get(Calendar.MONTH))
                + "/" + Calendar.getInstance().get(Calendar.YEAR) + " at "
                + Calendar.getInstance().get(Calendar.HOUR) + ":" + Calendar.getInstance().get(Calendar.MINUTE)
                + " " + kk + "\n";
        ss += "Table No. " + c.getText() + "     Bill No. " + a.getText() + "\n";
        ss += "-----------------------------------------------------\n";
        Paragraph para = new Paragraph(ss, fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        float[] columnWidths = { 3f, 1f };
        table.setWidths(columnWidths);
        PdfPCell defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        ObservableList ob = map.get(Integer.parseInt(gg.getTitle()));
        for (int i = 0; i < ob.size(); i++) {
            Item2 ii = (Item2) ob.get(i);
            String s1 = ii.getQuantity() + " x " + ii.getName();
            String s2 = "Rs. " + ii.getTotal();
            Paragraph para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            Paragraph para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            PdfPCell cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            PdfPCell cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }
        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.setWidths(columnWidths);
        defaultCell = table.getDefaultCell();
        defaultCell.setBorder(PdfPCell.NO_BORDER);

        String s1 = "Total:";
        String s2 = "Rs. " + h.getText();
        Paragraph para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        Paragraph para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        PdfPCell cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        PdfPCell cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        if (Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()) > 0.0) {
            s1 = "Discount:";
            s2 = "Rs. " + BillerFX.df.format(Double.parseDouble(h.getText()) - Double.parseDouble(i.getText()));
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[7].equals("1")) {
            s1 = ll[3];
            s2 = "Rs. " + k.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        if (ll[8].equals("1")) {
            s1 = ll[4];
            s2 = "Rs. " + l.getText();
            para1 = new Paragraph(s1, fontbold2);
            para1.setAlignment(Paragraph.ALIGN_LEFT);
            para2 = new Paragraph(s2, fontbold2);
            para2.setAlignment(Paragraph.ALIGN_RIGHT);
            cell1 = new PdfPCell(para1);
            cell1.setBorder(PdfPCell.NO_BORDER);
            cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
            cell2 = new PdfPCell(para2);
            cell2.setBorder(PdfPCell.NO_BORDER);
            cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);
            table.addCell(cell2);
        }

        s1 = "Grand Total:";
        s2 = "Rs. " + m.getText();
        para1 = new Paragraph(s1, fontbold2);
        para1.setAlignment(Paragraph.ALIGN_LEFT);
        para2 = new Paragraph(s2, fontbold2);
        para2.setAlignment(Paragraph.ALIGN_RIGHT);
        cell1 = new PdfPCell(para1);
        cell1.setBorder(PdfPCell.NO_BORDER);
        cell1.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell2 = new PdfPCell(para2);
        cell2.setBorder(PdfPCell.NO_BORDER);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        table.addCell(cell1);
        table.addCell(cell2);

        document.add(table);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        fontbold2 = FontFactory.getFont("Times-Roman", 8, Font.NORMAL);
        para = new Paragraph(
                "Thank You.\nThis invoice was created using BillerFX.\n (BillerFX Contact: ayushmaanbhav1008@gmail.com)\n",
                fontbold2);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        para = new Paragraph("-----------------------------------------------------\n", fontbold);
        para.setAlignment(Paragraph.ALIGN_CENTER);
        document.add(para);

        document.close();
    } catch (Exception mm) {
    }
    return fi;
}

From source file:bl.pdf.PDFFile.java

private Paragraph newLine(String txt, Font f, int alignment) {
    Paragraph ret;/*from  w  w  w  .  j  ava  2s .  co  m*/
    if (f != null) {
        ret = new Paragraph(txt, f);
    } else {
        ret = new Paragraph(txt);
    }
    if (alignment != -1) {
        ret.setAlignment(alignment);
    }
    return ret;
}

From source file:book.pdftemplates.FillTemplateHelper.java

@Override
public void onEndPage(PdfWriter writer, Document document) {
    PdfContentByte canvas = writer.getDirectContentUnder();
    // background
    canvas.addTemplate(background, 0, 0);
    try {//from w w w .ja  va  2s.  c o m
        // date
        ColumnText ct = new ColumnText(canvas);
        ct.setSimpleColumn(date);
        ct.addText(new Chunk(today, font));
        ct.go();
        // footer (page X of Y)
        ct.setSimpleColumn(footer);
        ct.addText(new Chunk("page " + writer.getPageNumber(), font));
        ct.addText(new Chunk(Image.getInstance(total), 0, 0));
        ct.go();
        // from address
        ct.setSimpleColumn(from);
        ct.addElement(new Paragraph(sender, font));
        ct.go();
        // to address
        ct.setSimpleColumn(to);
        ct.addElement(new Paragraph(receiver, font));
        ct.go();
    } catch (DocumentException e) {
        // can never happen, but if it does, we want to know!
        throw new ExceptionConverter(e);
    }
}