Example usage for com.itextpdf.text BaseColor BLACK

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

Introduction

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

Prototype

BaseColor BLACK

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

Click Source Link

Usage

From source file:pkgAgenda_Virtual.frmActividades.java

public void PDFpersonales() throws SQLException {
    Document documento = new Document();
    FileOutputStream FacturaPdf;/*  ww w. j a v  a 2s  . c o  m*/

    try {
        FacturaPdf = new FileOutputStream("archives/ActividadesPersonales.pdf");

        PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
        com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

    } catch (DocumentException | FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

    try {
        Calendar fecha = Calendar.getInstance();
        documento.open();
        com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
        imagen.setAbsolutePosition(0f, 0f);
        documento.add(imagen);
        Paragraph AV = new Paragraph("Agenda Virtual",
                FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
        AV.setAlignment(Element.ALIGN_RIGHT);
        documento.add(AV);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades Personales de " + frmLogin.usuario));
        documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));

        PdfPTable tblHoy = new PdfPTable(4);
        PdfPTable tblAntes = new PdfPTable(4);
        PdfPTable tblDespues = new PdfPTable(4);
        tblHoy.addCell("Titulo");
        tblHoy.addCell("Fecha");
        tblHoy.addCell("Hora");
        tblHoy.addCell("Lugar");
        tblAntes.addCell("Titulo");
        tblAntes.addCell("Fecha");
        tblAntes.addCell("Hora");
        tblAntes.addCell("Lugar");
        tblDespues.addCell("Titulo");
        tblDespues.addCell("Fecha");
        tblDespues.addCell("Hora");
        tblDespues.addCell("Lugar");

        //sdfhfjhsdfsd
        int valor;

        rs = H.Buscar("SELECT nom_act, fecha_act, hora_act, lugar_act FROM Actividades WHERE cod_usu = "
                + H.Usuario + " AND id_tipoact = 2");
        while (rs.next()) {
            String fecharecibida = rs.getString(2).substring(0, 10);
            valor = H.FechaAnterior(fecharecibida);
            if (valor == 2) {
                tblHoy.addCell(H.desencriptar(rs.getString(1)));
                tblHoy.addCell(fecharecibida);
                tblHoy.addCell(rs.getString(3).substring(0, 5));
                tblHoy.addCell(H.desencriptar(rs.getString(4)));
            } else if (valor == 1) {
                tblAntes.addCell(H.desencriptar(rs.getString(1)));
                tblAntes.addCell(fecharecibida);
                tblAntes.addCell(rs.getString(3).substring(0, 5));
                tblAntes.addCell(H.desencriptar(rs.getString(4)));
            } else if (valor == 0) {
                tblDespues.addCell(H.desencriptar(rs.getString(1)));
                tblDespues.addCell(fecharecibida);
                tblDespues.addCell(rs.getString(3).substring(0, 5));
                tblDespues.addCell(H.desencriptar(rs.getString(4)));
            }
        }

        //askjdhskfjhdf
        documento.add(new Paragraph("Actividades Pasadas"));
        documento.add(new Paragraph(" "));
        documento.add(tblAntes);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades de Hoy"));
        documento.add(new Paragraph(" "));
        documento.add(tblHoy);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades Futuras"));
        documento.add(new Paragraph(" "));
        documento.add(tblDespues);
        documento.add(new Paragraph(" "));
        documento.add(P);
        documento.close();
    } catch (DocumentException | IOException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

}

From source file:pkgAgenda_Virtual.frmActividades.java

public void PDFdeestudio() throws SQLException {
    Document documento = new Document();
    FileOutputStream FacturaPdf;//from   w  w  w.  ja  va 2s. c  om

    try {
        FacturaPdf = new FileOutputStream("archives/ActividadesdeEstudio.pdf");

        PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
        com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

    } catch (DocumentException | FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

    try {
        Calendar fecha = Calendar.getInstance();
        documento.open();
        com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
        imagen.setAbsolutePosition(0f, 0f);
        documento.add(imagen);
        Paragraph AV = new Paragraph("Agenda Virtual",
                FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
        AV.setAlignment(Element.ALIGN_RIGHT);
        documento.add(AV);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades de Estudio de " + frmLogin.usuario));
        documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));

        PdfPTable tblHoy = new PdfPTable(4);
        PdfPTable tblAntes = new PdfPTable(4);
        PdfPTable tblDespues = new PdfPTable(4);
        tblHoy.addCell("Asignatura");
        tblHoy.addCell("Tarea");
        tblHoy.addCell("Fecha");
        tblHoy.addCell("Hora");
        tblAntes.addCell("Asignatura");
        tblAntes.addCell("Tarea");
        tblAntes.addCell("Fecha");
        tblAntes.addCell("Hora");
        tblDespues.addCell("Asignatura");
        tblDespues.addCell("Tarea");
        tblDespues.addCell("Fecha");
        tblDespues.addCell("Hora");

        //sdfhfjhsdfsd
        int valor;

        rs = H.Buscar("SELECT nom_act, des_act, fecha_act, hora_act FROM Actividades WHERE cod_usu = "
                + H.Usuario + " AND id_tipoact = 1");
        while (rs.next()) {
            String fecharecibida = rs.getString(3).substring(0, 10);
            valor = H.FechaAnterior(fecharecibida);
            if (valor == 2) {
                tblHoy.addCell(H.desencriptar(rs.getString(1)));
                tblHoy.addCell(H.desencriptar(rs.getString(2)));
                tblHoy.addCell(fecharecibida);
                tblHoy.addCell(rs.getString(4).substring(0, 5));
            } else if (valor == 1) {
                tblAntes.addCell(H.desencriptar(rs.getString(1)));
                tblAntes.addCell(H.desencriptar(rs.getString(2)));
                tblAntes.addCell(fecharecibida);
                tblAntes.addCell(rs.getString(4).substring(0, 5));
            } else if (valor == 0) {
                tblDespues.addCell(H.desencriptar(rs.getString(1)));
                tblDespues.addCell(H.desencriptar(rs.getString(2)));
                tblDespues.addCell(fecharecibida);
                tblDespues.addCell(rs.getString(4).substring(0, 5));
            }
        }

        //askjdhskfjhdf
        documento.add(new Paragraph("Actividades Pasadas"));
        documento.add(new Paragraph(" "));
        documento.add(tblAntes);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades de Hoy"));
        documento.add(new Paragraph(" "));
        documento.add(tblHoy);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Actividades Futuras"));
        documento.add(new Paragraph(" "));
        documento.add(tblDespues);
        documento.add(new Paragraph(" "));
        documento.add(P);
        documento.close();
    } catch (DocumentException | IOException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

}

From source file:pkgAgenda_Virtual.frmAgenda.java

public void PDF() throws SQLException {
    Document documento = new Document();
    FileOutputStream FacturaPdf;/*w w  w.j a  v  a  2 s  . c o m*/

    try {
        FacturaPdf = new FileOutputStream("archives/Notas.pdf");

        PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
        com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

    } catch (DocumentException | FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

    try {
        Calendar fecha = Calendar.getInstance();
        documento.open();
        com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
        imagen.setAbsolutePosition(0f, 0f);
        documento.add(imagen);
        Paragraph AV = new Paragraph("Agenda Virtual",
                FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
        AV.setAlignment(Element.ALIGN_RIGHT);
        documento.add(AV);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Notas de " + frmLogin.usuario));
        documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        PdfPTable tabla = new PdfPTable(2);
        tabla.addCell("Titulo");
        tabla.addCell("Descripcion");

        //sdfhfjhsdfsd

        rs = H.Buscar(
                "SELECT nom_nota, des_nota FROM Notas WHERE cod_usu = " + H.Usuario + " ORDER BY nom_nota ASC");
        while (rs.next()) {
            tabla.addCell(rs.getString(1));
            tabla.addCell(rs.getString(2));
        }

        //askjdhskfjhdf
        documento.add(tabla);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(P);
        documento.close();
    } catch (DocumentException | IOException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

}

From source file:pkgAgenda_Virtual.frmVerContactos.java

public void PDF() throws SQLException {
    Document documento = new Document();
    FileOutputStream FacturaPdf;//w  w w.j  a va 2s . c om

    try {
        FacturaPdf = new FileOutputStream("archives/Contactos.pdf");

        PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf);
        com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788);
        writer.setBoxSize("art", rct);
        HeaderFooter event = new HeaderFooter();
        writer.setPageEvent(event);

    } catch (DocumentException | FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

    try {
        Calendar fecha = Calendar.getInstance();
        documento.open();
        com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png");
        imagen.setAbsolutePosition(0f, 0f);
        documento.add(imagen);
        Paragraph AV = new Paragraph("Agenda Virtual",
                FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK));
        AV.setAlignment(Element.ALIGN_RIGHT);
        documento.add(AV);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph("Contactos de " + frmLogin.usuario));
        documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/"
                + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + "  "
                + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE)));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        PdfPTable tabla = new PdfPTable(4);
        tabla.addCell("Apellidos");
        tabla.addCell("Nombres");
        tabla.addCell("Telefono");
        tabla.addCell("Correo");

        //sdfhfjhsdfsd
        rs = H.Buscar("SELECT ape_contacto FROM Contactos WHERE cod_usu = " + H.Usuario + "");
        while (rs.next()) {
            cantidad_contactos += 1;
        }
        contactosdesordenados = new String[cantidad_contactos];
        rs = H.Buscar("SELECT ape_contacto FROM Contactos WHERE cod_usu = " + H.Usuario + "");
        while (rs.next()) {
            contactosdesordenados[num_contacto] = H.desencriptar(rs.getString(1));
            num_contacto += 1;
        }
        contactosordenados = new String[cantidad_contactos];
        Arrays.sort(contactosdesordenados);
        contactosordenados = contactosdesordenados;
        for (int i = 0; i < contactosordenados.length; i++) {
            if (!"".equals(contactosordenados[i].toString())) {
                rs = H.Buscar(
                        "SELECT ape_contacto, nom_contacto, tel1_contacto, correo_contacto FROM Contactos WHERE ape_contacto = '"
                                + H.encriptar(contactosordenados[i].toString()) + "'");
                while (rs.next()) {
                    tabla.addCell(H.desencriptar(rs.getString(1)));
                    tabla.addCell(H.desencriptar(rs.getString(2)));
                    tabla.addCell(rs.getString(3));
                    tabla.addCell(H.desencriptar(rs.getString(4)));
                }
            }
        }

        //askjdhskfjhdf
        documento.add(tabla);
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(new Paragraph(" "));
        documento.add(P);
        documento.close();
    } catch (DocumentException | IOException ex) {
        JOptionPane.showMessageDialog(null, ex.toString());
    }

}

