Example usage for com.itextpdf.text Image getInstance

List of usage examples for com.itextpdf.text Image getInstance

Introduction

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

Prototype

public static Image getInstance(final Image image) 

Source Link

Document

gets an instance of an Image

Usage

From source file:modelo.pruebapdf.java

public boolean impOrden(int idOrden, String codOrden, int numRegTiq) {
    try {/*from   w  w w. j ava  2 s.c o  m*/

        int id = 0;
        int numTiquet = 0;
        String ob = "";
        colores verColor = new colores();
        String colorUno = "";
        String colorDos = "";
        ArrayList<String> lista = new ArrayList<String>();
        int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, c6 = 0, c7 = 0, c8 = 0, c9 = 0, c10 = 0, c11 = 0, c12 = 0,
                c13 = 0, c14 = 0, c15 = 0;
        int c16 = 0, c17 = 0, c18 = 0, c19 = 0, c20 = 0, c21 = 0, c22 = 0, c23 = 0, c24 = 0, c25 = 0, c26 = 0,
                c27 = 0, c28 = 0, c29 = 0;
        int c30 = 0, c31 = 0, c32 = 0, c33 = 0;
        String observacion = "";
        int CanTotal = 0;

        int idCliente = 0;
        String ciu = "";
        String fecped = "";
        String fecent = "";

        for (orden ord : new orden().CargarDatosOrden(codOrden)) {
            idCliente = ord.getCliente();
            ciu = ord.getCiudad();
            fecped = ord.getPedido();
            fecent = ord.getEntrega();
        }
        String nomCliente = nuevaOrden.ConsultarNombreCliente(idCliente);

        Chunk idClient = new Chunk(nomCliente,
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk direccion = new Chunk("Calle 12 # 6-68 Nia Ceci",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 12, Font.NORMAL, BaseColor.BLACK));
        Chunk Tiq = new Chunk("TK",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk ValTiq = new Chunk("",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Tel = new Chunk("Tel: 5783364",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 12, Font.NORMAL, BaseColor.BLACK));
        Chunk Ref = new Chunk("REF",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk ValRef = new Chunk("",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Correo = new Chunk("calzadoseiya@gmail.com",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 12, Font.NORMAL, BaseColor.BLACK));
        Chunk Cliente = new Chunk("CLIENTE",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk FecEnt = new Chunk("FECHA ENTREGA",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk ValFecEnt = new Chunk(fecent,
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk FecPed = new Chunk("FECHA PEDIDO",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk ValFecPed = new Chunk(fecped,
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk FechaTiq2 = new Chunk("",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Orden = new Chunk("ORDEN",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk ValOrd = new Chunk("",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Ciudad = new Chunk("CIUDAD",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk ValCiudad = new Chunk(ciu,
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Cant = new Chunk("CANT.",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Mon = new Chunk("MONTADA",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Emp = new Chunk("EMPLANTILLADA",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 8, Font.NORMAL, BaseColor.BLACK));
        Chunk OBSER = new Chunk("OBSERVACION",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 10, Font.NORMAL, BaseColor.BLACK));
        Chunk Col1 = new Chunk("Color 1",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 8, Font.NORMAL, BaseColor.BLACK));
        Chunk Col2 = new Chunk("Color 2",
                FontFactory.getFont(FontFactory.COURIER_BOLD, 8, Font.NORMAL, BaseColor.BLACK));
        Chunk Encabezado = new Chunk("SEIYA",
                FontFactory.getFont(FontFactory.HELVETICA_BOLD, 11, Font.NORMAL, BaseColor.BLACK));
        Chunk num21 = new Chunk("21",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num22 = new Chunk("22",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num23 = new Chunk("23",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num24 = new Chunk("24",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num25 = new Chunk("25",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num26 = new Chunk("26",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num27 = new Chunk("27",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num28 = new Chunk("28",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num29 = new Chunk("29",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num30 = new Chunk("30",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num31 = new Chunk("31",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num32 = new Chunk("32",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num33 = new Chunk("33",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num34 = new Chunk("34",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num35 = new Chunk("35",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num36 = new Chunk("36",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num37 = new Chunk("37",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num38 = new Chunk("38",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num39 = new Chunk("39",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num40 = new Chunk("40",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num41 = new Chunk("41",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num42 = new Chunk("42",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num43 = new Chunk("43",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));
        Chunk num44 = new Chunk("44",
                FontFactory.getFont(FontFactory.COURIER, 9, Font.NORMAL, BaseColor.BLACK));

        File folder = new File("c:\\seiya\\ordenes");
        folder.mkdirs();
        String dir = "C:\\seiya\\ordenes\\Orden_" + codOrden + ".pdf";
        // El archivo pdf que vamos a generar
        FileOutputStream fileOutputStream = new FileOutputStream(dir);
        Rectangle pageSize = new Rectangle(792f, 612f);

        Document document = new Document(pageSize, 1, 1, 1, 1);
        PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream);
        document.open();

        PdfPTable table = new PdfPTable(40);
        PdfPCell cell = new PdfPCell();

        Image image = Image.getInstance("logo.png");
        //    String col = "jhon";
        cell = new PdfPCell(image);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(7);
        cell.setRowspan(7);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(direccion));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(33);
        cell.setRowspan(2);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(Tel));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(33);
        cell.setRowspan(2);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(Correo));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(33);
        cell.setRowspan(2);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(" "));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(33);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(Tiq));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(Orden));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(codOrden));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(Cliente));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(idClient));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(9);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(Ciudad));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(ValCiudad));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(4);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(FecPed));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(ValFecPed));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(4);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(FecEnt));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(ValFecEnt));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(4);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(""));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(Ref));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(Cant));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(2);
        cell.setRowspan(1);
        table.addCell(cell);

        table.addCell(new Phrase(num21));
        table.addCell(new Phrase(num22));
        table.addCell(new Phrase(num23));
        table.addCell(new Phrase(num24));
        table.addCell(new Phrase(num25));
        table.addCell(new Phrase(num26));
        table.addCell(new Phrase(num27));
        table.addCell(new Phrase(num28));
        table.addCell(new Phrase(num29));
        table.addCell(new Phrase(num30));
        table.addCell(new Phrase(num31));
        table.addCell(new Phrase(num32));
        table.addCell(new Phrase(num33));
        table.addCell(new Phrase(num34));
        table.addCell(new Phrase(num35));
        table.addCell(new Phrase(num36));
        table.addCell(new Phrase(num37));
        table.addCell(new Phrase(num38));
        table.addCell(new Phrase(num39));
        table.addCell(new Phrase(num40));
        table.addCell(new Phrase(num41));
        table.addCell(new Phrase(num42));
        table.addCell(new Phrase(num43));

        cell = new PdfPCell(new Phrase(Col1));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(Col2));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(3);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(OBSER));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(5);
        cell.setRowspan(1);
        table.addCell(cell);

        ArrayList<String> resultat;
        resultat = nuevoTiquet.consultarTiquetporOrden(idOrden);
        Iterator<String> tiquetIterator = resultat.iterator();

        while (tiquetIterator.hasNext()) {

            String valorTiquet = tiquetIterator.next();
            System.out.print(valorTiquet + " ------ ");
            int tiq = Integer.parseInt(valorTiquet);
            ArrayList<tiquet> listaDatosTiquet;
            listaDatosTiquet = nuevoTiquet.conten(idOrden, tiq);//La consulta tiene que retornar un ArrayList

            for (tiquet ord : new tiquet().conten(idOrden, tiq)) {
                System.out.print("Referencia: " + nuevoTiquet.ConsultarReferencia(tiq, idOrden));
                c1 = ord.getTiquet();
                c2 = ord.getIdorden();
                observacion = ord.getObservacion();
                c4 = nuevoTiquet.ConsultarReferencia(tiq, idOrden);
                c5 = nuevoTiquet.ConsultarCantidad(tiq, idOrden);
                c8 = ord.getN21();
                c9 = ord.getN22();
                c10 = ord.getN23();
                c11 = ord.getN24();
                c12 = ord.getN25();
                c13 = ord.getN26();
                c14 = ord.getN27();
                c15 = ord.getN28();
                c16 = ord.getN29();
                c17 = ord.getN30();
                c18 = ord.getN31();
                c19 = ord.getN32();
                c20 = ord.getN33();
                c21 = ord.getN34();
                c22 = ord.getN35();
                c23 = ord.getN36();
                c24 = ord.getN37();
                c25 = ord.getN38();
                c26 = ord.getN39();
                c27 = ord.getN40();
                c28 = ord.getN41();
                c29 = ord.getN42();
                c30 = ord.getN43();

                String c01 = " ", c02 = " ", c03 = " ", c04 = " ", c05 = " ", c06 = " ", c07 = " ", c08 = " ",
                        c09 = " ", c010 = " ", c011 = " ", c012 = " ";
                String c013 = " ", c014 = " ", c015 = " ", c016 = " ", c017 = " ", c018 = " ", c019 = " ",
                        c020 = " ", c021 = " ", c022 = " ", c023 = " ", c024 = " ";
                String c025 = " ", c026 = " ", c027 = " ", c028 = " ", c029 = " ", c030 = " ", c031 = " ",
                        c032 = " ", c033 = " ", c034 = " ";
                if (c1 != 0)
                    c01 = String.valueOf(c1);
                if (c2 != 0)
                    c02 = String.valueOf(c2);
                //    if(c3!=0) c03 = String.valueOf(c3);
                if (c4 != 0)
                    c04 = String.valueOf(c4);
                if (c5 != 0) {
                    c05 = String.valueOf(c5);
                    CanTotal += c5;
                }
                if (c8 != 0)
                    c08 = String.valueOf(c8);
                if (c9 != 0)
                    c09 = String.valueOf(c9);
                if (c10 != 0)
                    c010 = String.valueOf(c10);
                if (c11 != 0)
                    c011 = String.valueOf(c11);
                if (c12 != 0)
                    c012 = String.valueOf(c12);
                if (c13 != 0)
                    c013 = String.valueOf(c13);
                if (c14 != 0)
                    c014 = String.valueOf(c14);
                if (c15 != 0)
                    c015 = String.valueOf(c15);
                if (c16 != 0)
                    c016 = String.valueOf(c16);
                if (c17 != 0)
                    c017 = String.valueOf(c17);
                if (c18 != 0)
                    c018 = String.valueOf(c18);
                if (c19 != 0)
                    c019 = String.valueOf(c19);
                if (c20 != 0)
                    c020 = String.valueOf(c20);
                if (c21 != 0)
                    c021 = String.valueOf(c21);
                if (c22 != 0)
                    c022 = String.valueOf(c22);
                if (c23 != 0)
                    c023 = String.valueOf(c23);
                if (c24 != 0)
                    c024 = String.valueOf(c24);
                if (c25 != 0)
                    c025 = String.valueOf(c25);
                if (c26 != 0)
                    c026 = String.valueOf(c26);
                if (c27 != 0)
                    c027 = String.valueOf(c27);
                if (c28 != 0)
                    c028 = String.valueOf(c28);
                if (c29 != 0)
                    c029 = String.valueOf(c29);
                if (c30 != 0)
                    c030 = String.valueOf(c30);

                cell = new PdfPCell(new Phrase(String.valueOf(tiq)));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(2);
                cell.setRowspan(1);
                table.addCell(cell);

                cell = new PdfPCell(new Phrase(c04));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(2);
                cell.setRowspan(1);
                table.addCell(cell);

                cell = new PdfPCell(new Phrase(c05));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(2);
                cell.setRowspan(1);
                table.addCell(cell);

                cell = new PdfPCell(new Phrase(c08));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c09));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c010));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c011));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c012));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c013));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c014));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c015));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c016));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c017));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c018));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c019));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c020));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c021));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c022));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c023));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c024));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c025));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c026));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c027));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c028));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c029));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(c030));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(1);
                cell.setRowspan(1);
                table.addCell(cell);

                colorUno = verColor.consultarNombreColorUno(ord.getIdcoloruno());
                colorDos = verColor.consultarNombreColorDos(ord.getIdcolordos());
                //  ob = verTiquet.ConsultaObservacion(tiquet);
                Chunk ValCol1 = new Chunk(colorUno,
                        FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK));
                Chunk ValCol2 = new Chunk(colorDos,
                        FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK));
                Chunk ValObserv = new Chunk(ord.getObservacion(),
                        FontFactory.getFont(FontFactory.COURIER, 10, Font.NORMAL, BaseColor.BLACK));

                cell = new PdfPCell(new Phrase(ValCol1));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(ValCol2));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(3);
                cell.setRowspan(1);
                table.addCell(cell);

                cell = new PdfPCell(new Phrase(ValObserv));
                cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                cell.setColspan(5);
                cell.setRowspan(1);
                table.addCell(cell);

            }

        }
        cell = new PdfPCell(new Phrase("Cantidad Total de Pares Producidos "));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(15);
        cell.setRowspan(1);
        table.addCell(cell);

        cell = new PdfPCell(new Phrase(String.valueOf(CanTotal)));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setColspan(25);
        cell.setRowspan(1);
        table.addCell(cell);

        table.setWidthPercentage(100f);
        table.setHorizontalAlignment(Element.ALIGN_RIGHT);
        document.add(table);

        document.close();

        return true;
    } catch (Exception x) {
        return false;
    }

}

