Example usage for com.itextpdf.text BaseColor RED

List of usage examples for com.itextpdf.text BaseColor RED

Introduction

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

Prototype

BaseColor RED

To view the source code for com.itextpdf.text BaseColor RED.

Click Source Link

Usage

From source file:jsimpresos.ConexionNotas.java

public void generarPdf(int idNota, String nombre, int cuenta) {
    Document documento = new Document();
    Nota nota = this.getNotaPorId(idNota);
    FileOutputStream ficheroPdf;/*from  w  w w  . j a va2  s.  c o m*/
    try {
        File carpeta = new File("C:\\archivosPuntoDeVenta");
        if (!carpeta.exists()) {
            carpeta.mkdir();
        }
        ficheroPdf = new FileOutputStream("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf");
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);
        documento.setMargins(0, 0, 0, 0);
        documento.open();
        Image foto = Image.getInstance("c:/archivosPuntoDeVenta/logo.JPG");
        foto.scaleToFit(80, 90);
        PdfPTable tabla = new PdfPTable(5);
        tabla.setWidths(new float[] { 13, 12, 25, 25, 25 });
        tabla.setWidthPercentage(100);
        PdfPCell celda = new PdfPCell();
        celda.addElement(foto);
        celda.setBorder(Rectangle.NO_BORDER);
        celda.setRowspan(6);
        tabla.addCell(celda);
        PdfPCell celda2 = new PdfPCell(
                new Paragraph("NOTA DE PEDIDO", FontFactory.getFont("Arial", 15, Font.BOLD)));
        System.out.println(nota.getUsuario());
        celda2.setColspan(3);
        celda2.setUseAscender(true);
        celda2.setBorder(Rectangle.NO_BORDER);
        celda2.setVerticalAlignment(Element.ALIGN_MIDDLE);
        tabla.addCell(celda2);
        PdfPCell celdaFecha = new PdfPCell(new Paragraph("Fecha: " + nota.getFecha()));
        celdaFecha.setBorder(Rectangle.NO_BORDER);
        tabla.addCell(celdaFecha);
        PdfPCell celda3 = new PdfPCell(new Phrase("Calle del Rayo y 2 de Abril 31a. Col. centro, Parral, Chih.",
                FontFactory.getFont("Arial", 7, Font.BOLD, BaseColor.RED)));
        celda3.setColspan(2);
        celda3.setBorder(Rectangle.NO_BORDER);
        tabla.addCell(celda3);
        PdfPCell celda4 = new PdfPCell(new Phrase("Tel. 5230073 y 6271034745",
                FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.RED)));
        celda4.setBorder(Rectangle.NO_BORDER);
        tabla.addCell(celda4);
        Paragraph p = new Paragraph("No. " + nota.getIdNota(),
                FontFactory.getFont("Arial", 13, Font.BOLD, BaseColor.RED));
        PdfPCell celda5 = new PdfPCell();
        celda5.setUseAscender(true);
        celda5.setVerticalAlignment(Element.ALIGN_MIDDLE);
        celda5.setHorizontalAlignment(Element.ALIGN_MIDDLE);
        celda5.addElement(p);
        tabla.addCell(celda5);
        PdfPCell celdanueva = new PdfPCell(
                new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        celdanueva.setBorder(Rectangle.NO_BORDER);
        celdanueva.setColspan(4);
        tabla.addCell(celdanueva);
        PdfPCell celdanueva1 = new PdfPCell(
                new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        celdanueva1.setBorder(Rectangle.NO_BORDER);
        tabla.addCell(celdanueva1);
        PdfPCell celdanueva2 = new PdfPCell(
                new Phrase("Datos del cliente", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        celdanueva2.setBorder(Rectangle.NO_BORDER);
        celdanueva2.setColspan(3);
        tabla.addCell(celdanueva2);
        PdfPCell celdanueva3 = new PdfPCell(
                new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        celdanueva3.setBorder(Rectangle.NO_BORDER);
        tabla.addCell(celdanueva3);
        if (nota.getCliente() == null) {
            PdfPCell celda6 = new PdfPCell(
                    new Phrase("Cliente:        " + nota.getNombres() + " " + nota.getApPaterno(),
                            FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
            celda6.setBorder(Rectangle.NO_BORDER);
            celda6.setColspan(3);
            tabla.addCell(celda6);
            PdfPCell celdanueva4 = new PdfPCell(
                    new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
            celdanueva4.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(celdanueva4);
            PdfPCell celda7 = new PdfPCell(new Phrase("Domicilio:       " + nota.getDomicilio(),
                    FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
            celda7.setBorder(Rectangle.NO_BORDER);
            celda7.setColspan(2);
            tabla.addCell(celda7);
            PdfPCell celda8 = new PdfPCell(new Phrase("Telfono: " + nota.getTelefono(),
                    FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
            celda8.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(celda8);

        } else {
            PdfPCell celda6 = new PdfPCell(new Phrase(
                    "Cliente:        " + nota.getCliente().getNombres() + " "
                            + nota.getCliente().getApPaterno(),
                    FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
            celda6.setBorder(Rectangle.NO_BORDER);
            celda6.setColspan(3);
            tabla.addCell(celda6);
            PdfPCell celdanueva4 = new PdfPCell(
                    new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
            celdanueva4.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(celdanueva4);
            PdfPCell celda7 = new PdfPCell(new Phrase("Domicilio:     " + nota.getCliente().getDomicilio(),
                    FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
            celda7.setBorder(Rectangle.NO_BORDER);
            celda7.setColspan(2);
            tabla.addCell(celda7);
            PdfPCell celda8 = new PdfPCell(new Phrase("Telfono: " + nota.getCliente().getTelefono(),
                    FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
            celda8.setBorder(Rectangle.NO_BORDER);
            tabla.addCell(celda8);
        }
        PdfPTable tabla2 = new PdfPTable(4);
        tabla2.setWidths(new float[] { 10, 70, 15, 15 });
        tabla2.setWidthPercentage(99.5f);
        PdfPCell celda21 = new PdfPCell(
                new Phrase("Cantidad", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK)));
        tabla2.addCell(celda21);
        PdfPCell celda22 = new PdfPCell(
                new Phrase("Artculo", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK)));
        tabla2.addCell(celda22);
        PdfPCell celda23 = new PdfPCell(
                new Phrase("Precio unitario", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK)));
        tabla2.addCell(celda23);
        PdfPCell celda24 = new PdfPCell(
                new Phrase("Total", FontFactory.getFont("Arial", 11, Font.BOLD, BaseColor.BLACK)));
        tabla2.addCell(celda24);
        double total = 0;
        for (int i = 0; i < 6; i++) {
            if (i < nota.getArticulos().size()) {
                PdfPCell celda25 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getCantidad() + "",
                        FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
                tabla2.addCell(celda25);
                PdfPCell celda26 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getServicio() + "",
                        FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
                tabla2.addCell(celda26);
                PdfPCell celda27 = new PdfPCell(new Phrase(nota.getArticulos().get(i).getPrecio() + "",
                        FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
                tabla2.addCell(celda27);
                PdfPCell celda28 = new PdfPCell(new Phrase(
                        (nota.getArticulos().get(i).getCantidad() * nota.getArticulos().get(i).getPrecio())
                                + "",
                        FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
                tabla2.addCell(celda28);
                total += nota.getArticulos().get(i).getCantidad() * nota.getArticulos().get(i).getPrecio();
            } else {
                PdfPCell celda29 = new PdfPCell(
                        new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
                tabla2.addCell(celda29);
                tabla2.addCell(celda29);
                tabla2.addCell(celda29);
                tabla2.addCell(celda29);
            }

        }
        PdfPTable tabla3 = new PdfPTable(4);
        tabla3.setWidths(new float[] { 55, 25, 15, 15 });
        tabla3.setWidthPercentage(99.5f);
        PdfPCell celda31 = new PdfPCell(new Phrase("Observaciones: " + nota.getObservaciones(),
                FontFactory.getFont("Arial", 9, BaseColor.BLACK)));
        celda31.setRowspan(4);
        tabla3.addCell(celda31);
        PdfPCell celda32 = new PdfPCell(new Phrase(
                "Suma recibida de abono : " + nota.getAbonos().get(nota.getAbonos().size() - 1).getMonto(),
                FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        celda32.setRowspan(4);
        tabla3.addCell(celda32);
        PdfPCell celda33 = new PdfPCell(
                new Phrase("Total", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        tabla3.addCell(celda33);
        PdfPCell celda34 = new PdfPCell(
                new Phrase(total + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        tabla3.addCell(celda34);
        PdfPCell celda35 = new PdfPCell(
                new Phrase("Total abonado", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        tabla3.addCell(celda35);
        double totalAbonado = 0;
        for (int i = 0; i < nota.getAbonos().size(); i++) {
            totalAbonado += nota.getAbonos().get(i).getMonto();

        }
        PdfPCell celda36 = new PdfPCell(
                new Phrase(totalAbonado + "", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        tabla3.addCell(celda36);
        PdfPCell celda37 = new PdfPCell(
                new Phrase("Saldo actual", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        tabla3.addCell(celda37);
        PdfPCell celda38 = new PdfPCell(new Phrase((total - totalAbonado) + "",
                FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        tabla3.addCell(celda38);
        PdfPCell celda39 = new PdfPCell(
                new Phrase("Fecha entrega", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        tabla3.addCell(celda39);
        PdfPCell celda40 = new PdfPCell(new Phrase(nota.getFechaEntrega(),
                FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        tabla3.addCell(celda40);
        PdfPTable tabla4 = new PdfPTable(3);
        tabla4.setWidths(new float[] { 30, 30, 30 });
        tabla4.setWidthPercentage(99.5f);
        PdfPCell celda41 = new PdfPCell(
                new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        celda41.setBorder(Rectangle.NO_BORDER);
        celda41.setColspan(3);
        tabla4.addCell(celda41);
        PdfPCell celda42 = new PdfPCell(
                new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        celda42.setBorder(Rectangle.NO_BORDER);
        tabla4.addCell(celda42);
        PdfPCell celda43 = new PdfPCell(new Phrase("Firma de conformidad del cliente: ",
                FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        celda43.setBorder(Rectangle.NO_BORDER);
        tabla4.addCell(celda43);
        PdfPCell celda44 = new PdfPCell(
                new Phrase(" ", FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK)));
        celda44.setBorder(Rectangle.NO_BORDER);
        tabla4.addCell(celda44);
        tabla4.addCell(celda41);
        tabla4.addCell(celda41);
        tabla4.addCell(celda41);
        documento.add(tabla);
        documento.add(tabla2);
        documento.add(tabla3);
        documento.add(tabla4);
        documento.add(tabla);
        documento.add(tabla2);
        documento.add(tabla3);
        documento.add(tabla4);

        documento.close();

        abrirPDF("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf");
    } catch (FileNotFoundException ex) {
        //            JOptionPane.showMessageDialog(null, "Error con el pdf");
        //            System.out.println(ex.getMessage());
        cuenta++;
        generarPdf(idNota, "nota", cuenta);
        abrirPDF("c:/archivosPuntoDeVenta/" + nombre + cuenta + ".pdf");
    } catch (DocumentException ex) {
        JOptionPane.showMessageDialog(null, "Error al guardar pdf");
        System.out.println(ex.getMessage());
    } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, "Error con el pdf");
    }
}

From source file:Model.MyFontSelector.java

License:Open Source License

/**
 * Inicializa as fontes// www . j a  v  a 2  s .  com
 * Initialize the fonts
 * @param baseFontList A List with the BaseFonts
 */
private void initFonts(ArrayList<BaseFont> baseFontList) {
    FontSelector fontSelectorTitle = new FontSelector();
    FontSelector fontSelectorBlue = new FontSelector();
    FontSelector fontSelectorGreen = new FontSelector();
    FontSelector fontSelectorRed = new FontSelector();
    FontSelector fontSelectorBlack = new FontSelector();

    for (BaseFont bf : baseFontList) {
        Font TITLE = new Font(bf, 16, Font.BOLD, BaseColor.BLACK);
        Font BLUE = new Font(bf, 14, Font.NORMAL, BaseColor.BLUE);
        Font GREEN = new Font(bf, 14, Font.NORMAL, new BaseColor(8, 138, 75));
        Font RED = new Font(bf, 14, Font.NORMAL, BaseColor.RED);
        Font BLACK = new Font(bf, 14, Font.NORMAL, BaseColor.BLACK);

        fontSelectorTitle.addFont(TITLE);
        fontSelectorBlue.addFont(BLUE);
        fontSelectorGreen.addFont(GREEN);
        fontSelectorRed.addFont(RED);
        fontSelectorBlack.addFont(BLACK);
    }

    fontSelectors.put("TITLE", fontSelectorTitle);
    fontSelectors.put("BLUE", fontSelectorBlue);
    fontSelectors.put("GREEN", fontSelectorGreen);
    fontSelectors.put("RED", fontSelectorRed);
    fontSelectors.put("BLACK", fontSelectorBlack);
}

From source file:Modelo.generatePDF.java

public void generatePDFFactura(String url, Object cliente_proveedor, ArrayList<ArticuloPedido> articulos,
        double suma) {
    try {/* w  w w  . j ava2 s  . c o  m*/
        Document documento = new Document();//Creamos el documento
        FileOutputStream ficheroPdf = new FileOutputStream(url + "_factura.pdf");//Abrimos el flujo y le asignamos nombre al pdf y su direccion
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);//Instanciamos el documento con el fichero

        documento.open();//Abrimos el documento

        Cliente c = (Cliente) cliente_proveedor;

        documento.add(new Paragraph("FACTURA", FontFactory.getFont("arial", 30, Font.BOLD, BaseColor.BLACK)));//Le indicamos el tipo de letra, el tamanio, el estilo y el color de la letra
        documento.add(new Paragraph(" "));//Realiza un salto de linea
        documento.add(new Paragraph("---DATOS--- "));//Crea un parrafo con el String que le introduzcamos
        //Le decimos que nos imprima el Dni, Nombre y Apellidos del cliente, contenidos en el objeto Cliente y le indicamos el tipo de letra, tamanio, estilo y color de la letra
        documento.add(new Paragraph("DNI: " + c.getDni(),
                FontFactory.getFont("arial", 25, Font.BOLD, BaseColor.BLACK)));
        documento.add(new Paragraph("NOMBRE: " + c.getNombre(),
                FontFactory.getFont("arial", 25, Font.BOLD, BaseColor.BLACK)));
        documento.add(new Paragraph("APELLIDOS: " + c.getApellidos(),
                FontFactory.getFont("arial", 25, Font.BOLD, BaseColor.BLACK)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));

        int cont = 0;//Este contador se usara para que cuando sea la primera vez que inserta datos en la tabla inserte los nombres de las columnas en vez de datos
        PdfPTable tabla = new PdfPTable(3);//Creamos una tabla de tres columnas

        //Insertaremos todos los articulos del pedido
        Iterator it = articulos.iterator();
        while (it.hasNext()) {
            if (cont == 0) {
                tabla.addCell("NOMBRE");
                tabla.addCell("PRECIO");
                tabla.addCell("CANTIDAD");
            }
            //Imprimimos en el PDF los nombres de los articulos del pedido, su precio y la cantidad comprada
            ArticuloPedido artPed = (ArticuloPedido) it.next();
            tabla.addCell(artPed.getArticulo().getNombre());
            tabla.addCell(Double.toString(artPed.getArticulo().getPrecio()));
            tabla.addCell(Integer.toString(artPed.getCantidad()));
            suma = suma + artPed.getArticulo().getPrecio() * artPed.getArticulo().getCantidad();//Imprimimos el coste de cada articulo en relacion a su cantidad
            cont++;
        }

        documento.add(tabla);//Aadimos la tabla al documento

        documento.add(new Paragraph(""));
        documento.add(new Paragraph("TOTAL: " + suma + " ",
                FontFactory.getFont("arial", 25, Font.NORMAL, BaseColor.RED)));//Imprimimos el coste total del pedido
        documento.close();//Cerramos el flujo con el documento

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

From source file:nl.ctmm.trait.proteomics.qcviewer.utils.ReportPDFExporter.java

License:Apache License

/**
 * Create the metrics values table for given report unit. This table will be added to the PDF document.
 *
 * @param allMetricsMap map of all QC metrics - keys and description.
 * @param reportUnit    Report unit for which to create the metrics values table.
 * @return PDF table containing metrics values of the report unit.
 *//*from  w w w.  java  2  s  .c  o  m*/
private static PdfPTable createMetricsValuesTable(final Map<String, String> allMetricsMap,
        final ReportUnit reportUnit) {
    /*
     * TODO: Column size, font size and spacing of the metrics value table. 
     */
    // Create columns names.
    final String columnNames[] = { Constants.METRICS_ID_COLUMN_NAME, Constants.DESCRIPTION_COLUMN_NAME,
            Constants.VALUE_COLUMN_NAME, Constants.METRICS_ID_COLUMN_NAME, Constants.DESCRIPTION_COLUMN_NAME,
            Constants.VALUE_COLUMN_NAME, };
    //Creation of table object.
    final PdfPTable table = new PdfPTable(columnNames.length);
    try {
        table.setSpacingBefore(TABLE_SPACING);
        //Set the table width. 
        table.setTotalWidth(COLUMN_WIDTHS);
        table.setLockedWidth(true);
        //Add table header. 
        for (int i = 0; i < TOTAL_COLUMNS; ++i) {
            final PdfPCell headerCell = new PdfPCell(new Phrase(columnNames[i], Constants.TABLE_HEADER_FONT));
            headerCell.setBackgroundColor(BaseColor.RED);
            headerCell.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.addCell(headerCell);
        }
        //Read metricsValues corresponding to reportUnit.
        final Map<String, String> metricsValues = reportUnit.getMetricsValues();
        //TODO: Split allMetricsMap in two parts such that sorted rows are properly added in the table.
        //Get all keys  
        final Object[] keyArray = allMetricsMap.keySet().toArray();
        //get all values
        final Object[] valueArray = allMetricsMap.values().toArray();
        //Calculate halfSize
        final int halfSize = keyArray.length / 2;
        for (int i = 0; i < halfSize; ++i) {
            addMetric(keyArray[i].toString(), valueArray[i].toString(), metricsValues, table);
            addMetric(keyArray[i + halfSize].toString(), valueArray[i + halfSize].toString(), metricsValues,
                    table);
        }
    } catch (final DocumentException e) {
        //DocumentException signals that an error has occurred in a Document.
        logger.log(Level.SEVERE, String.format(PDF_TABLE_EXCEPTION_MESSAGE, reportUnit.getMsrunName()), e);
    }
    return table;
}

From source file:pdf.PDFDesign.java

public PDFDesign(String s, String c, String sn, Map<String, String> fontMap) {
    size = s;//w w w  .  j a v a 2s  .c  o m
    titleLineFixedHeight = 15.0f;
    priceFontInc = 0;
    textFontInc = 0;
    styleName = sn;
    fontPaths = new FontPaths(fontMap);
    nColumns = 6;
    switch (c) {
    case "black":
        color = BaseColor.BLACK;
        break;
    case "gray":
        color = BaseColor.DARK_GRAY;
        break;
    case "red":
        color = BaseColor.RED.darker();
        break;
    case "green":
        color = BaseColor.GREEN.darker().darker().darker();
        break;
    case "blue":
        color = BaseColor.BLUE.darker().darker().darker();
        break;
    default:
        this.color = BaseColor.BLACK;
    }
    switch (size) {
    case "3x5":
        cellHeight = 83.8f;
        break;
    case "3.5x5":
        cellHeight = 97.8f;
        break;
    case "3.5x6":
        priceFontInc = 8;
        cellHeight = 97.8f;
        nColumns = 5;
        break;
    case "3.5x7":
        cellHeight = 97.8f;
        nColumns = 4;
        break;
    case "4x6":
        titleLineFixedHeight = 26.0f;
        priceFontInc = 8;
        cellHeight = 117.0f;
        nColumns = 5;
        break;
    case "4x7":
        titleLineFixedHeight = 26.0f;
        priceFontInc = 8;
        cellHeight = 117.0f;
        nColumns = 4;
        break;
    case "5x6":
        titleLineFixedHeight = 30.0f;
        priceFontInc = 13;
        textFontInc = 2;
        cellHeight = 145.0f;
        nColumns = 5;
        break;
    case "5x7":
        titleLineFixedHeight = 30.0f;
        priceFontInc = 18;
        textFontInc = 3;
        cellHeight = 145.0f;
        nColumns = 4;
        break;
    case "6x7":
        titleLineFixedHeight = 34.0f;
        priceFontInc = 26;
        textFontInc = 5;
        cellHeight = 175.0f;
        nColumns = 4;
        break;
    }
    try {
        int normal = Font.NORMAL;
        int bold = Font.BOLD;

        droidsans = BaseFont.createFont(fontPaths.getPath("droidsans"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        BaseFont impact = BaseFont.createFont(fontPaths.getPath("impact"), BaseFont.IDENTITY_H,
                BaseFont.EMBEDDED);

        switch (styleName) {
        case "style1":
            BaseFont courier = BaseFont.createFont(fontPaths.getPath("courier"), BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            initValues(42f, new Font(courier, 12 + textFontInc, normal, color),
                    new Font(courier, 9 + textFontInc, normal, color),
                    new Font(impact, 43 + priceFontInc + textFontInc, normal, color),
                    new Font(courier, 20 + textFontInc, normal, color),
                    new Font(courier, 8 + textFontInc, normal, color));
            break;
        case "style2":
            BaseFont digital7 = BaseFont.createFont(fontPaths.getPath("digital7"), BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            initValues(42f, new Font(droidsans, 10 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color),
                    new Font(digital7, 55 + priceFontInc + textFontInc, normal, color),
                    new Font(digital7, 30, normal, color), new Font(droidsans, 7 + textFontInc, normal, color));
            break;
        case "style3":
            BaseFont modern = BaseFont.createFont(fontPaths.getPath("modern"), BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            initValues(40f, new Font(droidsans, 10 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color),
                    new Font(modern, 55 + priceFontInc + textFontInc, normal, color),
                    new Font(modern, 30, normal, color), new Font(droidsans, 7 + textFontInc, normal, color));
            break;
        case "style4":
            BaseFont gothic = BaseFont.createFont(fontPaths.getPath("gothic"), BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            initValues(40f, new Font(droidsans, 10 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color),
                    new Font(gothic, 48 + priceFontInc + textFontInc, bold, color),
                    new Font(gothic, 30, bold, color), new Font(droidsans, 7 + textFontInc, normal, color));
            break;
        case "style5":
            BaseFont bookman = BaseFont.createFont(fontPaths.getPath("bookman"), BaseFont.IDENTITY_H,
                    BaseFont.EMBEDDED);
            initValues(35f, new Font(droidsans, 10 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color),
                    new Font(bookman, 45 + priceFontInc + textFontInc, bold, color),
                    new Font(bookman, 25, normal, color), new Font(droidsans, 7 + textFontInc, normal, color));
            break;

        case "style6":
            initValues(45f, new Font(droidsans, 10 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color),
                    new Font(impact, 45 + priceFontInc + textFontInc, normal, color),
                    new Font(droidsans, 20 + textFontInc, normal, color),
                    new Font(droidsans, 7 + textFontInc, normal, color));
            break;

        default:
            System.out.println("[*] Unknown Style");
            break;
        }

    } catch (DocumentException | IOException ex) {
        System.out.println("[E] " + ex.getMessage());
    }
}

From source file:pkgfinal.viewTable.java

private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed

    try {/* w w w .  j av a 2 s  .c  o  m*/

        Document document = new Document();

        PdfWriter.getInstance(document, new FileOutputStream(" " + jComboBox1.getSelectedItem() + ".pdf"));
        document.open();
        //   Image image =  Image.getInstance("save.png");
        //     document.add(new Paragraph("image"));
        //    document.add(image);
        document.add(new Paragraph("ECHO TRADERS",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD, BaseColor.RED)));
        document.add(new Paragraph(" " + jComboBox1.getSelectedItem() + " Report ",
                FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.BOLD, BaseColor.BLUE)));
        document.add(new Paragraph(new java.util.Date().toString()));
        document.add(new Paragraph("--------------------------------------------------------"));
        PdfPTable table = new PdfPTable(7);
        PdfPCell cell = new PdfPCell(new Paragraph("Purcahse_Sale Report"));

        cell.setColspan(7);

        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setBackgroundColor(BaseColor.GREEN);

        table.addCell(cell);
        String sql = "select * from '" + jComboBox1.getSelectedItem() + "' ";
        pst = conn.prepareStatement(sql);
        rs = pst.executeQuery();
        while (rs.next()) {

            String v1 = rs.getString("ID");
            String add = rs.getString("Date");
            String v2 = rs.getString("BrandName");
            String v3 = rs.getString("ManufactureName");
            String v4 = rs.getString("PurchaseQuantity");
            String v5 = rs.getString("SaleQuantity");
            String v6 = rs.getString("TotalQuantity");

            //  table.addCell("ID");
            table.addCell(v1);
            //        table.addCell(v/*.date_tf.getDateFormatString()*/);
            table.addCell(add);
            //  table.addCell("Brand name");
            table.addCell(v2);
            //  table.addCell("Manyfacture Name");
            table.addCell(v3);
            //   table.addCell("purchase Quantity");
            table.addCell(v4);
            table.addCell(v5);
            table.addCell(v6);

        }
        document.add(table);

        com.itextpdf.text.List list = new com.itextpdf.text.List(true, 20);
        list.add("Printed Date:_____________");
        list.add("Signature:_______________");
        document.add(list);

        document.close();
        JOptionPane.showMessageDialog(null, "Saved Report");
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, e);
    }
}

From source file:proyectopdf.Pleno.java

public static void main(String a[]) throws FileNotFoundException, DocumentException, IOException {
    String ae;/*from   w ww . j  a va 2 s . co  m*/
    JFileChooser jfc = new JFileChooser();
    jfc.showOpenDialog(null);
    BufferedReader archivo = new BufferedReader(new FileReader(jfc.getSelectedFile().getPath()));
    FileOutputStream nuevo = new FileOutputStream("hola.pdf");
    Document documento = new Document();
    PdfWriter.getInstance(documento, nuevo);
    documento.open();
    String w;
    while (archivo.ready()) {

        ae = archivo.readLine();

        StringTokenizer tituloI = new StringTokenizer(ae, "{T}{#T}{C}{#C}{P}{#P}{S}{#S}");

        while (tituloI.hasMoreTokens()) {
            String a1 = tituloI.nextToken();
            w = a1;

            documento.add(new Paragraph(a1, FontFactory.getFont("arial", // fuente
                    22, // tamao
                    Font.ITALIC, // estilo
                    BaseColor.BLUE)));
        }

        String a2 = "";

        while (tituloI.hasMoreTokens()) {
            a2 = tituloI.nextToken();
            documento.add(new Paragraph(a2, FontFactory.getFont("arial", // fuente
                    22, // tamao
                    Font.ITALIC, // estilo
                    BaseColor.RED)));
        }

        String a3 = "";
        while (tituloI.hasMoreTokens()) {
            a3 = tituloI.nextToken();
            documento.add(new Paragraph(a3, FontFactory.getFont("arial", // fuente
                    22, // tamao
                    Font.ITALIC, // estilo
                    BaseColor.CYAN)));
        }

        String a4 = "";
        while (tituloI.hasMoreTokens()) {
            a4 = tituloI.nextToken();
            documento.add(new Paragraph(a4, FontFactory.getFont("arial", // fuente
                    22, // tamao
                    Font.ITALIC, // estilo
                    BaseColor.YELLOW)));
        }
        System.out.println(archivo.readLine());
    }
    documento.close();
}

From source file:ro.ldir.chartpackage.GarbagePackageBuilder.java

License:Open Source License

public void writePDF(OutputStream out)
        throws DocumentException, MalformedURLException, XPathExpressionException, IOException {
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, "Cp1250", BaseFont.NOT_EMBEDDED);
    final Font hfFont = new Font(bf, 8, Font.NORMAL, BaseColor.GRAY);

    Document document = new Document(PageSize.A4, 50, 50, 50, 50);
    PdfWriter writer = PdfWriter.getInstance(document, out);
    writer.setBoxSize("art", new Rectangle(36, 54, 559, 788));

    writer.setPageEvent(new PdfPageEventHelper() {
        private int page = 0;

        @Override//from   w  w  w  .jav  a 2  s.c om
        public void onEndPage(PdfWriter writer, Document arg1) {
            page++;
            Rectangle rect = writer.getBoxSize("art");
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
                    new Phrase("Pachet mormane - \u00a9 Let's Do It, Romania!", hfFont),
                    (rect.getLeft() + rect.getRight()) / 2, rect.getTop() + 18, 0);
            ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,
                    new Phrase("- " + page + " -", hfFont), (rect.getLeft() + rect.getRight()) / 2,
                    rect.getBottom() - 18, 0);
        }
    });

    document.open();
    document.addAuthor("Let's Do It, Romania!");
    document.addTitle("Pachet mormane");
    document.addCreationDate();

    Font titleFont = new Font(bf, 24, Font.BOLD);
    Font noteFont = new Font(bf, 12, Font.NORMAL, BaseColor.RED);
    Font headerFont = new Font(bf, 12, Font.BOLD);
    Font normalFont = new Font(bf, 11);
    Font defFont = new Font(bf, 11, Font.BOLD);
    Paragraph par;
    int page = 0;

    for (Garbage garbage : garbages) {
        par = new Paragraph();
        par.setAlignment(Element.ALIGN_CENTER);
        par.add(new Chunk("Morman " + garbage.getGarbageId() + "\n", titleFont));
        par.add(new Chunk("Citi\u0163i cu aten\u0163ie!", noteFont));
        document.add(par);

        par = new Paragraph();
        par.setSpacingBefore(20);
        par.add(new Chunk("1. Date generale\n", headerFont));
        par.add(new Chunk("Jude\u0163ul: ", defFont));
        par.add(new Chunk(garbage.getCounty().getName() + "\n", normalFont));
        par.add(new Chunk("Comuna: ", defFont));
        par.add(new Chunk(garbage.getTown().getName() + "\n", normalFont));
        if (garbage.getChartedArea() != null) {
            par.add(new Chunk("Zona cartare: ", defFont));
            par.add(new Chunk(garbage.getChartedArea().getName() + "\n", normalFont));
        }
        par.add(new Chunk("Pozi\u0163ie: ", defFont));
        par.add(new Chunk(garbage.getY() + ", " + garbage.getX() + "\n", normalFont));
        par.add(new Chunk("Descriere:\n", defFont));
        par.add(new Phrase(garbage.getDescription() + "\n", normalFont));
        par.add(new Chunk("Componen\u0163\u0103 gunoi:\n", defFont));
        List list = new List();
        list.add(new ListItem(
                new Chunk("Procent plastic: " + garbage.getPercentagePlastic() + "%", normalFont)));
        list.add(new ListItem(
                new Chunk("Procent sticl\u0103: " + garbage.getPercentageGlass() + "%", normalFont)));
        list.add(new ListItem(new Chunk("Procent metale: " + garbage.getPercentageMetal() + "%", normalFont)));
        list.add(new ListItem(
                new Chunk("Procent nereciclabile: " + garbage.getPercentageWaste() + "%", normalFont)));
        par.add(list);
        document.add(par);

        par = new Paragraph();
        par.setSpacingBefore(20);
        par.add(new Chunk("2. Indica\u0163ii rutiere\n", headerFont));
        Image img = Image.getInstance(getImage(garbage));
        img.scaleToFit((float) (PageSize.A4.getWidth() * .75), (float) (PageSize.A4.getHeight() * .75));
        img.setAlignment(Element.ALIGN_CENTER);
        par.add(img);
        document.add(par);

        if (page < garbages.size() - 1)
            document.newPage();
        page++;
    }

    document.close();
}

From source file:SessionBean.ReportMgt.ReportMgtBean.java

License:Open Source License

public void createMonthlyReport(Integer startYear, Integer startMonth, Integer endYear, Integer endMonth) {
    try {//from  ww w  . j a v  a  2 s  .c  o m
        String RESULT;
        System.out.print("start");
        if (startYear.equals(endYear) && startMonth.equals(endMonth)) {
            RESULT = "d:/GeneralReport-" + startYear + "." + startMonth + ".pdf";
        } else {
            RESULT = "d:/GeneralReport-" + startYear + "." + startMonth + "-" + endYear + "." + endMonth
                    + ".pdf";
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        Document document = new Document();
        PdfWriter.getInstance(document, baos);
        document.open();
        Image image = Image.getInstance("d:/logo-4227.png");
        image.scaleAbsolute(150, 50);
        document.add(new Paragraph(""));
        document.add(image);
        Calendar targetPeriod = Calendar.getInstance();
        int month = targetPeriod.get(Calendar.MONTH) + 1;
        int year = targetPeriod.get(Calendar.YEAR);
        String reportTile;
        document.add(new Paragraph("WineXpress General Sales Report",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.BLACK)));

        if (startYear.equals(endYear) && startMonth.equals(endMonth)) {
            reportTile = startYear + "." + startMonth;
            document.add(new Paragraph(reportTile,
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
        } else {
            reportTile = startYear + "." + startMonth + "-" + endYear + "." + endMonth;
            document.add(new Paragraph(reportTile,
                    FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
        }

        document.add(new Paragraph("Generated Time: " + new Date().toString(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.PLAIN, BaseColor.BLACK)));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));

        PdfPTable table = new PdfPTable(6);
        table.getDefaultCell().setBorder(0);
        //            PdfPCell cell= new PdfPCell(new Paragraph("Wine Name"));
        //           cell.setColspan(4);
        //            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            cell.setBackgroundColor(BaseColor.BLACK);
        //           table.addCell(cell);
        table.addCell("Item ID");
        table.addCell("Item Name");
        table.addCell("Sales   (bottle)");
        table.addCell("Revenue (SGD)");
        table.addCell("Cost    (SGD)");
        table.addCell("Profit  (SGD)");

        Integer totalSales = 0;
        Double totalRevenue = 0D;
        Double totalCost = 0D;
        Double totalProfit = 0D;

        Query q1;
        q1 = em.createQuery("select i from PurchaseEntity i");
        Query q2;
        q2 = em.createQuery("select i from ItemEntity i");
        System.out.print("2");
        List<ItemEntity> itemList = q2.getResultList();
        List<PurchaseEntity> purchaseList = q1.getResultList();
        System.out.print("3");
        startMonth -= 1;
        endMonth -= 1;
        for (ItemEntity i : itemList) {
            Integer sales = 0;
            Double revenue = 0D;
            Double cost = 0D;

            for (PurchaseEntity p : purchaseList) {

                if ((p.getPurchasedDate().get(Calendar.YEAR) >= startYear)
                        && (p.getPurchasedDate().get(Calendar.YEAR) <= endYear)
                        && (p.getPurchasedDate().get(Calendar.MONTH) >= startMonth)
                        && (p.getPurchasedDate().get(Calendar.MONTH) <= endMonth)) {
                    System.out.print("looploop1");
                    Long orderId = p.getOrderId();
                    OrderEntity order = em.find(OrderEntity.class, orderId);
                    ItemEntity item = em.find(ItemEntity.class, order.getItemId());
                    System.out.print("looploop2");
                    if (item.getId().equals(i.getId())) {
                        sales += p.getQuantity();
                        revenue += p.getTotalPrice();
                        cost += p.getQuantity() * item.getCost();
                        System.out.print("looploop3");
                    }
                }
            }
            Double profit = revenue - cost;
            totalSales += sales;
            totalRevenue += revenue;
            totalCost += cost;
            totalProfit += profit;
            table.addCell(i.getId().toString());
            table.addCell(i.getItemName());
            table.addCell(sales.toString());
            table.addCell(revenue.toString());
            table.addCell(cost.toString());
            table.addCell(profit.toString());
        }

        document.add(table);

        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));

        PdfPTable table2 = new PdfPTable(6);
        table2.getDefaultCell().setBorder(0);

        table2.addCell(" ");
        table2.addCell(" ");
        table2.addCell(totalSales.toString());
        table2.addCell(totalRevenue.toString());
        table2.addCell(totalCost.toString());
        table2.addCell(totalProfit.toString());

        document.add(table2);
        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));

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

        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("Copyright  2015 All rights reserved | WineXpress",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, BaseColor.BLACK)));
        document.close();
        FileOutputStream fos = new FileOutputStream(RESULT);
        fos.write(baos.toByteArray());
        fos.close();
        System.out.println("created");

        Calendar generatedTime = Calendar.getInstance();

        ReportEntity report = new ReportEntity("GeneralReport-" + reportTile, "G", RESULT, generatedTime);
        em.persist(report);
        em.flush();

    } catch (Exception e) {
    }
}

From source file:SessionBean.ReportMgt.ReportMgtBean.java

License:Open Source License

public void createProductReport(Long productId, Integer startYear, Integer startMonth, Integer endYear,
        Integer endMonth) {//from   ww  w.jav a 2s.  c  o  m
    try {
        System.out.print("start");
        ItemEntity item = em.find(ItemEntity.class, productId);
        String RESULT;
        String reportTitle;

        if (startYear.equals(endYear) && startMonth.equals(endMonth)) {
            RESULT = "d:/ProductReport-" + item.getId() + "-" + startYear + "." + startMonth + ".pdf";
            reportTitle = startYear + "." + startMonth;
        } else {
            RESULT = "d:/ProductReport-" + item.getId() + "-" + startYear + "." + startMonth + "-" + endYear
                    + "." + endMonth + ".pdf";
            reportTitle = startYear + "." + startMonth + "-" + endYear + "." + endMonth;
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Document document = new Document();
        PdfWriter.getInstance(document, baos);
        document.open();
        Image image = Image.getInstance("d:/logo-4227.png");
        image.scaleAbsolute(150, 50);
        document.add(image);

        document.add(new Paragraph("WineXpress Product Sales Report",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.BLACK)));
        document.add(new Paragraph("Item " + item.getId() + ": " + item.getItemName() + ", " + item.getVitage(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 18, Font.BOLD, BaseColor.RED)));
        document.add(new Paragraph("Generated Time: " + new Date().toString(),
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, Font.PLAIN, BaseColor.BLACK)));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));

        PdfPTable table = new PdfPTable(5);
        table.getDefaultCell().setBorder(0);
        //            PdfPCell cell= new PdfPCell(new Paragraph("Wine Name"));
        //           cell.setColspan(4);
        //            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            cell.setBackgroundColor(BaseColor.BLACK);
        //           table.addCell(cell);
        table.addCell("Period");
        table.addCell("Sales");
        table.addCell("Revenue");
        table.addCell("Cost");
        table.addCell("Profit");
        table.addCell(" ");
        table.addCell("(bottle)");
        table.addCell("(SGD)");
        table.addCell("(SGD)");
        table.addCell("(SGD)");

        Integer totalSales = 0;
        Double totalRevenue = 0D;
        Double totalCost = 0D;
        Double totalProfit = 0D;

        Query q1;
        q1 = em.createQuery("select i from PurchaseEntity i");
        Query q2;
        q2 = em.createQuery("select i from ItemEntity i");
        System.out.print("2");
        List<ItemEntity> itemList = q2.getResultList();
        List<PurchaseEntity> purchaseList = q1.getResultList();
        System.out.print("3");

        for (int y = startYear; y <= endYear; y++) {

            for (int m = startMonth - 1; m <= endMonth - 1; m++) {
                Integer sales = 0;
                Double revenue = 0D;
                Double cost = 0D;
                System.out.print("loop");
                for (PurchaseEntity p : purchaseList) {
                    System.out.print("looploop1");
                    Long orderId = p.getOrderId();
                    OrderEntity order = em.find(OrderEntity.class, orderId);
                    ItemEntity item1 = em.find(ItemEntity.class, order.getItemId());
                    System.out.print("looploop2");
                    if (item1.getId().equals(item.getId()) && p.getPurchasedDate().get(Calendar.MONTH) == m
                            && p.getPurchasedDate().get(Calendar.YEAR) == y) {
                        sales += p.getQuantity();
                        revenue += p.getTotalPrice();
                        cost += p.getQuantity() * item.getCost();
                        System.out.print("looploop3");
                    }
                }
                Double profit = revenue - cost;
                totalSales += sales;
                totalRevenue += revenue;
                totalCost += cost;
                totalProfit += profit;
                int n = m + 1;
                table.addCell(y + "-" + n);
                table.addCell(sales.toString());
                table.addCell(revenue.toString());
                table.addCell(cost.toString());
                table.addCell(profit.toString());
            }
        }
        document.add(table);

        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));

        PdfPTable table2 = new PdfPTable(5);
        table2.getDefaultCell().setBorder(0);

        table2.addCell(" ");
        table2.addCell(totalSales.toString());
        table2.addCell(totalRevenue.toString());
        table2.addCell(totalCost.toString());
        table2.addCell(totalProfit.toString());

        document.add(table2);
        document.add(new Paragraph(
                "--------------------------------------------------------------------------------------------------------------------------"));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));

        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph(" "));
        document.add(new Paragraph("Copyright  2015 All rights reserved | WineXpress",
                FontFactory.getFont(FontFactory.TIMES_BOLD, 12, BaseColor.BLACK)));
        document.close();
        FileOutputStream fos = new FileOutputStream(RESULT);
        fos.write(baos.toByteArray());
        fos.close();
        System.out.println("created");

        Calendar generatedTime = Calendar.getInstance();
        ReportEntity report = new ReportEntity("ProductReport-" + item.getId() + "-" + reportTitle,
                item.getId().toString(), RESULT, generatedTime);
        em.persist(report);
        em.flush();

    } catch (Exception e) {
    }
}