From source file:printers.AbstractHorariosPrinter.java

License:Open Source License

private PdfPCell createCeldaHorarioItem(HorarioItem h, int fila, int columna, int numColumnas, int numFilas) {
    Paragraph p;//  w w  w .  j  a v a2 s .  co m
    PdfPCell c;
    if (!h.isHuecoLibre()) {

        p = getParagraphForAsignatura(h);
        c = new PdfPCell(p);
        c.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        c.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        //Color col = h.getAsignatura().getColorEnTablaDeHorarios();
        Color col = h.getTramo().getColorEnTablaDeHorarios();
        c.setBackgroundColor(new BaseColor(col.getRed(), col.getGreen(), col.getBlue()));
        c.setPadding(5);
        c.setBorderColor(BaseColor.BLACK);
        c.setBorderWidth(1);
        c.setUseBorderPadding(false);
        c.setUseVariableBorders(true);

    } else {
        p = new Paragraph("");//"C"+h.getNumcasilla()+" D"+h.getDiaSemana()+" "+h.getRangoHoras().getInicio());
        c = new PdfPCell(p);
        c.setUseVariableBorders(true);
        c.setBorderColor(BaseColor.LIGHT_GRAY);
        c.setBorderWidth(.3F);
        //            c.setBorder(Rectangle.NO_BORDER);
        if (columna == numColumnas - 1) {
            c.setBorderColorRight(BaseColor.BLACK);
        }
        //            if (fila == numFilas - 1) {
        //                c.setBorder(Rectangle.BOTTOM);
        //            }
        //            if ((columna == numColumnas - 1) && (fila == numFilas - 1)) {
        //                c.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
        //            }
    }

    if (h.getNumeroDeCasillasQueOcupa() > 1) {
        c.setRowspan(h.getNumeroDeCasillasQueOcupa());

    }

    return c;
}