From source file:mvjce.PDF.java

public static void create(int sino) {// sino = SI.No
    // TODO code application logic here
    try {//  ww  w .  java2 s . c  o m
        //Create Document instance.
        Document document = new Document();

        //Create OutputStream instance.
        OutputStream outputStream = new FileOutputStream(
                new File("/home/narein/NetBeansProjects/" + sem + cl + "/" + usn + ".pdf"));

        //Create PDFWriter instance.
        PdfWriter.getInstance(document, outputStream);

        //Open the document.
        document.open();
        //image position
        Image imageCenter = Image.getInstance("/home/narein/Downloads/mvj.png");
        //imageCenter.setAlignment(Image.MIDDLE);
        imageCenter.setAbsolutePosition(235, 780);
        imageCenter.scaleAbsolute(146f, 53f);
        //Permanently affiliated para
        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        table.addCell(getCell(
                "\n\n\nPermanently affiliated to VTU, Govt. of Karnataka\nApproved by AICTE, New Delhi\nNear ITPB, Bengaluru- 560067\n\n"
                        + hod_name + ", HOD - " + dep,
                PdfPCell.ALIGN_LEFT));
        table.addCell(getCell("\n\n\n\nPh: 080-42991000\nFax: 080-28452443\nWebsite: www.mvjce.edu.in\nEmail: "
                + hod_email + "\n\n", PdfPCell.ALIGN_RIGHT));
        //line across pdf
        final LineSeparator lineSeparator = new LineSeparator();
        Chunk linebreak = new Chunk(lineSeparator);
        Phrase p = new Phrase("\nPROGRESS REPORT\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Paragraph para = new Paragraph(p);
        para.setAlignment(Element.ALIGN_CENTER);
        Chunk glue = new Chunk(new VerticalPositionMark());
        Paragraph p1 = new Paragraph("\nRef:", new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        p1.add(new Chunk(glue));
        //get current date
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd.MM.yyyy");
        LocalDate localDate = LocalDate.now();
        //add date to pdf
        p1.add(new Phrase("Date: " + dtf.format(localDate) + "\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
        Phrase dear_prnts = new Phrase("Dear Parents,\n", new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        Phrase The_acad = new Phrase(
                "                  The academic performance of your ward Mr/Ms " + name + " of Semester " + sem
                        + " bearing the USN " + usn + " is as follows,\n\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Phrase Rem = new Phrase("Remarks\n", new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Phrase your_ward = new Phrase(
                "\nYour ward's overall performance is Good / Satisfactory / Poor / Very Poor\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Phrase you_are = new Phrase("\nYou are requested to:\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        Phrase req = new Phrase("");
        Paragraph para2 = new Paragraph(
                "1) Advice your ward to attend classes regularly\n2) Note that he/she may likely be detainedfrom appearing for examinations\n"
                        + "3) Advice your ward to improve in Test/Exam performance particularly in subject\n4) Meet the Head of the Department\n5) Meet the principal\n",
                new Font(FontFamily.TIMES_ROMAN, 9));
        Chunk glue1 = new Chunk(new VerticalPositionMark());
        Paragraph p3 = new Paragraph("\nSIGNATURE:\n\nNAME OF PROCTOR:\n\nCONTACT NUMBER:",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD));
        p3.add(new Chunk(glue1));
        p3.add(new Phrase(
                "SIGNATURE OF HOD\n\n            Kindly attend the Parent Teacher Meeting to be held on the date informed to your ward.\n",
                new Font(FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
        Phrase Note = new Phrase("\nNOTE:", new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD));
        Paragraph p4 = new Paragraph();
        p4.add(Note);
        p4.add(new Phrase(
                "  Parents are requested to contact the proctor (By Email/Letter/Phone) and confirm receipt of this feedback. Parents are also"
                        + "welcome to interact with proctors/subject faculty/ HOD for any discussion/clarification.\n",
                new Font(FontFamily.TIMES_ROMAN, 9)));
        //Add content to the document.
        document.add(imageCenter);
        document.add(table);
        document.add(linebreak);
        document.add(para);
        document.add(p1);
        document.add(dear_prnts);
        document.add(The_acad);
        document.add(createinternalsTable());
        if (internal.equals("1")) {
            document.add(new Phrase("\nPREVIOUS SEMESTER VTU RESULT\n\n",
                    new Font(FontFamily.TIMES_ROMAN, 10, Font.UNDERLINE | Font.BOLD)));
            document.add(createexternalTable());
        }
        document.add(Rem);
        document.add(your_ward);
        document.add(you_are);
        document.add(para2);
        document.add(p3);
        document.add(p4);
        //document.add(paragraph);document.add(paragraph1);

        //Close document and outputStream.
        document.close();
        outputStream.close();

        System.out.println("Pdf created successfully.");
    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:naprawa.praca.PracaController.java

public void akcjaDrukuj() {
    mapaUslug = getDaoFactory().getDaoDefect().pobierzUslugi(getConnection(), wybranyDefect);
    FileOutputStream file = null;
    File druk = null;/*  ww  w  .  j  a v  a2  s.  c  om*/
    try {
        Document document = new Document(PageSize.A5, 0, 0, 0, 0);
        String userPath = System.getProperty("user.home");
        druk = new File(userPath + "/Baks wydruki");
        if (!druk.exists()) {
            druk.mkdirs();
        }

        File wydruk = new File(druk + "/" + wybranyDefect.getInfoNaprawa() + ".pdf");
        if (!wydruk.exists()) {
            try {
                wydruk.createNewFile();
            } catch (IOException ex) {
                Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        file = new FileOutputStream(wydruk);
        try {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(wydruk));
            document.open();

            PdfPTable table = new PdfPTable(2);
            table.setWidthPercentage(100);
            table.setSpacingBefore(0f);
            table.setSpacingAfter(0f);

            PdfPTable tableO = new PdfPTable(2);
            tableO.setWidthPercentage(100);
            tableO.setSpacingBefore(0f);
            table.setSpacingAfter(0f);

            tableO.addCell(getNewCell(
                    "BAK's Machine\nin. Baej Krzciuk\n26-800 Biaobrzegi\nul. Brzechwy 31\ntel. 509-281-487"));
            Image image = Image.getInstance(getClass().getClassLoader().getResource("baksZ.jpg"));
            tableO.addCell(image);

            table.addCell(tableO);

            PdfPCell cell1 = getNewCell(
                    "Biaobrzegi, dn. " + new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
            cell1.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell1);

            table.addCell(addTableCzesc());
            table.addCell(addTableCzescService("Materiay", RodzajUslugi.MATERIAL));
            table.addCell(addTableCzescService("Naprawa", RodzajUslugi.NAPRAWA));

            PdfPTable tablePodsumowanie = new PdfPTable(3);
            tablePodsumowanie.setWidthPercentage(100);
            int[] width = { 8, 77, 15 };
            tablePodsumowanie.setWidths(width);
            PdfPCell cell = getNewCell("Podsumowanie");
            cell.setColspan(10);
            cell.setBorder(PdfPCell.NO_BORDER);
            cell.setHorizontalAlignment(Element.ALIGN_CENTER);
            tablePodsumowanie.addCell(cell);

            tablePodsumowanie.addCell(getNewCell("1."));
            tablePodsumowanie.addCell(getNewCell("Czci"));
            tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztCzesciS() + " z"));

            tablePodsumowanie.addCell(getNewCell("2."));
            tablePodsumowanie.addCell(getNewCell("Materiay"));
            tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztMaterialyS() + " z"));

            tablePodsumowanie.addCell(getNewCell("3."));
            tablePodsumowanie.addCell(getNewCell("Naprawa"));
            tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztNaprawyS() + " z"));

            tablePodsumowanie.addCell(getNewCell(""));
            tablePodsumowanie.addCell(getNewCell("RAZEM"));
            tablePodsumowanie.addCell(getNewCell(wybranyDefect.getKosztSumaS() + " z"));

            table.addCell(tablePodsumowanie);

            document.add(table);

            document.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex);
        BaksSessionBean.getInstance().fireMessage(widok, "Wydruk",
                "Pdf do ktrego chcesz zapisa wynik jest otwarty!\n Zamknij i sprbuj jeszcze raz.");
    } finally {
        try {
            file.close();
        } catch (IOException ex) {
            Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    Desktop desktop = null;
    if (Desktop.isDesktopSupported()) {
        desktop = Desktop.getDesktop();
        try {
            desktop.open(druk);
        } catch (IOException ex) {
            Logger.getLogger(WyszukPlatnosciController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    BaksSessionBean.getInstance().fireMessage(widok, "Zapis",
            "Wydruk zapisany w folderze: " + System.getProperty("user.home") + "/Baks wydruki");
}

From source file:net.pflaeging.PortableSigner.PDFSigner.java

License:Open Source License

/** Creates a new instance of DoSignPDF */
public void doSignPDF(String pdfInputFileName, String pdfOutputFileName, String pkcs12FileName, String password,
        Boolean signText, String signLanguage, String sigLogo, Boolean finalize, String sigComment,
        String signReason, String signLocation, Boolean noExtraPage, float verticalPos, float leftMargin,
        float rightMargin, Boolean signLastPage, byte[] ownerPassword) throws PDFSignerException {
    try {/*w  w  w . j a v  a  2 s  . c  om*/
        //System.out.println("-> DoSignPDF <-");
        //System.out.println("Eingabedatei: " + pdfInputFileName);
        //System.out.println("Ausgabedatei: " + pdfOutputFileName);
        //System.out.println("Signaturdatei: " + pkcs12FileName);
        //System.out.println("Signaturblock?: " + signText);
        //System.out.println("Sprache der Blocks: " + signLanguage);
        //System.out.println("Signaturlogo: " + sigLogo);
        System.err.println("Position V:" + verticalPos + " L:" + leftMargin + " R:" + rightMargin);
        Rectangle signatureBlock;

        java.security.Security.insertProviderAt(new org.bouncycastle.jce.provider.BouncyCastleProvider(), 2);

        pkcs12 = new GetPKCS12(pkcs12FileName, password);

        PdfReader reader = null;
        try {
            //                System.out.println("Password:" + ownerPassword.toString());
            if (ownerPassword == null)
                reader = new PdfReader(pdfInputFileName);
            else
                reader = new PdfReader(pdfInputFileName, ownerPassword);
        } catch (IOException e) {

            /* MODIFY BY: Denis Torresan
             Main.setResult(
                java.util.ResourceBundle.getBundle(
                "net/pflaeging/PortableSigner/i18n").getString(
                "CouldNotBeOpened"),
                true,
                e.getLocalizedMessage());
             */

            throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n")
                    .getString("CouldNotBeOpened"), true, e.getLocalizedMessage());
        }
        FileOutputStream fout = null;
        try {
            fout = new FileOutputStream(pdfOutputFileName);
        } catch (FileNotFoundException e) {

            /* MODIFY BY: Denis Torresan
             Main.setResult(
                java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("CouldNotBeWritten"),
                true,
                e.getLocalizedMessage());
             */

            throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n")
                    .getString("CouldNotBeWritten"), true, e.getLocalizedMessage());

        }
        PdfStamper stp = null;
        try {
            Date datum = new Date(System.currentTimeMillis());

            int pages = reader.getNumberOfPages();

            Rectangle size = reader.getPageSize(pages);
            stp = PdfStamper.createSignature(reader, fout, '\0', null, true);
            HashMap<String, String> pdfInfo = reader.getInfo();
            // thanks to Markus Feisst
            String pdfInfoProducer = "";

            if (pdfInfo.get("Producer") != null) {
                pdfInfoProducer = pdfInfo.get("Producer").toString();
                pdfInfoProducer = pdfInfoProducer + " (signed with PortableSigner " + Version.release + ")";
            } else {
                pdfInfoProducer = "Unknown Producer (signed with PortableSigner " + Version.release + ")";
            }
            pdfInfo.put("Producer", pdfInfoProducer);
            //System.err.print("++ Producer:" + pdfInfo.get("Producer").toString());
            stp.setMoreInfo(pdfInfo);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XmpWriter xmp = new XmpWriter(baos, pdfInfo);
            xmp.close();
            stp.setXmpMetadata(baos.toByteArray());
            if (signText) {
                String greet, signator, datestr, ca, serial, special, note, urn, urnvalue;
                int specialcount = 0;
                int sigpage;
                int rightMarginPT, leftMarginPT;
                float verticalPositionPT;
                ResourceBundle block = ResourceBundle
                        .getBundle("net/pflaeging/PortableSigner/Signatureblock_" + signLanguage);
                greet = block.getString("greeting");
                signator = block.getString("signator");
                datestr = block.getString("date");
                ca = block.getString("issuer");
                serial = block.getString("serial");
                special = block.getString("special");
                note = block.getString("note");
                urn = block.getString("urn");
                urnvalue = block.getString("urnvalue");

                //sigcomment = block.getString(signLanguage + "-comment");
                // upper y
                float topy = size.getTop();
                System.err.println("Top: " + topy * ptToCm);
                // right x
                float rightx = size.getRight();
                System.err.println("Right: " + rightx * ptToCm);
                if (!noExtraPage) {
                    sigpage = pages + 1;
                    stp.insertPage(sigpage, size);
                    // 30pt left, 30pt right, 20pt from top
                    rightMarginPT = 30;
                    leftMarginPT = 30;
                    verticalPositionPT = topy - 20;
                } else {
                    if (signLastPage) {
                        sigpage = pages;
                    } else {
                        sigpage = 1;
                    }
                    System.err.println("Page: " + sigpage);
                    rightMarginPT = Math.round(rightMargin / ptToCm);
                    leftMarginPT = Math.round(leftMargin / ptToCm);
                    verticalPositionPT = topy - Math.round(verticalPos / ptToCm);
                }
                if (!GetPKCS12.atEgovOID.equals("")) {
                    specialcount = 1;
                }
                PdfContentByte content = stp.getOverContent(sigpage);

                float[] cellsize = new float[2];
                cellsize[0] = 100f;
                // rightx = width of page
                // 60 = 2x30 margins
                // cellsize[0] = description row
                // cellsize[1] = 0
                // 70 = logo width
                cellsize[1] = rightx - rightMarginPT - leftMarginPT - cellsize[0] - cellsize[1] - 70;

                // Pagetable = Greeting, signatureblock, comment
                // sigpagetable = outer table
                //      consist: greetingcell, signatureblock , commentcell
                PdfPTable signatureBlockCompleteTable = new PdfPTable(2);
                PdfPTable signatureTextTable = new PdfPTable(2);
                PdfPCell signatureBlockHeadingCell = new PdfPCell(
                        new Paragraph(new Chunk(greet, new Font(Font.FontFamily.HELVETICA, 12))));
                signatureBlockHeadingCell.setPaddingBottom(5);
                signatureBlockHeadingCell.setColspan(2);
                signatureBlockHeadingCell.setBorderWidth(0f);
                signatureBlockCompleteTable.addCell(signatureBlockHeadingCell);

                // inner table start
                // Line 1
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(signator, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(GetPKCS12.subject, new Font(Font.FontFamily.COURIER, 10))));
                // Line 2
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(datestr, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(datum.toString(), new Font(Font.FontFamily.COURIER, 10))));
                // Line 3
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(ca, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(GetPKCS12.issuer, new Font(Font.FontFamily.COURIER, 10))));
                // Line 4
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(serial, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                signatureTextTable.addCell(new Paragraph(
                        new Chunk(GetPKCS12.serial.toString(), new Font(Font.FontFamily.COURIER, 10))));
                // Line 5
                if (specialcount == 1) {
                    signatureTextTable.addCell(new Paragraph(
                            new Chunk(special, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                    signatureTextTable.addCell(new Paragraph(
                            new Chunk(GetPKCS12.atEgovOID, new Font(Font.FontFamily.COURIER, 10))));
                }
                signatureTextTable.addCell(
                        new Paragraph(new Chunk(urn, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                signatureTextTable
                        .addCell(new Paragraph(new Chunk(urnvalue, new Font(Font.FontFamily.COURIER, 10))));
                signatureTextTable.setTotalWidth(cellsize);
                System.err.println(
                        "signatureTextTable Width: " + cellsize[0] * ptToCm + " " + cellsize[1] * ptToCm);
                // inner table end

                signatureBlockCompleteTable.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
                Image logo;
                //                     System.out.println("Logo:" + sigLogo + ":");
                if (sigLogo == null || "".equals(sigLogo)) {
                    logo = Image.getInstance(
                            getClass().getResource("/net/pflaeging/PortableSigner/SignatureLogo.png"));
                } else {
                    logo = Image.getInstance(sigLogo);
                }

                PdfPCell logocell = new PdfPCell();
                logocell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                logocell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
                logocell.setImage(logo);
                signatureBlockCompleteTable.addCell(logocell);
                PdfPCell incell = new PdfPCell(signatureTextTable);
                incell.setBorderWidth(0f);
                signatureBlockCompleteTable.addCell(incell);
                PdfPCell commentcell = new PdfPCell(
                        new Paragraph(new Chunk(sigComment, new Font(Font.FontFamily.HELVETICA, 10))));
                PdfPCell notecell = new PdfPCell(
                        new Paragraph(new Chunk(note, new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD))));
                //commentcell.setPaddingTop(10);
                //commentcell.setColspan(2);
                // commentcell.setBorderWidth(0f);
                if (!sigComment.equals("")) {
                    signatureBlockCompleteTable.addCell(notecell);
                    signatureBlockCompleteTable.addCell(commentcell);
                }
                float[] cells = { 70, cellsize[0] + cellsize[1] };
                signatureBlockCompleteTable.setTotalWidth(cells);
                System.err.println(
                        "signatureBlockCompleteTable Width: " + cells[0] * ptToCm + " " + cells[1] * ptToCm);
                signatureBlockCompleteTable.writeSelectedRows(0, 4 + specialcount, leftMarginPT,
                        verticalPositionPT, content);
                System.err.println(
                        "signatureBlockCompleteTable Position " + 30 * ptToCm + " " + (topy - 20) * ptToCm);
                signatureBlock = new Rectangle(30 + signatureBlockCompleteTable.getTotalWidth() - 20,
                        topy - 20 - 20, 30 + signatureBlockCompleteTable.getTotalWidth(), topy - 20);
                //                    //////
                //                    AcroFields af = reader.getAcroFields();
                //                    ArrayList names = af.getSignatureNames();
                //                    for (int k = 0; k < names.size(); ++k) {
                //                        String name = (String) names.get(k);
                //                        System.out.println("Signature name: " + name);
                //                        System.out.println("\tSignature covers whole document: " + af.signatureCoversWholeDocument(name));
                //                        System.out.println("\tDocument revision: " + af.getRevision(name) + " of " + af.getTotalRevisions());
                //                        PdfPKCS7 pk = af.verifySignature(name);
                //                        X509Certificate tempsigner = pk.getSigningCertificate();
                //                        Calendar cal = pk.getSignDate();
                //                        Certificate pkc[] = pk.getCertificates();
                //                        java.util.ResourceBundle tempoid =
                //                                java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/SpecialOID");
                //                        String tmpEgovOID = "";
                //
                //                        for (Enumeration<String> o = tempoid.getKeys(); o.hasMoreElements();) {
                //                            String element = o.nextElement();
                //                            // System.out.println(element + ":" + oid.getString(element));
                //                            if (tempsigner.getNonCriticalExtensionOIDs().contains(element)) {
                //                                if (!tmpEgovOID.equals("")) {
                //                                    tmpEgovOID += ", ";
                //                                }
                //                                tmpEgovOID += tempoid.getString(element) + " (OID=" + element + ")";
                //                            }
                //                        }
                //                        //System.out.println("\tSigniert von: " + PdfPKCS7.getSubjectFields(pk.getSigningCertificate()));
                //                        System.out.println("\tSigniert von: " + tempsigner.getSubjectX500Principal().toString());
                //                        System.out.println("\tDatum: " + cal.getTime().toString());
                //                        System.out.println("\tAusgestellt von: " + tempsigner.getIssuerX500Principal().toString());
                //                        System.out.println("\tSeriennummer: " + tempsigner.getSerialNumber());
                //                        if (!tmpEgovOID.equals("")) {
                //                            System.out.println("\tVerwaltungseigenschaft: " + tmpEgovOID);
                //                        }
                //                        System.out.println("\n");
                //                        System.out.println("\tDocument modified: " + !pk.verify());
                ////                Object fails[] = PdfPKCS7.verifyCertificates(pkc, kall, null, cal);
                ////                if (fails == null) {
                ////                    System.out.println("\tCertificates verified against the KeyStore");
                ////                } else {
                ////                    System.out.println("\tCertificate failed: " + fails[1]);
                ////                }
                //                    }
                //
                //                //////
            } else {
                signatureBlock = new Rectangle(0, 0, 0, 0); // fake definition
            }
            PdfSignatureAppearance sap = stp.getSignatureAppearance();
            //                sap.setCrypto(GetPKCS12.privateKey, GetPKCS12.certificateChain, null,
            //                        PdfSignatureAppearance.WINCER_SIGNED );
            sap.setCrypto(GetPKCS12.privateKey, GetPKCS12.certificateChain, null, null);
            sap.setReason(signReason);
            sap.setLocation(signLocation);
            //                if (signText) {
            //                    sap.setVisibleSignature(signatureBlock,
            //                            pages + 1, "PortableSigner");
            //                }
            if (finalize) {
                sap.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
            } else {
                sap.setCertificationLevel(PdfSignatureAppearance.NOT_CERTIFIED);
            }
            stp.close();

            /* MODIFY BY: Denis Torresan
            Main.setResult(
              java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("IsGeneratedAndSigned"),
              false,
              "");
                */

        } catch (Exception e) {

            /* MODIFY BY: Denis Torresan
             Main.setResult(
                java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("ErrorWhileSigningFile"),
                true,
                e.getLocalizedMessage());
             */

            throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n")
                    .getString("ErrorWhileSigningFile"), true, e.getLocalizedMessage());

        }
    } catch (KeyStoreException kse) {

        /* MODIFY BY: Denis Torresan
         Main.setResult(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n").getString("ErrorCreatingKeystore"),
            true, kse.getLocalizedMessage());
         */

        throw new PDFSignerException(java.util.ResourceBundle.getBundle("net/pflaeging/PortableSigner/i18n")
                .getString("ErrorCreatingKeystore"), true, kse.getLocalizedMessage());

    }
}

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

License:Apache License

/**
 * Create image of the TIC Chart.//www . j a  v a 2  s. c o m
 *
 * @param reportUnit Report unit for which to create TIC chart image.
 * @return TIC Chart image.
 */
private static Image createTICChartImage(final ReportUnit reportUnit) {
    /*Reference: http://vangjee.wordpress.com/2010/11/03/how-to-use-and-not-use-itext-and-jfreechart/
     * Apache License, Version 2.0
     */
    JFreeChart ticChart = null;
    try {
        ticChart = (JFreeChart) reportUnit.getChartUnit().getTicChart().clone();
    } catch (final CloneNotSupportedException e) {
        logger.log(Level.SEVERE, String.format(CLONE_EXCEPTION_MESSAGE, reportUnit.getMsrunName()), e);
    }
    final String titleString = String.format(TIC_GRAPH_TITLE, reportUnit.getMsrunName(),
            reportUnit.getChartUnit().getMaxTicIntensityString());
    final TextTitle newTitle = new TextTitle(titleString, Constants.PDF_CHART_TITLE_FONT);
    newTitle.setPaint(Color.red);
    if (ticChart != null) {
        ticChart.setTitle(newTitle);
    }
    Image chartImage = null;
    try {
        final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        if (ticChart != null) {
            ChartUtilities.writeChartAsPNG(byteArrayOutputStream, ticChart, CHART_IMAGE_WIDTH,
                    CHART_IMAGE_HEIGHT, new ChartRenderingInfo());
        }
        chartImage = Image.getInstance(byteArrayOutputStream.toByteArray());
        byteArrayOutputStream.close();
    } catch (final BadElementException | IOException e) {
        // TODO Explain when these exception can occur.
        /*
         * IOException occurs in case PDF file can not be created. 
         * e.g. PDF file with same name exist in the PDF directory and it is open. 
         * In this case, the PDF file can not be overwritten. 
         * BadElementException Signals an attempt to create an Element that hasn't got the right form. 
         */
        logger.log(Level.SEVERE, PDF_EXPORT_EXCEPTION_MESSAGE, e);
    }
    if (chartImage != null) {
        chartImage.setAlignment(Element.ALIGN_CENTER);
    }
    return chartImage;
}

From source file:nwk.com.br.documents.ClienteMaisComprouPdf.java

private PdfPTable cabecalho() throws Exception {

    //Cria Uma nova tabela com tres colunas, onde cada uma ocupa 20%, 20% e 60% do tamanho delas
    PdfPTable cabecalho = new PdfPTable(new float[] { 0.3f, 0.4f, 0.3f });
    cabecalho.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento
    cabecalho.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    cabecalho.getDefaultCell().setBorder(0);

    //Instancia a imagem da logo da empresa
    Image img = Image.getInstance("logoorc.png");//instancia a imagem
    img.setAlignment(Element.ALIGN_CENTER);//alinha a imagem no centro

    //Cria uma linha da tabela que pegara 3 linhas com a logo nela
    PdfPCell logo = new PdfPCell(img);
    logo.setBorder(0);/*from  ww  w  .  j  a  v  a  2s. c  o  m*/
    logo.setRowspan(3);

    //adiciona a logo a tabela
    cabecalho.addCell(logo);

    //adiciona informaes da empresa a tabela
    cabecalho.addCell(new Phrase(new Chunk("Sos da Piscina", f)));
    cabecalho.addCell(new Phrase(new Chunk(formatDate.format(dia).toString(), f)));
    cabecalho.addCell(new Phrase(new Chunk("Avenida Rebouas, 1440 - Centro", f)));
    cabecalho.addCell(new Phrase(new Chunk("Sumar/SP - 13170-140", f)));
    cabecalho.addCell(new Phrase(new Chunk("contato@sosdapiscina.com.br", f)));
    cabecalho.addCell(new Phrase(new Chunk("www.sosdapiscina.com.br", f)));
    cabecalho.addCell(new Phrase(new Chunk("", f)));

    return cabecalho;
}

From source file:nwk.com.br.documents.OrcamentoPdf.java

private PdfPTable cabecalho(Orcamento orcamento) throws Exception {

    //Cria Uma nova tabela com tres colunas, onde cada uma ocupa 20%, 20% e 60% do tamanho delas
    PdfPTable cabecalho = new PdfPTable(new float[] { 0.3f, 0.4f, 0.3f });
    cabecalho.setWidthPercentage(100.0f);//seta o tamanho da tabela em relaao ao documento
    cabecalho.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
    cabecalho.getDefaultCell().setBorder(0);

    //Instancia a imagem da logo da empresa
    Image img = Image.getInstance("logoorc.png");//instancia a imagem
    img.setAlignment(Element.ALIGN_CENTER);//alinha a imagem no centro

    //Cria uma linha da tabela que pegara 3 linhas com a logo nela
    PdfPCell logo = new PdfPCell(img);
    logo.setBorder(0);/*from   w  w  w.j a  v a 2s  . c  o  m*/
    logo.setRowspan(3);

    //adiciona a logo a tabela
    cabecalho.addCell(logo);

    //adiciona informaes da empresa a tabela
    cabecalho.addCell(new Phrase(new Chunk("Sos da Piscina", f)));
    cabecalho.addCell(new Phrase(new Chunk(formatDate.format(orcamento.getDhOrcamento()).toString(), f)));
    cabecalho.addCell(new Phrase(new Chunk("Avenida Rebouas, 1440 - Centro", f)));
    cabecalho.addCell(new Phrase(new Chunk("Sumar/SP - 13170-140", f)));
    cabecalho.addCell(new Phrase(new Chunk("contato@sosdapiscina.com.br", f)));
    cabecalho.addCell(new Phrase(new Chunk("www.sosdapiscina.com.br", f)));
    cabecalho.addCell(new Phrase(new Chunk("", f)));

    return cabecalho;
}

From source file:objects.manipulate.java

public static void createPDF(String filename, String[] RESOURCES)
        throws DocumentException, FileNotFoundException, IOException {
    Document document = new Document();
    document.setMargins(0, 0, 0, 0);//w ww .ja  v a  2  s  . c  om
    Rectangle rectangle = new Rectangle(0, 0, 742, 960);
    document.setPageSize(rectangle);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
    document.open();

    Image img;
    for (int i = 0; i < RESOURCES.length; i++) {
        //img = Image.getInstance(String.format("resources/img/%s", RESOURCES[i]));
        img = Image.getInstance(RESOURCES[i]);
        if (img.getScaledWidth() > 742 || img.getScaledHeight() > 960) {
            img.scaleToFit(742, 960);
        }

        document.add(img);
    }

    document.close();
}

From source file:op.tools.SYSConst.java

License:Open Source License

public static Image getPDF_16x16_tagPurple() throws BadElementException, IOException {
    return Image.getInstance(
            OPDE.getOPWD() + sep + AppInfo.dirArtwork + sep + AppInfo.dirArtwork16 + sep + "tag_purple.png");
}

From source file:Operaciones.ResponsablesOP.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);/*from   ww  w  .j  av  a 2 s.c  o m*/

    Session session = HibernateUtil.getSessionFactory().openSession();
    try {
        Orden ord = (Orden) session.get(Orden.class, Integer.parseInt(t_orden.getText()));
        Configuracion con = (Configuracion) session.get(Configuracion.class, 1);
        Date fecha = new Date();
        Date fecha1 = new Date();
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
        String valor = dateFormat.format(fecha);

        File folder = new File("reportes/" + ord.getIdOrden());
        folder.mkdirs();
        PdfReader reader = new PdfReader("imagenes/PlantillaHojaAsignacion.pdf");
        PdfStamper stamp = new PdfStamper(reader,
                new FileOutputStream("reportes/" + ord.getIdOrden() + "/" + valor + "-HojaAsignacion.pdf"));
        PdfContentByte cb = stamp.getUnderContent(1);
        AcroFields fdfDoc = stamp.getAcroFields();
        BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED);

        cb.beginText();
        fdfDoc.setField("orden", String.valueOf(ord.getIdOrden()));

        if (ord.getCompania() != null)
            fdfDoc.setField("compania", ord.getCompania().getNombre());
        else
            fdfDoc.setField("compania", "");

        if (ord.getSiniestro() != null)
            fdfDoc.setField("siniestro", ord.getSiniestro());
        else
            fdfDoc.setField("siniestro", "");

        if (ord.getPoliza() != null)
            fdfDoc.setField("poliza", ord.getPoliza());
        else
            fdfDoc.setField("poliza", "");
        if (ord.getFecha() != null)
            fdfDoc.setField("apertura", ord.getFecha().toString());
        else
            fdfDoc.setField("apertura", "");
        if (ord.getFechaSiniestro() != null)
            fdfDoc.setField("f_siniestro", ord.getFechaSiniestro().toString());
        else
            fdfDoc.setField("f_siniestro", "");
        if (ord.getInciso() != null)
            fdfDoc.setField("inciso", ord.getInciso());
        else
            fdfDoc.setField("inciso", "");

        if (ord.getTipo() != null)
            fdfDoc.setField("unidad", ord.getTipo().getTipoNombre());
        else
            fdfDoc.setField("unidad", "");
        if (ord.getModelo() != null)
            fdfDoc.setField("modelo", ord.getModelo().toString());
        else
            fdfDoc.setField("modelo", "");
        if (ord.getMarca() != null)
            fdfDoc.setField("marca", ord.getMarca().getMarcaNombre());
        else
            fdfDoc.setField("marca", "");
        if (ord.getNoEconomico() != null)
            fdfDoc.setField("economico", ord.getNoEconomico());
        else
            fdfDoc.setField("economico", "");
        if (ord.getNoMotor() != null)
            fdfDoc.setField("no_motor", ord.getNoMotor());
        else
            fdfDoc.setField("no_motor", "");
        if (ord.getNoSerie() != null)
            fdfDoc.setField("no_serie", ord.getNoSerie());
        else
            fdfDoc.setField("no_serie", "");

        //tabla 
        if (ord.getEmpleadoByRHojalateria() != null)
            fdfDoc.setField("HOJALATERIA", ord.getEmpleadoByRHojalateria().getIdEmpleado().toString());
        else
            fdfDoc.setField("HOJALATERIA", "");
        if (ord.getEmpleadoByRHojalateria() != null)
            fdfDoc.setField("R_H", ord.getEmpleadoByRHojalateria().getNombre().toString());
        else
            fdfDoc.setField("R_H", "");

        if (ord.getEmpleadoByRMecanica() != null)
            fdfDoc.setField("MECANICA", ord.getEmpleadoByRMecanica().getIdEmpleado().toString());
        else
            fdfDoc.setField("MECANICA", "");
        if (ord.getEmpleadoByRMecanica() != null)
            fdfDoc.setField("R_M", ord.getEmpleadoByRMecanica().getNombre().toString());
        else
            fdfDoc.setField("R_M", "");

        if (ord.getEmpleadoByRSuspension() != null)
            fdfDoc.setField("SUSPENSIN", ord.getEmpleadoByRSuspension().getIdEmpleado().toString());
        else
            fdfDoc.setField("SUSPENSIN", "");
        if (ord.getEmpleadoByRSuspension() != null)
            fdfDoc.setField("R_S", ord.getEmpleadoByRSuspension().getNombre().toString());
        else
            fdfDoc.setField("R_S", "");

        if (ord.getEmpleadoByRElectrico() != null)
            fdfDoc.setField("ELECTRICO", ord.getEmpleadoByRElectrico().getIdEmpleado().toString());
        else
            fdfDoc.setField("ELECTRICO", "");

        if (ord.getEmpleadoByRElectrico() != null)
            fdfDoc.setField("R_E", ord.getEmpleadoByRElectrico().getNombre().toString());
        else
            fdfDoc.setField("R_E", "");

        if (ord.getEmpleadoByRPintura() != null)
            fdfDoc.setField("PINTURA", ord.getEmpleadoByRPintura().getIdEmpleado().toString());
        else
            fdfDoc.setField("PINTURA", "");
        if (ord.getEmpleadoByRPintura() != null)
            fdfDoc.setField("R_P", ord.getEmpleadoByRPintura().getNombre().toString());
        else
            fdfDoc.setField("R_P", "");

        //FECHAS
        String valor1 = "";
        if (ord.getRHojalateriaFecha() != null) {
            fecha1 = ord.getRHojalateriaFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_H", valor1);
        } else {
            fdfDoc.setField("F_H", valor1);
        }
        if (ord.getRMecanicaFecha() != null) {
            fecha1 = ord.getRMecanicaFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_M", valor1);
        } else {
            fdfDoc.setField("F_M", valor1);
        }
        if (ord.getRSuspensionFecha() != null) {
            fecha1 = ord.getRSuspensionFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_S", valor1);
        } else {
            fdfDoc.setField("F_S", valor1);
        }
        if (ord.getRElectricoFecha() != null) {
            fecha1 = ord.getRElectricoFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_E", valor1);
        } else {
            fdfDoc.setField("F_E", valor1);
        }
        if (ord.getRPinturaFecha() != null) {
            fecha1 = ord.getRPinturaFecha();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_P", valor1);
        } else {
            fdfDoc.setField("F_P", valor1);
        }
        //ASIGNO OPERARIO
        if (ord.getUsuarioByRHojalateriaAsigno() != null)
            fdfDoc.setField("A_H", ord.getUsuarioByRHojalateriaAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_H", "");

        if (ord.getUsuarioByRMecanicaAsigno() != null)
            fdfDoc.setField("A_M", ord.getUsuarioByRMecanicaAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_M", "");
        if (ord.getUsuarioByRSuspensionAsigno() != null)
            fdfDoc.setField("A_S", ord.getUsuarioByRSuspensionAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_S", "");
        if (ord.getUsuarioByRElectricoAsigno() != null)
            fdfDoc.setField("A_E", ord.getUsuarioByRElectricoAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_E", "");

        if (ord.getUsuarioByRPinturaAsigno() != null)
            fdfDoc.setField("A_P", ord.getUsuarioByRPinturaAsigno().getIdUsuario());
        else
            fdfDoc.setField("A_P", "");
        //LIMITE
        if (ord.getHojalateriaLimite() != null) {
            fecha1 = ord.getHojalateriaLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_H_L", valor1);
        } else {
            fdfDoc.setField("F_H_L", "");
        }
        if (ord.getMecanicaLimite() != null) {
            fecha1 = ord.getMecanicaLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_M_L", valor1);
        } else {
            fdfDoc.setField("F_M_L", "");
        }
        if (ord.getSuspensionLimite() != null) {
            fecha1 = ord.getSuspensionLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_S_L", valor1);
        } else {
            fdfDoc.setField("F_S_L", "");
        }
        if (ord.getElectricoLimite() != null) {
            fecha1 = ord.getElectricoLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_E_L", valor1);
        } else {
            fdfDoc.setField("F_E_L", "");
        }
        if (ord.getPinturaLimite() != null) {
            fecha1 = ord.getPinturaLimite();
            dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
            valor1 = dateFormat.format(fecha1);
            fdfDoc.setField("F_P_L", valor1);
        } else {
            fdfDoc.setField("F_P_L", "");
        }

        Foto[] fotos = (Foto[]) ord.getFotos().toArray(new Foto[0]);
        for (int k = 0; k < fotos.length - 1; k++) {
            for (int f = 0; f < (fotos.length - 1) - k; f++) {
                if (fotos[f].getFecha().after(fotos[f + 1].getFecha()) == true) {
                    Foto aux;
                    aux = fotos[f];
                    fotos[f] = fotos[f + 1];
                    fotos[f + 1] = aux;
                }
            }
        }
        if (fotos.length > 0) {
            try {
                Image img;
                img = Image
                        .getInstance("ordenes/" + ord.getIdOrden() + "/miniatura/" + fotos[0].getDescripcion());
                img.setAbsolutePosition(30, 495);
                img.scaleAbsoluteWidth(124);
                img.scaleAbsoluteHeight(80);
                cb.addImage(img, true);
            } catch (Exception e) {
                //e.printStackTrace();
            }
        } else {
        }

        cb.endText();
        stamp.close();

        PDF reporte = new PDF();
        reporte.cerrar();
        reporte.visualizar("reportes/" + ord.getIdOrden() + "/" + valor + "-HojaAsignacion.pdf");
    } catch (Exception e) {
        System.out.println(e);
        JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto");
    }
    if (session != null)
        if (session.isOpen())
            session.close();
}