From source file:printom.PDFCreator.java

public static void createLabel(int aLabelType, int aJobNum, char aJobIdentifier, String aCustName,
        String aItemName, String aItemCode, String aDate, String aPOrderNum, int aInputPcs) {

    String myJobNum = String.valueOf(aJobNum);
    char myJobIdentifier = aJobIdentifier;
    String myCustName = aCustName;
    String myItemName = aItemName;
    String myItemCode = aItemCode;
    String myDate = aDate;/*from  w  w w .  j a va  2 s .  c o m*/
    String myPOrderNum = aPOrderNum;
    String myInputPcs = String.valueOf(aInputPcs);

    try {
        String src = "";
        if (aLabelType == 1) {
            src = CTNLABEL;
        }
        String dest = RESULTLABEL;

        Font timesJob = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.BOLD, BaseColor.WHITE);
        Font timesDef = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);

        PdfReader reader = new PdfReader(src);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
        PdfContentByte canvas = stamper.getOverContent(1);

        for (int k = 0; k < 3; k++) {

            //Positions
            int[] x = { 298, 350, 125, 80, 80, 80, 80, 120 };
            int[] y = { 562, 562, 518, 498, 479, 459, 440, 420 };

            if (k == 1) {
                for (int j = 0; j < 8; j++) {
                    y[j] = y[j] - 186;
                }
            }

            if (k == 2) {
                for (int j = 0; j < 8; j++) {
                    y[j] = y[j] - 372;
                }
            }

            for (int i = 0; i < 2; i++) {

                if (i == 1) {
                    for (int j = 0; j < 8; j++) {
                        x[j] = x[j] + 372;
                    }
                }

                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myJobNum, timesJob), x[0],
                        y[0], 0);
                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                        new Phrase(String.valueOf(myJobIdentifier), timesDef), x[1], y[1], 0);
                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myCustName, timesDef), x[2],
                        y[2], 0);
                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myItemName, timesDef), x[3],
                        y[3], 0);
                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myItemCode, timesDef), x[4],
                        y[4], 0);
                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myDate, timesDef), x[5], y[5],
                        0);
                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myPOrderNum, timesDef), x[6],
                        y[6], 0);
                ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myInputPcs, timesDef), x[7],
                        y[7], 0);
            }
        }
        stamper.close();
        reader.close();

    } catch (IOException | DocumentException ex) {
        Logger.getLogger(PDFCreator.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:printom.PDFCreator.java

public static void createReport(int aJobNum, char aJobIdentifier, String aCustName, String aItemName,
        String aItemCode, String aDate, String aPOrderNum, int aInputPcs, int aQtyWithOvers, int aNumContainers,
        String aInputContainer) {

    String myJobNum = String.valueOf(aJobNum);
    char myJobIdentifier = aJobIdentifier;
    String myCustName = aCustName;
    String myItemName = aItemName;
    String myItemCode = aItemCode;
    String myDate = aDate;//from   w ww. java2 s  .c om
    String myPOrderNum = aPOrderNum;
    String myInputPcs = String.valueOf(aInputPcs);
    int myQtyWithOvers = aQtyWithOvers;
    int myNumContainers = aNumContainers;
    String myInputContainer = aInputContainer;

    double amount = myQtyWithOvers;
    DecimalFormat formatter = new DecimalFormat("#,###");

    String myStrQtyWithOvers = formatter.format(amount);

    try {
        String src = REPORT;
        String dest = RESULTREPORT;

        Font timesJob = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD, BaseColor.WHITE);
        Font timesDef = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);

        PdfReader reader = new PdfReader(src);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(dest));
        PdfContentByte canvas = stamper.getOverContent(1);

        int[] x = { 441, 510, 426, 87, 87, 87, 426, 307, 218, 325, 426 };
        int[] y = { 547, 547, 473, 450, 428, 473, 450, 325, 385, 385, 428 };

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myJobNum, timesJob), x[0], y[0], 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                new Phrase(String.valueOf(myJobIdentifier), timesDef), x[1], y[1], 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myCustName, timesDef), x[2], y[2], 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myItemName, timesDef), x[3], y[3], 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myItemCode, timesDef), x[4], y[4], 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myDate, timesDef), x[5], y[5], 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myPOrderNum, timesDef), x[6], y[6],
                0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myInputPcs, timesDef), x[7], y[7], 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myStrQtyWithOvers, timesDef), x[8],
                y[8], 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                new Phrase("(" + String.valueOf(myNumContainers) + " cases with overs)", timesDef), x[9], y[9],
                0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myInputContainer, timesDef), x[10],
                y[10], 0);
        stamper.close();
        reader.close();

    } catch (IOException | DocumentException ex) {
        Logger.getLogger(PDFCreator.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:printom.PDFCreator.java

public static void createBOL(ArrayList<Shipment> aShipmentList, int aTemplate) {

    ArrayList<Shipment> shipmentList = aShipmentList;
    Order chosenOrder = shipmentList.get(0).getChosenOrder();

    String bolCode = shipmentList.get(0).getBolCode();
    String bolFileName = bolCode + ".pdf";

    String myCustName = Customer.getCustomerName(chosenOrder.getCustID());
    String myShipDate = Prompter.dateString(shipmentList.get(0).getDateShipped());
    String myCarrier = shipmentList.get(0).getCarrier();
    String myInstructs = shipmentList.get(0).getInstructions();
    Address myAddress = Address.retAddress(shipmentList.get(0).getChosenOrder().getShipAddressID());

    try {/* w w  w  . java 2  s .c om*/

        //BaseFont bf1 = BaseFont.createFont("c:/windows/fonts/consola.ttf",
        //BaseFont.WINANSI, BaseFont.EMBEDDED);
        Font timesJob = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD, BaseColor.WHITE);
        Font timesDef = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK);

        Font courierNorm = new Font(Font.FontFamily.COURIER, 11, Font.NORMAL, BaseColor.BLACK);
        Font courierSBig = new Font(Font.FontFamily.COURIER, 13, Font.NORMAL, BaseColor.BLACK);

        // step 1
        Document document = new Document(PageSize.LETTER, 18, 18, 126, 54);
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(bolFileName));
        // step 3
        document.open();
        // step 4
        // we set the compression to 0 so that we can read the PDF syntax
        writer.setCompressionLevel(0);
        // writes something to the direct content using a convenience method
        PdfContentByte canvas = writer.getDirectContentUnder();

        // Graphic Letterheard
        Image image = Image.getInstance("AresLH.jpg");
        image.scalePercent(50f);
        image.setAbsolutePosition(43, 680);

        if (aTemplate == 1)
            document.add(image);

        // 11" = 792
        // 8.5 = 612
        // TEXT SIZE = 11
        // LINE SPACING = 11
        // PARAGRAPH SPACE = 3 * 11
        int myPageWidth = 612;
        int myPageHeight = 792;
        int myTopMargin = 655;
        int myTopSubMargin = 622;
        int myPageLeftMargin = 54;

        // HEADER LINES
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ARES BOL# " + bolCode, courierNorm),
                myPageLeftMargin, myTopMargin, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("DATE: " + myShipDate, courierNorm),
                myPageWidth - myPageLeftMargin, myTopMargin, 0);

        // CONSIGNEE ADDRESS
        int myAddressStartY = myTopSubMargin;
        int myCurrentY = myTopSubMargin;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CONSIGNEE", courierNorm),
                myPageLeftMargin, myCurrentY, 0);

        myCurrentY -= 11;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ADDRESS:", courierNorm),
                myPageLeftMargin, myCurrentY, 0);

        myCurrentY = myAddressStartY;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                new Phrase(myAddress.getAttention(), courierNorm), 125, myCurrentY, 0);

        myCurrentY -= 11;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myAddress.getAddress1(), courierNorm),
                125, myCurrentY, 0);

        myCurrentY -= 11;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                new Phrase(myAddress.getCity() + ", " + myAddress.getState() + " " + myAddress.getZipCode(),
                        courierNorm),
                125, myCurrentY, 0);

        myCurrentY -= 11;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myAddress.getLastLine(), courierNorm),
                125, myCurrentY, 0);

        // FROM ADDRESS
        myCurrentY = myAddressStartY;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("FROM:", courierNorm),
                myPageLeftMargin + 288, myCurrentY, 0);

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                new Phrase("Ares Printing & Packaging", courierNorm), 98 + 288, myCurrentY, 0);

        myCurrentY -= 11;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                new Phrase("63 Flushing Ave, Bldg 5", courierNorm), 98 + 288, myCurrentY, 0);

        myCurrentY -= 11;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Brooklyn Navy Yard", courierNorm),
                98 + 288, myCurrentY, 0);

        myCurrentY -= 11;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Brooklyn, NY 11205", courierNorm),
                98 + 288, myCurrentY, 0);

        // CARRIER, FOB AND SPECIAL INSTRUCTIONS
        myCurrentY -= 33;
        int myItemStartY = myCurrentY;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CARRIER: " + myCarrier, courierNorm),
                myPageLeftMargin, myCurrentY, 0);

        myCurrentY -= 11;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("FOB: Brooklyn", courierNorm),
                myPageLeftMargin, myCurrentY, 0);

        myCurrentY -= 11;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                new Phrase("SPECIAL INSTRUCTIONS: " + myInstructs, courierNorm), myPageLeftMargin, myCurrentY,
                0);

        int myBOLTPallets = 0;
        int myBOLTCases = 0;
        int myBOLTPieces = 0;

        myCurrentY -= 22;

        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                new Phrase("---------------------------------------------------------------------------",
                        courierNorm),
                myPageLeftMargin, myCurrentY, 0);

        // Start Item/ShipLine Information
        for (Shipment shipment : shipmentList) {

            ArrayList<Inventory> shipInventoryList = shipment.getInvenList();
            ArrayList<Inventory.InventoryLine> invenLineList = new ArrayList<>();

            Item item = new Item(shipInventoryList.get(0).getItemID());
            String apo = "";

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

                if (i == 0) {
                    apo += shipInventoryList.get(i).getJobNum();
                } else {
                    apo += ", " + shipInventoryList.get(i).getJobNum();
                }

                invenLineList.addAll(shipInventoryList.get(i).getInvenLines());

            }
            //START ITEM
            myCurrentY -= 22;

            if (myCurrentY < 100) {
                document.newPage();
                if (aTemplate == 1) {
                    document.add(image);
                }
                myCurrentY = myTopSubMargin;
            }

            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase("ITEM NAME: " + item.getItemName(), courierNorm), myPageLeftMargin, myCurrentY,
                    0);

            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase("CUSTOMER PO#: " + chosenOrder.getPOrderNum(), courierNorm),
                    myPageLeftMargin + 288, myCurrentY, 0);

            myCurrentY -= 11;

            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase("ITEM CODE: " + item.getItemCode(), courierNorm), myPageLeftMargin, myCurrentY,
                    0);

            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("APO: " + apo, courierNorm),
                    myPageLeftMargin + 288, myCurrentY, 0);

            myCurrentY -= 22;

            ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pallets", courierNorm),
                    myPageLeftMargin + 115, myCurrentY, 0);

            ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
                    new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);

            ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pieces per case", courierNorm),
                    myPageLeftMargin + 340, myCurrentY, 0);

            // ITEM 1
            myCurrentY -= 12;

            int myItemTPallets = 0;
            int myItemTCases = 0;
            int myItemTPieces = 0;

            for (Inventory.InventoryLine invenLine : invenLineList) {

                ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
                        new Phrase(String.valueOf(invenLine.getPallets()), courierNorm), myPageLeftMargin + 115,
                        myCurrentY, 0);

                ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm),
                        myPageLeftMargin + 150, myCurrentY, 0);

                ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
                        new Phrase(String.valueOf(invenLine.getCases()), courierNorm), myPageLeftMargin + 215,
                        myCurrentY, 0);

                ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm),
                        myPageLeftMargin + 281, myCurrentY, 0);

                ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
                        new Phrase(String.valueOf(invenLine.getPieces()), courierNorm), myPageLeftMargin + 340,
                        myCurrentY, 0);

                // LINE 2
                myCurrentY -= 11;

                myItemTPallets += invenLine.getPallets();
                myItemTCases += invenLine.getPallets() * invenLine.getCases();
                myItemTPieces += invenLine.getPallets() * invenLine.getCases() * invenLine.getPieces();

                myBOLTPallets += myItemTPallets;
                myBOLTCases += myItemTCases;
                myBOLTPieces += myItemTPieces;

            }

            myCurrentY -= 22;

            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM TOTALS:", courierNorm),
                    myPageLeftMargin, myCurrentY, 0);

            ColumnText.showTextAligned(
                    canvas, Element.ALIGN_LEFT, new Phrase("   PALLETS: " + myItemTPallets + "   CASES: "
                            + myItemTCases + "   QUANTITY: " + myItemTPieces, courierNorm),
                    myPageLeftMargin + 95, myCurrentY, 0);

            myCurrentY -= 11;

            ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
                    new Phrase("---------------------------------------------------------------------------",
                            courierNorm),
                    myPageLeftMargin, myCurrentY, 0);

        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////           

        /*
                
        //START ITEM
                    myCurrentY -= 22;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0);
                
                    myCurrentY -= 11;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0);
                
                    myCurrentY -= 22;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
                
                
                     // ITEM 1
                    myCurrentY -= 12;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
           // LINE 2
                    myCurrentY -= 11;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
                
                
                    myCurrentY -= 33;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("   PALLETS: 12   CASES: 282   QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0);
                
                    myCurrentY -= 11;
                            
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0);
        //////////////         
        //END ITEM
        ////////////// 
                            
                            
                            
                            
                            
                    myCurrentY -= 22;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0);
                
                    myCurrentY -= 11;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0);
                
                    myCurrentY -= 22;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
                    myCurrentY -= 6;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0);
        //////////////         
        //END ITEM
        ////////////// 
                            
                    myCurrentY -= 12;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
           // LINE 2
                    myCurrentY -= 11;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
                    myCurrentY -= 1;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0);
                
                    myCurrentY -= 33;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("   PALLETS: 12   CASES: 282   QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0);
                
                    myCurrentY -= 11;
                            
        //////////////         
        //START ITEM
        ////////////// 
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    //START ITEM
                    myCurrentY -= 22;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0);
                
                    myCurrentY -= 11;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0);
                
                    myCurrentY -= 22;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
                    myCurrentY -= 6;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0);
                
                     // ITEM 1
                    myCurrentY -= 12;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
           // LINE 2
                    myCurrentY -= 11;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
                    myCurrentY -= 1;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0);
                
                    myCurrentY -= 33;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("   PALLETS: 12   CASES: 282   QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0);
                
                    myCurrentY -= 11;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0);
        //////////////         
        //END ITEM
        ////////////// 
                    */

        //////////////         
        //START FOOTER
        //////////////     
        myCurrentY -= 33;

        if (myCurrentY < 85) {
            document.newPage();
            myCurrentY = myTopSubMargin;
        }

        ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
                new Phrase("SHIPMENT RECEIVED IN GOOD CONDITION BY:", courierNorm), myPageLeftMargin + 128,
                myCurrentY, 0);

        myCurrentY -= 33;

        ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
                new Phrase("______________________________________", courierNorm), myPageLeftMargin + 128,
                myCurrentY, 0);
        myCurrentY -= 16;

        ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
                new Phrase("(SIGNATURE) (DATE & TIME)", courierNorm), myPageLeftMargin + 128, myCurrentY, 0);

        myCurrentY += 49;

        ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT,
                new Phrase("TOTAL PALLETS: " + myBOLTPallets, courierSBig), myPageLeftMargin + 500, myCurrentY,
                0);

        myCurrentY -= 13;

        ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT,
                new Phrase("TOTAL CASES: " + myBOLTCases, courierSBig), myPageLeftMargin + 500, myCurrentY, 0);

        myCurrentY -= 13;

        ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT,
                new Phrase("TOTAL WEIGHT: ~" + ((myBOLTCases * 25) + (myBOLTPallets * 40)) + " lbs",
                        courierSBig),
                myPageLeftMargin + 500, myCurrentY, 0);
        //////////////         
        //END FOOTER
        ////////////// 
        /*
                    document.newPage();
                            
                    myCurrentY = myTopSubMargin;
                
        //////////////         
        //START ITEM
        ////////////// 
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    //START ITEM
                    myCurrentY -= 22;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0);
                
                    myCurrentY -= 11;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0);
                
                    myCurrentY -= 22;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
                    myCurrentY -= 6;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0);
                
                     // ITEM 1
                    myCurrentY -= 12;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
           // LINE 2
                    myCurrentY -= 11;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER,
            new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0);
                
                    myCurrentY -= 1;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0);
                
                    myCurrentY -= 33;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0);
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("   PALLETS: 12   CASES: 282   QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0);
                
                    myCurrentY -= 11;
                
                    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT,
            new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0);
        //////////////         
        //END ITEM
        ////////////// 
                    */

        // step 5
        document.close();

        if (Desktop.isDesktopSupported()) {
            try {
                File f = new File(bolFileName);
                Desktop.getDesktop().open(f);
            } catch (IOException ex) {
                // no application registered for PDFs
            }
        }

    } catch (IOException | DocumentException ex) {
        Logger.getLogger(PDFCreator.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:PROCESOS.ImprimirPDF.java

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("application/pdf");
    String precio_unitario = request.getParameter("precio");

    String id_vale = request.getParameter("codigo");

    //  if(request.getParameter("codigo")!=null){
    OutputStream salida = response.getOutputStream();
    try {/*from w w w .  ja v  a  2 s .c  o m*/

        try {

            DTO.ClaseTransaccion clase = new ClaseTransaccion();
            clase = consulta.Transaccion();
            Document documento = new Document(PageSize.A4, 36, 36, 45, 20);
            PdfWriter pw = PdfWriter.getInstance(documento, salida);
            documento.open();
            Paragraph parrafo1 = new Paragraph();
            Font font_titulo = new Font(Font.FontFamily.HELVETICA, 16, Font.UNDERLINE, BaseColor.BLACK);
            parrafo1.add(new Phrase("TecnoBencina, COMPROBANTE", font_titulo));
            parrafo1.setAlignment(Element.ALIGN_CENTER);
            parrafo1.add(new Phrase(Chunk.NEWLINE));
            parrafo1.add(new Phrase(Chunk.NEWLINE));
            documento.add(parrafo1);

            Paragraph parrafo2 = new Paragraph();
            Font font_titulo_p2 = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL, BaseColor.BLACK);

            if (id_vale.length() > 0) {
                parrafo2.add(new Phrase("Comprobante de transaccion : codigo del vale : " + id_vale,
                        font_titulo_p2));
            } else {
                parrafo2.add(new Phrase("Comprobante de transaccion ", font_titulo_p2));
            }

            parrafo2.setAlignment(Element.ALIGN_JUSTIFIED);
            parrafo2.add(new Phrase(Chunk.NEWLINE));
            parrafo2.add(new Phrase(Chunk.NEWLINE));
            parrafo2.add(new Phrase(Chunk.NEWLINE));
            documento.add(parrafo2);

            PdfPTable tabla = new PdfPTable(9);
            PdfPCell celda1 = new PdfPCell(new Paragraph("ID transaccion ",
                    FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda2 = new PdfPCell(
                    new Paragraph("Estado ", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda3 = new PdfPCell(new Paragraph("ID de surtidor",
                    FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda4 = new PdfPCell(
                    new Paragraph("Litros", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda5 = new PdfPCell(
                    new Paragraph("Monto", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda6 = new PdfPCell(
                    new Paragraph("Fecha", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda7 = new PdfPCell(
                    new Paragraph("ID pago", FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));
            PdfPCell celda8 = new PdfPCell(new Paragraph("Precio unitario",
                    FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)));

            tabla.addCell(celda1);
            tabla.addCell(celda2);
            tabla.addCell(celda3);
            tabla.addCell(celda4);
            tabla.addCell(celda5);
            tabla.addCell(celda6);
            tabla.addCell(celda7);
            tabla.addCell(celda8);

            tabla.addCell(String.valueOf(clase.getId_transaccion()));
            tabla.addCell(clase.getEstado());
            tabla.addCell(String.valueOf(clase.getId_transaccion()));
            tabla.addCell(String.valueOf(clase.getLitros()));
            tabla.addCell(String.valueOf(clase.getMonto()));
            tabla.addCell(String.valueOf(clase.getFecha()));
            tabla.addCell(String.valueOf(clase.getId_pago()));
            tabla.addCell(precio_unitario);

            documento.add(tabla);
            documento.addAuthor("TecnoBencina");
            documento.addTitle("Comprobante");
            documento.addLanguage("Espaol");
            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));
            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));

            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));
            documento.add(new Paragraph(new Phrase(Chunk.NEWLINE)));
            documento.add(new Paragraph("texto....", font_titulo_p2));
            documento.close();
        } catch (Exception s) {
            s.getMessage();
        }

    } catch (Exception s) {
        System.out.println("" + s.getMessage());
    } finally {
        salida.close();
    }
    // }
}

From source file:py.com.palermo.imprimeetiquetas.web.ProductoController.java

public String createPdf() throws IOException, DocumentException {

    if (hayParaImprimir()) {

        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance()
                .getExternalContext().getResponse();
        response.setContentType("application/x-pdf");
        response.setHeader("Content-Disposition", "attachment; filename=\"etiquetas.pdf\"");

        // step 1
        Document document = new Document(new Rectangle(86, 35));
        // step 2

        document.setMargins(0f, 0f, 0f, 0f);

        PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
        // step 3
        document.open();//from  www .  j  a va  2s  .c o  m

        // step 4
        PdfContentByte cb = writer.getDirectContent();

        for (ProductoCantidad p : productos) {
            if (p.getCantidad() > 0) {

                BarcodeEAN codeEAN = new BarcodeEAN();
                codeEAN.setCode(p.getCodigo());
                codeEAN.setCodeType(Barcode.EAN13);
                codeEAN.setBarHeight(10f);
                codeEAN.setX(0.7f);
                codeEAN.setSize(4f);

                NumberFormat nf = NumberFormat.getCurrencyInstance(new Locale("es", "py"));
                Font fontbold = FontFactory.getFont("Times-Roman", 5, Font.NORMAL);
                Chunk productTitle = new Chunk(p.getNombre() + "," + " " + nf.format(p.getPrecio()), fontbold);

                // EAN 13
                Paragraph pTitile = new Paragraph(productTitle);
                pTitile.setAlignment(Element.ALIGN_CENTER);
                pTitile.setLeading(0, 1);

                PdfPTable table = new PdfPTable(1);
                table.setPaddingTop(0f);

                table.setWidthPercentage(96);
                PdfPCell cell = new PdfPCell();
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setBorder(Rectangle.NO_BORDER);
                cell.addElement(codeEAN.createImageWithBarcode(cb, null, BaseColor.BLACK));

                table.addCell(cell);

                PdfPCell cell2 = new PdfPCell();
                cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell2.setBorder(Rectangle.NO_BORDER);
                cell2.addElement(pTitile);

                table.addCell(cell2);

                for (int i = 0; i < p.getCantidad(); i++) {
                    document.add(table);
                    document.newPage();
                }
            }
        }

        // step 5
        document.close();

        response.getOutputStream().flush();
        response.getOutputStream().close();
        FacesContext.getCurrentInstance().responseComplete();
    } else {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "No hay nada que imprimir", ""));
    }
    return null;
}