Example usage for com.itextpdf.text Rectangle NO_BORDER

List of usage examples for com.itextpdf.text Rectangle NO_BORDER

Introduction

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

Prototype

int NO_BORDER

To view the source code for com.itextpdf.text Rectangle NO_BORDER.

Click Source Link

Document

This represents a rectangle without borders.

Usage

From source file:Servlets.GenerarPinEstudiante.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    int idEstudiante = Integer.parseInt(req.getParameter("idEst"));

    resp.setContentType("application/pdf");
    OutputStream out = resp.getOutputStream();

    String foto = getServletContext().getRealPath("/recursos/img/logoColegio.png");
    req.setCharacterEncoding("UTF-8");

    try {/* ww  w. ja  va 2 s .  c o  m*/
        try {
            Document documento = new Document();
            PdfWriter.getInstance(documento, out);

            documento.open();

            Paragraph par1 = new Paragraph();
            Font fontit = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.GRAY);
            par1.add(new Phrase("Pin de Acceso HeartsTics", fontit));
            par1.setAlignment(Element.ALIGN_CENTER);
            par1.add(new Phrase(Chunk.NEWLINE));
            par1.add(new Phrase(Chunk.NEWLINE));
            documento.add(par1);
            //                Image image = Image.getInstance("E:\\ArchivosVarios\\logoColegio.png");
            //                image.scalePercent(50);
            Image image = Image.getInstance(foto);
            image.scalePercent(60);

            Font fuentetabla = FontFactory.getFont("Arial", 8, Font.BOLD, BaseColor.BLACK);
            Font fuentetablaPin = FontFactory.getFont("Arial", 10, Font.BOLD, BaseColor.BLACK);
            Font fuentetablaHeader = FontFactory.getFont("Arial", 9, Font.BOLD, BaseColor.BLACK);

            Servicio controlador = new Servicio();
            Pin estudiante = controlador.pinEstudiante(idEstudiante);
            PdfPTable tabla = new PdfPTable(3);

            tabla.setWidthPercentage(60);

            PdfPCell celdaHeader = new PdfPCell(new Paragraph("COLEGIO SAGRADOS CORAZONES", fuentetablaHeader));
            celdaHeader.setVerticalAlignment(Element.ALIGN_MIDDLE);
            celdaHeader.setHorizontalAlignment(Element.ALIGN_CENTER);
            celdaHeader.setColspan(3);
            tabla.addCell(celdaHeader);
            PdfPCell celda01 = new PdfPCell(image);
            //PdfPCell celda01 = new PdfPCell(new Paragraph("imagen"));
            celda01.setHorizontalAlignment(Element.ALIGN_CENTER);
            celda01.setVerticalAlignment(Element.ALIGN_MIDDLE);
            celda01.setRowspan(2);
            celda01.setBorder(Rectangle.NO_BORDER);
            celda01.setBorder(Rectangle.LEFT);
            tabla.addCell(celda01);

            PdfPCell celda1 = new PdfPCell(new Paragraph(
                    "Estudiante: " + estudiante.getNombres() + " " + estudiante.getApellidos(), fuentetabla));
            PdfPCell celda2 = new PdfPCell(new Paragraph("Pin: " + estudiante.getIdPin(), fuentetablaPin));
            PdfPCell celda3 = new PdfPCell(
                    new Paragraph("Fecha creacion: " + estudiante.getInicio(), fuentetabla));
            PdfPCell celda4 = new PdfPCell(
                    new Paragraph("Fecha vencimiento: " + estudiante.getFin(), fuentetabla));

            celda1.setHorizontalAlignment(Element.ALIGN_CENTER);
            celda1.setVerticalAlignment(Element.ALIGN_MIDDLE);
            celda1.setColspan(2);
            celda1.setBorder(Rectangle.NO_BORDER);
            celda1.setBorder(Rectangle.RIGHT);

            celda2.setHorizontalAlignment(Element.ALIGN_CENTER);
            celda2.setVerticalAlignment(Element.ALIGN_MIDDLE);
            celda2.setColspan(2);
            celda2.setBorder(Rectangle.NO_BORDER);
            celda2.setBorder(Rectangle.RIGHT);

            PdfPTable tableFecha = new PdfPTable(2);
            tableFecha.setWidthPercentage(60);
            celda3.setHorizontalAlignment(Element.ALIGN_CENTER);
            celda4.setHorizontalAlignment(Element.ALIGN_CENTER);

            tabla.addCell(celda1);
            tabla.addCell(celda2);
            tableFecha.addCell(celda3);
            tableFecha.addCell(celda4);
            Paragraph par2 = new Paragraph();

            par2.add(new Phrase(Chunk.NEWLINE));
            documento.add(par2);

            documento.add(tabla);
            documento.add(tableFecha);

            documento.close();

        } catch (Exception e) {
            e.getMessage();
        }
    } finally {
        out.close();
    }

}

From source file:sistema.Minuta.java

public void generarMinutaPDF() {
    Document document = new Document();

    try {//from   www.j  a  v  a2  s.c  o m
        String ruta = "C:\\Users\\Gerardo\\Documents\\Facultad 5E\\Programacin Distribuida\\Programas\\SistemaControl\\minutas\\";
        PdfWriter.getInstance(document, new FileOutputStream(ruta + "Minuta_Reunion" + id_reunion + ".pdf"));

        document.open();

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

        PdfPCell fecha = new PdfPCell(new Paragraph("Fecha"));
        PdfPCell nReunion = new PdfPCell(new Paragraph("No. Reunin"));

        fecha.setColspan(3);
        nReunion.setColspan(3);

        table.addCell(fecha);
        table.addCell(nReunion);

        PdfPCell cFecha = new PdfPCell(new Paragraph(this.fecha));
        PdfPCell cNReunion = new PdfPCell(new Paragraph(id_reunion));

        cFecha.setColspan(3);
        cNReunion.setColspan(3);

        table.addCell(cFecha);
        table.addCell(cNReunion);

        PdfPCell asunto = new PdfPCell(new Paragraph("Asunto:"));
        PdfPCell cAsunto = new PdfPCell(new Paragraph(this.asunto));

        cAsunto.setColspan(5);

        table.addCell(asunto);
        table.addCell(cAsunto);

        PdfPCell lugar = new PdfPCell(new Paragraph("Lugar:"));
        PdfPCell cLugar = new PdfPCell(new Paragraph(this.lugar));

        cLugar.setColspan(5);

        table.addCell(lugar);
        table.addCell(cLugar);

        PdfPCell presidente = new PdfPCell(new Paragraph("Presidente:"));
        PdfPCell cPresidente = new PdfPCell(new Paragraph(this.presidente));

        cPresidente.setColspan(5);

        table.addCell(presidente);
        table.addCell(cPresidente);

        PdfPCell secretario = new PdfPCell(new Paragraph("Secretario:"));
        PdfPCell cSecretario = new PdfPCell(new Paragraph(this.secretario));

        cSecretario.setColspan(5);

        table.addCell(secretario);
        table.addCell(cSecretario);

        PdfPCell ordenDia = new PdfPCell(new Paragraph("Orden del da"));

        ordenDia.setColspan(6);

        table.addCell(ordenDia);

        PdfPCell cOrdenDia = new PdfPCell(new Paragraph(this.ordenDia));

        cOrdenDia.setColspan(6);

        table.addCell(cOrdenDia);

        PdfPCell detalles = new PdfPCell(new Paragraph("Detalles de la reunin"));

        detalles.setColspan(6);

        table.addCell(detalles);

        PdfPCell cDetalles = new PdfPCell(new Paragraph(this.detalles));

        cDetalles.setColspan(6);

        table.addCell(cDetalles);

        PdfPCell acuerdos = new PdfPCell(new Paragraph("Acuerdos"));

        acuerdos.setColspan(6);

        table.addCell(acuerdos);

        PdfPCell cAcuerdos = new PdfPCell(new Paragraph(this.acuerdos));

        cAcuerdos.setColspan(6);

        table.addCell(cAcuerdos);

        PdfPCell proximaReunion = new PdfPCell(new Paragraph("Fecha de la prxima reunin"));
        PdfPCell cProximaReunion = new PdfPCell(new Paragraph("2015-11-30"));

        proximaReunion.setColspan(3);
        cProximaReunion.setColspan(3);

        table.addCell(proximaReunion);
        table.addCell(cProximaReunion);

        PdfPCell participantes = new PdfPCell(new Paragraph("Participantes"));

        participantes.setColspan(6);

        table.addCell(participantes);

        PdfPCell profesor = new PdfPCell(new Paragraph("Nombre del profesor"));
        PdfPCell asistencia = new PdfPCell(new Paragraph("Asistencia"));
        PdfPCell firma = new PdfPCell(new Paragraph("Firma"));

        profesor.setColspan(3);
        asistencia.setColspan(1);
        firma.setColspan(2);

        table.addCell(profesor);
        table.addCell(asistencia);
        table.addCell(firma);

        int i = 0;
        while (i < this.participantes.length) {
            PdfPCell nProfesor = new PdfPCell(new Paragraph(this.participantes[i]));
            PdfPCell nAsistencia = new PdfPCell(new Paragraph("Si"));
            PdfPCell nFirma = new PdfPCell(new Paragraph(" \n "));

            nProfesor.setColspan(3);
            nAsistencia.setColspan(1);
            nFirma.setColspan(2);
            nProfesor.setRowspan(2);
            nAsistencia.setRowspan(2);
            nFirma.setRowspan(2);

            table.addCell(nProfesor);
            table.addCell(nAsistencia);
            table.addCell(nFirma);
            i++;
        }

        document.add(table);

        Paragraph pFirmas = new Paragraph();
        pFirmas.setAlignment(Element.ALIGN_CENTER);
        Chunk firmas = new Chunk("Firmas");
        pFirmas.add(firmas);
        document.add(pFirmas);

        PdfPTable tCargos = new PdfPTable(8);
        PdfPCell fPresidente = new PdfPCell(new Paragraph("Presidente"));
        PdfPCell fSecretario = new PdfPCell(new Paragraph("Secretario"));
        PdfPCell fespacio = new PdfPCell(new Paragraph(" "));

        fPresidente.setColspan(3);
        fSecretario.setColspan(3);

        fPresidente.setHorizontalAlignment(Element.ALIGN_CENTER);
        fSecretario.setHorizontalAlignment(Element.ALIGN_CENTER);

        fPresidente.setBorder(Rectangle.NO_BORDER);
        fSecretario.setBorder(Rectangle.NO_BORDER);
        fespacio.setBorder(Rectangle.NO_BORDER);

        tCargos.addCell(fespacio);
        tCargos.addCell(fPresidente);
        tCargos.addCell(fSecretario);
        tCargos.addCell(fespacio);

        document.add(tCargos);

        PdfPTable tFirmas = new PdfPTable(8);
        PdfPCell firmaPresidente = new PdfPCell(new Paragraph("_____________________"));
        PdfPCell firmaSecretario = new PdfPCell(new Paragraph("______________________"));
        PdfPCell tespacio = new PdfPCell(new Paragraph(" "));
        PdfPCell nombrePresidente = new PdfPCell(new Paragraph(this.presidente));
        PdfPCell nombreSecretario = new PdfPCell(new Paragraph(this.secretario));

        firmaPresidente.setColspan(3);
        firmaSecretario.setColspan(3);
        firmaPresidente.setRowspan(3);
        firmaSecretario.setRowspan(3);
        tespacio.setColspan(1);

        nombrePresidente.setColspan(3);
        nombreSecretario.setColspan(3);

        firmaPresidente.setHorizontalAlignment(Element.ALIGN_CENTER);
        firmaSecretario.setHorizontalAlignment(Element.ALIGN_CENTER);
        firmaPresidente.setVerticalAlignment(Element.ALIGN_BOTTOM);
        firmaSecretario.setVerticalAlignment(Element.ALIGN_BOTTOM);
        nombrePresidente.setHorizontalAlignment(Element.ALIGN_CENTER);
        nombreSecretario.setHorizontalAlignment(Element.ALIGN_CENTER);

        firmaPresidente.setBorder(Rectangle.NO_BORDER);
        firmaSecretario.setBorder(Rectangle.NO_BORDER);
        tespacio.setBorder(Rectangle.NO_BORDER);
        nombrePresidente.setBorder(Rectangle.NO_BORDER);
        nombreSecretario.setBorder(Rectangle.NO_BORDER);

        tFirmas.addCell(tespacio);
        tFirmas.addCell(firmaPresidente);
        tFirmas.addCell(firmaSecretario);
        tFirmas.addCell(tespacio);
        tFirmas.addCell(tespacio);
        tFirmas.addCell(tespacio);
        tFirmas.addCell(tespacio);
        tFirmas.addCell(tespacio);
        tFirmas.addCell(tespacio);
        tFirmas.addCell(nombrePresidente);
        tFirmas.addCell(nombreSecretario);
        tFirmas.addCell(tespacio);

        document.add(tFirmas);

        document.close();

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:src.servlets.ManageAdmin.java

/**
 * Handles the HTTP <code>GET</code> method.
 *
 * @param request servlet request/*from  w  w  w. j a v  a  2s. c o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    Map m = request.getParameterMap();
    if (m.containsKey("GetPDF")) {
        try {
            String Report = getServletContext().getRealPath("") + "admin\\PDF_Report.pdf";

            FileOutputStream file = new FileOutputStream(Report);
            Document document = new Document();
            document.addAuthor("K00140908");
            PdfWriter.getInstance(document, file);
            ///////////////////////ADDING THE FILES TO PDF////////////////////
            //Inserting Image in PDF
            String uploadPath = getServletContext().getRealPath("") + "images\\logo.gif";

            Image img = Image.getInstance(uploadPath);

            img.scaleAbsolute(120f, 60f);// width,height of image in float

            //            Inserting Title in PDF  ORIGINAL
            //            Font fontTitle=new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.WHITE);
            //            Chunk title=new Chunk("PDF GENERATION in Java with iText", fontTitle);
            //            title.setBackground(new BaseColor(255,102,0), 1f, 1f, 1f, 3f);
            //            title.setLineHeight(30f);
            //            title.setUnderline(BaseColor.BLACK,5f,0.5f,2f,0.5f,PdfContentByte.LINE_CAP_ROUND);
            Font fontTitle = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD, BaseColor.BLACK);
            Chunk title = new Chunk("Lit Realty System Report", fontTitle);
            title.setLineHeight(30f);

            //Inserting Table in PDF
            PdfPTable table = new PdfPTable(3);
            table.setWidthPercentage(100); // Sets the width percentage that the table will occupy in the page
            table.setSpacingAfter(10f);
            table.setSpacingBefore(15f);
            table.setWidths(new float[] { 2f, 2f, 2f }); // Sets relative width of table

            Font fontHeader = new Font(Font.FontFamily.HELVETICA, 15, Font.BOLD, BaseColor.BLUE);
            PdfPCell headercell = new PdfPCell(new Phrase("Property Photo", fontHeader)); // Creates new cell in table
            headercell.setBackgroundColor(new BaseColor(230, 230, 243));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            headercell = new PdfPCell(new Phrase("Property ID", fontHeader));
            headercell.setBackgroundColor(new BaseColor(233, 233, 233));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            headercell = new PdfPCell(new Phrase("Price", fontHeader));
            headercell.setBackgroundColor(new BaseColor(233, 233, 233));
            headercell.setPaddingBottom(5f);
            table.addCell(headercell);

            PdfPCell cell1 = new PdfPCell(img, false);

            table.addCell(cell1);
            table.addCell("134000");
            table.addCell("213445");
            table.addCell("134000");

            //Inserting List
            com.itextpdf.text.List list = new com.itextpdf.text.List(true, 30);
            list.add(new ListItem("Example1"));
            list.add(new ListItem("Example2"));
            list.add(new ListItem("Example3"));

            //Adding elements into PDF Document
            document.open();

            document.add(img);
            document.add(title);

            document.add(Chunk.NEWLINE);
            document.add(table);

            document.newPage();
            document.add(new Chunk("List of Examples").setUnderline(+1f, -5f));
            document.add(list);

            document.newPage();
            document.add(new Chunk("List of Examples").setUnderline(+1f, -5f));
            document.add(list);

            document.newPage();
            document.add(new Chunk("List of Properts By Agent X").setUnderline(+1f, -5f));
            //////////////////////GET Propertys From Entity///////////////
            List<Properties> allPropertiesList = PropertiesDB.getAllProperties();

            PdfPTable propertyTable = new PdfPTable(3);
            PdfPCell propertyHeadingcell1 = new PdfPCell(new Phrase("Photo"));
            PdfPCell propertyHeadingcell2 = new PdfPCell(new Phrase("Property ID"));
            PdfPCell propertyHeadingcell3 = new PdfPCell(new Phrase("Price"));

            propertyHeadingcell1.setBorder(Rectangle.NO_BORDER);
            propertyHeadingcell2.setBorder(Rectangle.NO_BORDER);
            propertyHeadingcell3.setBorder(Rectangle.NO_BORDER);

            propertyTable.addCell(propertyHeadingcell1);
            propertyTable.addCell(propertyHeadingcell2);
            propertyTable.addCell(propertyHeadingcell3);

            document.add(Chunk.NEWLINE);

            String uploadPathforPropertyPhoto = getServletContext().getRealPath("")
                    + "images\\properties\\thumbnails\\";

            Image propertyThumbnail;

            img.scaleAbsolute(120f, 60f);// width,height of image in float

            for (Properties anProperty : allPropertiesList) {
                propertyThumbnail = Image.getInstance(uploadPathforPropertyPhoto + anProperty.getPhoto());
                PdfPCell propertycell1 = new PdfPCell(propertyThumbnail, false);
                propertycell1.setPaddingBottom(20);
                PdfPCell propertycell2 = new PdfPCell(new Phrase(anProperty.getListingNum().toString()));
                PdfPCell propertycell3 = new PdfPCell(new Phrase(anProperty.getPrice().toString()));

                propertycell1.setBorder(Rectangle.NO_BORDER);
                propertycell2.setBorder(Rectangle.NO_BORDER);
                propertycell3.setBorder(Rectangle.NO_BORDER);

                propertyTable.addCell(propertycell1);
                propertyTable.addCell(propertycell2);
                propertyTable.addCell(propertycell3);

            }
            document.add(Chunk.NEWLINE);
            document.add(propertyTable);
            //////////////////////GET Propertys From Entity///////////////

            document.close();
            file.close();

            System.out.println("Pdf created successfully ! :)");

            String filePath = Report;
            File downloadFile = new File(filePath);
            FileInputStream inStream = new FileInputStream(downloadFile);

            // if you want to use a relative path to context root:
            String relativePath = getServletContext().getRealPath("");
            System.out.println("relativePath = " + relativePath);

            // obtains ServletContext
            ServletContext context = getServletContext();

            // gets MIME type of the file
            String mimeType = context.getMimeType(filePath);
            if (mimeType == null) {
                // set to binary type if MIME mapping not found
                mimeType = "application/octet-stream";
            }
            System.out.println("MIME type: " + mimeType);

            // modifies response
            response.setContentType(mimeType);
            response.setContentLength((int) downloadFile.length());

            // forces download
            String headerKey = "Content-Disposition";
            String headerValue = String.format("attachment; filename=\"%s\"", downloadFile.getName());
            response.setHeader(headerKey, headerValue);

            // obtains response's output stream
            OutputStream outStream = response.getOutputStream();

            byte[] buffer = new byte[4096];
            int bytesRead = -1;

            while ((bytesRead = inStream.read(buffer)) != -1) {
                outStream.write(buffer, 0, bytesRead);
            }

            inStream.close();
            outStream.close();
            /////////////////

            processRequest(request, response);
        } catch (DocumentException ex) {
            Logger.getLogger(ManageAdmin.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:superlaskuttaja.logiikka.PdfExtractor.java

private void muodostaDokumentti(Document document, String laskunNumero, PdfWriter writer)
        throws DocumentException, SQLException, ParseException {
    document.open();//from www. j  ava  2s. c  o  m
    //----------------------------------------------------------------------
    PdfPTable table1 = new PdfPTable(7);
    Font f1 = new Font(Font.FontFamily.HELVETICA, 10);
    Font f2 = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD);
    Font f3 = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD);
    Font f4 = new Font(Font.FontFamily.HELVETICA, 16, Font.BOLD);
    ResultSet rs = lataaja.getDbc()
            .executeQuery("select distinct Laskuttaja.yrityksenNimi, Laskuttaja.katuosoite,\n"
                    + "Laskuttaja.postinumero, Laskuttaja.kaupunki, Lasku.paivays, Laskuttaja.alvTunniste,\n"
                    + "Pankkiviivakoodi.erapaiva, Lasku.viivastyskorko, Pankkiviivakoodi.viiteTarkisteella,\n"
                    + "T.nimi, Lasku.maksuehto, T.katuosoite, Laskuttaja.tilinumeronPankki,\n"
                    + "T.postinumero, T.kaupunki, Laskuttaja.tilinumero, T.email, Laskuttaja.tilinumeronSwiftBic,\n"
                    + "V.nimi, V.katuosoite, V.postinumero, V.kaupunki, V.email, Lasku.lisatiedot,\n"
                    + "T.asiakasnumero, V.asiakasnumero, Laskuttaja.nimi, Laskuttaja.puhelinnumero,\n"
                    + "Laskuttaja.sahkopostiOsoite, Pankkiviivakoodi.pankkiviivakoodi\n"
                    + "from Lasku, Pankkiviivakoodi, Laskuttaja, Suorite, Asiakas T, Asiakas V\n"
                    + "where Lasku.laskunNumero = " + laskunNumero + "\n"
                    + "and Lasku.laskuttaja = Laskuttaja.yrityksenNimi\n"
                    + "and Lasku.laskuttajanVersio = Laskuttaja.versio\n"
                    + "and Lasku.pankkiviivakoodi = Pankkiviivakoodi.pankkiviivakoodi\n"
                    + "and Lasku.laskunnumero = Suorite.lasku\n" + "and Suorite.tilaaja = T.asiakasnumero\n"
                    + "and Suorite.tilaajanVersio = T.versio\n"
                    + "and Suorite.vastaanottaja = V.asiakasnumero\n"
                    + "and Suorite.vastaanottajanVersio = V.versio\n" + "");
    rs.first();
    table1.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin()));
    table1.setLockedWidth(true);
    table1.setWidths(new int[] { 370, 100, 73, 100, 73, 100, 179 });
    PdfPCell cell;
    Paragraph p;

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    p = new Paragraph(rs.getString(1), f4);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table1.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    p = new Paragraph("LASKU", f4);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table1.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table1.addCell(cell);

    table1.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(7);
    p = new Paragraph(rs.getString(2), f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table1.addCell(cell);

    table1.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    p = new Paragraph(rs.getString(3) + " " + rs.getString(4), f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table1.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    p = new Paragraph("Pivys", f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.LIGHT_GRAY);
    table1.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    p = new Paragraph(pvmFormaatti1.format(pvmFormaatti3.parse(rs.getTimestamp(5).toString())), f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.LIGHT_GRAY);
    table1.addCell(cell);

    table1.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table1.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    p = new Paragraph("Laskun numero", f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.LIGHT_GRAY);
    table1.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    p = new Paragraph(laskunNumero, f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.LIGHT_GRAY);
    table1.addCell(cell);

    table1.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    p = new Paragraph("Alv-tunniste: " + rs.getString(6), f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table1.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    p = new Paragraph("Erpiv", f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.LIGHT_GRAY);
    table1.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    p = new Paragraph(pvmFormaatti1.format(pvmFormaatti4.parse(rs.getDate(7).toString())), f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.LIGHT_GRAY);
    table1.addCell(cell);

    table1.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table1.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    p = new Paragraph("Viivstyskorko", f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.LIGHT_GRAY);
    table1.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    p = new Paragraph(Integer.toString(rs.getInt(8)) + ".0%", f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.LIGHT_GRAY);
    table1.addCell(cell);

    table1.completeRow();

    //Jos vastaanottaja on sama kuin tilaaja ei laiteta erikseen vastaanottajan tietoja nkyville.
    if (rs.getInt(25) == rs.getInt(26)) {
        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(3);
        p = new Paragraph(rs.getString(10), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph("Viitenumero", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph(rs.getString(9), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(3);
        p = new Paragraph(rs.getString(12), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph("Maksuehto", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph(rs.getString(11), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(3);
        p = new Paragraph(rs.getString(14) + " " + rs.getString(15), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph("Pankki", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph(rs.getString(13), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(3);
        p = new Paragraph(rs.getString(17), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph("Tilinumero", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph(rs.getString(16), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(3);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph("Swift/BIC", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph(rs.getString(18), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph(" ", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph("Listiedot", f2);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph(rs.getString(24), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph(" ", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        document.add(table1);
    } else {
        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(3);
        p = new Paragraph("Palvelun tilaaja", f2);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph("Viitenumero", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph(rs.getString(9), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(3);
        p = new Paragraph(rs.getString(10), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph("Maksuehto", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph(rs.getString(11), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(3);
        p = new Paragraph(rs.getString(12), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph("Pankki", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph(rs.getString(13), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(3);
        p = new Paragraph(rs.getString(14) + " " + rs.getString(15), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph("Tilinumero", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph(rs.getString(16), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(3);
        p = new Paragraph(rs.getString(17), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph("Swift/BIC", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(2);
        p = new Paragraph(rs.getString(18), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
        cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
        cell.setBorderColor(BaseColor.LIGHT_GRAY);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph("Palvelun vastaanottaja", f2);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph(rs.getString(19), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph(rs.getString(20), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph(rs.getString(21) + " " + rs.getString(22), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph(rs.getString(23), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph("Listiedot", f2);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph(rs.getString(24), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(7);
        p = new Paragraph(" ", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        table1.addCell(cell);

        table1.completeRow();

        document.add(table1);
    }

    // Otetaan alemmas tulevia tietoja talteen.
    String[] alasTulevatTiedot = new String[] { rs.getString(9), rs.getString(1), rs.getString(27),
            rs.getString(13), rs.getString(2), rs.getString(28), rs.getString(16),
            rs.getString(3) + " " + rs.getString(4), rs.getString(29), rs.getString(18), rs.getString(30), };

    //Muodostetaan suoritteiden taulukko.
    PdfPTable table2 = new PdfPTable(7);
    table2.setWidths(new int[] { 370, 100, 73, 100, 73, 100, 179 });
    table2.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin()));
    table2.setLockedWidth(true);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph("Kuvaus", f2);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.BLACK);
    cell.setBorderWidth(0.2f);
    table2.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph("Mr", f2);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.BLACK);
    cell.setBorderWidth(0.2f);
    table2.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph("Yks.", f2);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.BLACK);
    cell.setBorderWidth(0.2f);
    table2.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(" hinta", f2);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.BLACK);
    cell.setBorderWidth(0.2f);
    table2.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph("Alv %", f2);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.BLACK);
    cell.setBorderWidth(0.2f);
    table2.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph("Alv ", f2);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.BLACK);
    cell.setBorderWidth(0.2f);
    table2.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph("Yhteens", f2);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
    cell.setBorder(LEFT + BOTTOM + RIGHT + TOP);
    cell.setBorderColor(BaseColor.BLACK);
    cell.setBorderWidth(0.2f);
    table2.addCell(cell);

    table2.completeRow();

    rs = lataaja.getDbc().executeQuery(
            "select distinct kuvaus, maara, maaranYksikot, aHintaVeroton, alvProsentti, ((alvProsentti / 100.0) * aHintaVeroton * maara) as alvEuroa,\n"
                    + "((1.0 + alvProsentti / 100.0) * aHintaVeroton * maara) as yht, alkuaika\n"
                    + "from Suorite\n" + "where lasku = " + laskunNumero + "\n" + "");

    while (rs.next()) {
        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(1);
        p = new Paragraph(rs.getString(1) + " "
                + pvmFormaatti1.format(pvmFormaatti3.parse(rs.getTimestamp(8).toString())), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_LEFT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBorder(LEFT + RIGHT);
        cell.setBorderColor(BaseColor.BLACK);
        cell.setBorderWidth(0.2f);
        table2.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(1);
        p = new Paragraph(rs.getBigDecimal(2, 2).toString(), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBorder(LEFT + RIGHT);
        cell.setBorderColor(BaseColor.BLACK);
        cell.setBorderWidth(0.2f);
        table2.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(1);
        p = new Paragraph(rs.getString(3), f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBorder(LEFT + RIGHT);
        cell.setBorderColor(BaseColor.BLACK);
        cell.setBorderWidth(0.2f);
        table2.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(1);
        p = new Paragraph(rs.getBigDecimal(4, 2).toString() + "", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBorder(LEFT + RIGHT);
        cell.setBorderColor(BaseColor.BLACK);
        cell.setBorderWidth(0.2f);
        table2.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(1);
        p = new Paragraph(rs.getString(5) + "%", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBorder(LEFT + RIGHT);
        cell.setBorderColor(BaseColor.BLACK);
        cell.setBorderWidth(0.2f);
        table2.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(1);
        p = new Paragraph(rs.getBigDecimal(6, 2).toString() + "", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBorder(LEFT + RIGHT);
        cell.setBorderColor(BaseColor.BLACK);
        cell.setBorderWidth(0.2f);
        table2.addCell(cell);

        cell = new PdfPCell();
        cell.setBorder(Rectangle.NO_BORDER);
        cell.setColspan(1);
        p = new Paragraph(rs.getBigDecimal(7, 2).toString() + "", f1);
        p.setLeading(0, 1);
        p.setAlignment(Element.ALIGN_RIGHT);
        cell.addElement(p);
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setBorder(LEFT + RIGHT);
        cell.setBorderColor(BaseColor.BLACK);
        cell.setBorderWidth(0.2f);
        table2.addCell(cell);

        table2.completeRow();
    }

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(7);
    p = new Paragraph(" ", f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBorder(TOP);
    cell.setBorderColor(BaseColor.BLACK);
    cell.setBorderWidth(0.2f);
    table2.addCell(cell);

    table2.completeRow();

    rs = lataaja.getDbc().executeQuery(
            "select distinct sum(aHintaVeroton * maara), sum((alvProsentti / 100.0) * aHintaVeroton * maara)\n"
                    + "from Suorite\n" + "where lasku = " + laskunNumero + "\n" + "");

    rs.first();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table2.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    p = new Paragraph("Veroton hinta yhteens", f2);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table2.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(rs.getBigDecimal(1, 2).toString() + "", f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table2.addCell(cell);

    table2.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table2.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    p = new Paragraph("Arvonlisvero yhteens", f2);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table2.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(rs.getBigDecimal(2, 2).toString() + "", f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table2.addCell(cell);

    table2.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(7);
    p = new Paragraph(" ", f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table2.addCell(cell);

    table2.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(4);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table2.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(2);
    p = new Paragraph("Yhteens", f3);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table2.addCell(cell);

    rs = lataaja.getDbc()
            .executeQuery("select laskunSumma\n" + "from Lasku, Pankkiviivakoodi\n" + "where laskunNumero = "
                    + laskunNumero + "\n" + "and Lasku.pankkiviivakoodi = Pankkiviivakoodi.pankkiviivakoodi\n"
                    + "");

    rs.first();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(rs.getBigDecimal(1, 2).toString() + "", f3);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table2.addCell(cell);

    table2.completeRow();

    document.add(table2);

    PdfPTable table3 = new PdfPTable(3);
    table3.setWidths(new int[] { 1, 1, 1 });
    table3.setTotalWidth(document.right(document.rightMargin()) - document.left(document.leftMargin()));
    table3.setLockedWidth(true);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    p = new Paragraph("Pyydmme kyttmn maksaessanne viitenumeroa: " + alasTulevatTiedot[0], f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    table3.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    p = new Paragraph(" ", f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    cell.setBorder(BOTTOM);
    cell.setBorderColor(BaseColor.BLACK);
    cell.setBorderWidth(0.2f);
    table3.addCell(cell);

    table3.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(alasTulevatTiedot[1], f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(alasTulevatTiedot[2], f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(alasTulevatTiedot[3], f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    table3.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(alasTulevatTiedot[4], f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(alasTulevatTiedot[5], f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(alasTulevatTiedot[6], f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    table3.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(alasTulevatTiedot[7], f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_LEFT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(alasTulevatTiedot[8], f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(1);
    p = new Paragraph(alasTulevatTiedot[9], f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    table3.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    p = new Paragraph(" ", f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_RIGHT);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    table3.completeRow();

    cell = new PdfPCell();
    cell.setBorder(Rectangle.NO_BORDER);
    cell.setColspan(3);
    p = new Paragraph("Virtuaaliviivakoodi: " + alasTulevatTiedot[10], f1);
    p.setLeading(0, 1);
    p.setAlignment(Element.ALIGN_CENTER);
    cell.addElement(p);
    cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    table3.addCell(cell);

    table3.completeRow();

    table3.writeSelectedRows(0, -1, document.left(document.leftMargin()),
            table3.getTotalHeight() + document.bottom(document.bottomMargin()), writer.getDirectContent());
    //----------------------------------------------------------------------
    document.close();

}

From source file:tn.com.hitechart.eds.Util.pdfRpport.FirstPdf.java

private void createTable(Section subCatPart) throws BadElementException {

    //-------------------------- TAB POINTAGE -------------------//
    PdfPTable table = new PdfPTable(8);
    table.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    table.setLockedWidth(true);/*  w ww.ja  va  2 s .  c  o m*/
    // t.setBorderColor(BaseColor.GRAY);
    // t.setPadding(4);
    // t.setSpacing(4);
    // t.setBorderWidth(1);
    //----------- C1 --------------//
    PdfPCell c1 = new PdfPCell(new Phrase("Date Rapport"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C2 --------------//
    c1 = new PdfPCell(new Phrase("Technicien"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C3 --------------//
    c1 = new PdfPCell(new Phrase("Poinatge"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    //----------- C4 --------------//
    c1 = new PdfPCell(new Phrase("Matin"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);
    //----------- C5 --------------//
    c1 = new PdfPCell(new Phrase("Aprs-Midi"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    //----------- C6 --------------//
    c1 = new PdfPCell(new Phrase("Rapport Journalier", catFont));
    c1.setBorder(Rectangle.NO_BORDER);
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setColspan(3);
    table.addCell(c1);
    //----------- C7 --------------//

    //----------- C8 --------------//

    table.setHeaderRows(1);

    //----------- R2 --------------//
    //----------- C1 --------------//
    c1 = new PdfPCell(new Phrase(tabDatapointage[0], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setRowspan(2);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(user.getLogin(), dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    c1.setRowspan(2);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase("Arrive"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[1], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[2], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C7 --------------//

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C8 --------------//

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);

    //----------- R3 --------------//

    c1 = new PdfPCell(new Phrase("Sortie"));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[3], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(tabDatapointage[4], dataFont));
    c1.setHorizontalAlignment(Element.ALIGN_CENTER);
    table.addCell(c1);

    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C7 --------------//
    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    //----------- C8 --------------//
    c1 = new PdfPCell(new Phrase(""));
    c1.setBorder(Rectangle.NO_BORDER);
    table.addCell(c1);
    table.setSpacingAfter(10);
    subCatPart.add(table);

    //-------------------------- END TAB POINTAGE -------------------//
    // TODO: 20/01/2017
    //--------------------------------- TASK ---------------------//
    PdfPTable tableTask = new PdfPTable(5);

    tableTask.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableTask.setLockedWidth(true);

    PdfPCell c2 = new PdfPCell(new Phrase("Dossiers Traits", catFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    c2.setColspan(5);
    c2.setBorder(Rectangle.NO_BORDER);
    tableTask.addCell(c2);

    tableTask.setHeaderRows(1);

    c2 = new PdfPCell(new Phrase("NDoss.", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Client", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Dure", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Mission", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);

    c2 = new PdfPCell(new Phrase("Resultat", dataFont));
    c2.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableTask.addCell(c2);
    if (tasks.isEmpty()) {
        c2 = new PdfPCell(new Phrase("Aucune  Tache a t trait", catFontempty));
        c2.setHorizontalAlignment(Element.ALIGN_CENTER);
        c2.setColspan(5);
        tableTask.addCell(c2);
    } else {

        if (!dossiers.isEmpty()) {
            for (Dossier d : dossiers) {

                tableTask.addCell(d.getNumDoss());
                tableTask.addCell(d.getClient());
                tableTask.addCell(convertLongtoDurationfr(d.getTimeDuration()));
                tableTask.addCell(td.getTaskById(d.get_idTask()).getType());
                tableTask.addCell(td.getTaskById(d.get_idTask()).getRes());
            }
        }

    }

    tableTask.setSpacingAfter(10);

    subCatPart.add(tableTask);

    //-------------------------- END TAB TASK -------------------//
    // TODO: 20/01/2017  tab achat
    //-------------------------- TAB ACHAT -------------------//

    PdfPTable tableAchat = new PdfPTable(3);

    tableAchat.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableAchat.setLockedWidth(true);

    PdfPCell c3 = new PdfPCell(new Phrase("Frais Engags", catFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    c3.setColspan(3);
    c3.setBorder(Rectangle.NO_BORDER);
    tableAchat.addCell(c3);

    tableAchat.setHeaderRows(1);
    c3 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAchat.addCell(c3);

    c3 = new PdfPCell(new Phrase("Dsignation", dataFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAchat.addCell(c3);

    c3 = new PdfPCell(new Phrase("Montant TCC", dataFont));
    c3.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAchat.addCell(c3);
    if (achats.isEmpty()) {
        c3 = new PdfPCell(new Phrase("la liste des achats est vide", catFontempty));
        c3.setHorizontalAlignment(Element.ALIGN_CENTER);
        c3.setColspan(3);
        tableAchat.addCell(c3);
    } else {

        for (Achat achat : achats) {

            tableAchat.addCell(String.valueOf(achat.getNumDoss()));
            tableAchat.addCell(achat.getDesignation());
            tableAchat.addCell(String.valueOf(achat.getPrix()));
        }
    }
    tableAchat.setSpacingAfter(10);
    subCatPart.add(tableAchat);
    //-------------------------- END TAB ACHAT -------------------//

    // TODO: 20/01/2017  tab composant
    //-------------------------- TAB COMPOSANT -------------------//

    PdfPTable tableComp = new PdfPTable(3);

    tableComp.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableComp.setLockedWidth(true);

    PdfPCell c4 = new PdfPCell(new Phrase("Composants", catFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    c4.setColspan(3);
    c4.setBorder(Rectangle.NO_BORDER);
    tableComp.addCell(c4);
    tableComp.setHeaderRows(1);

    c4 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableComp.addCell(c4);

    c4 = new PdfPCell(new Phrase("Dsignation", dataFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableComp.addCell(c4);

    c4 = new PdfPCell(new Phrase("Quantit", dataFont));
    c4.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableComp.addCell(c4);

    if (comps.isEmpty()) {
        c4 = new PdfPCell(new Phrase("la liste des composants est vide", catFontempty));
        c4.setHorizontalAlignment(Element.ALIGN_CENTER);
        c4.setColspan(3);
        tableComp.addCell(c4);
    } else {
        for (Composant comp : comps) {

            tableComp.addCell(String.valueOf(comp.getNumDoss()));
            tableComp.addCell(comp.getName());
            tableComp.addCell(String.valueOf(comp.getQte()));
        }
    }
    tableComp.setSpacingAfter(10);
    subCatPart.add(tableComp);
    //-------------------------- END TAB COMPOSANT -------------------//

    // TODO: 20/01/2017  tab message
    //-------------------------- TAB MESSAGE -------------------//

    PdfPTable tableMsg = new PdfPTable(2);

    tableMsg.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableMsg.setLockedWidth(true);

    PdfPCell c5 = new PdfPCell(new Phrase("Message  Transmettre", catFont));
    c5.setHorizontalAlignment(Element.ALIGN_CENTER);
    c5.setColspan(3);
    c5.setBorder(Rectangle.NO_BORDER);
    tableMsg.addCell(c5);

    c5 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c5.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableMsg.addCell(c5);

    tableMsg.setHeaderRows(1);
    c5 = new PdfPCell(new Phrase("Message", dataFont));
    c5.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableMsg.addCell(c5);

    tableMsg.setHeaderRows(1);
    if (msgs.isEmpty()) {
        c5 = new PdfPCell(new Phrase("Aucun message", catFontempty));
        c5.setHorizontalAlignment(Element.ALIGN_CENTER);
        c5.setColspan(3);
        tableMsg.addCell(c5);
    } else {
        for (Message msg : msgs) {

            tableMsg.addCell(String.valueOf(msg.getNumDoss()));
            tableMsg.addCell(msg.getMsg());
        }
    }
    tableMsg.setSpacingAfter(10);
    subCatPart.add(tableMsg);
    //-------------------------- END TAB MESSAGE -------------------//

    // TODO: 20/01/2017  tab Activitee
    //-------------------------- TAB ACTIVITEE -------------------//

    PdfPTable tableAct = new PdfPTable(2);

    tableAct.setTotalWidth(PageSize.A4.rotate().getWidth() - 10);
    tableAct.setLockedWidth(true);

    PdfPCell c6 = new PdfPCell(new Phrase("Autre Activites", catFont));
    c6.setHorizontalAlignment(Element.ALIGN_CENTER);
    c6.setColspan(2);
    c6.setBorder(Rectangle.NO_BORDER);
    tableAct.addCell(c6);

    tableAct.setHeaderRows(1);

    c6 = new PdfPCell(new Phrase("N.Doss.", dataFont));
    c6.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAct.addCell(c6);

    c6 = new PdfPCell(new Phrase("Dure", dataFont));
    c6.setHorizontalAlignment(Element.ALIGN_CENTER);
    tableAct.addCell(c6);
    if (autreActs.isEmpty()) {
        c6 = new PdfPCell(new Phrase("Aucune autre Activite a t effectu", catFontempty));
        c6.setHorizontalAlignment(Element.ALIGN_CENTER);
        c6.setColspan(3);
        tableAct.addCell(c6);
    } else {

        for (Task autreA : autreActs) {

            tableAct.addCell(String.valueOf(autreA.getType()));
            tableAct.addCell(autreA.getNumDoss());
        }

    }
    tableAct.setSpacingAfter(10);
    subCatPart.add(tableAct);
    //-------------------------- END TAB MESSAGE -------------------//
}

From source file:utilities.itext.Turnover.java

private static Paragraph createTablesWithDetails(ArrayList<PaymentPosition> data) throws DocumentException {
    Paragraph paragraph = new Paragraph();

    PdfPTable expense = new PdfPTable(2);
    float[] colWidths = { 5f, 1f };
    expense.setWidths(colWidths);//from w  w w  .ja  v  a2  s. co m

    int lastPaymentID = 0;
    for (PaymentPosition pp : data) {
        if (lastPaymentID != pp.getPayment().getId()) {
            //new Payment
            Paragraph p1 = new Paragraph(pp.getPayment().getPayee().getName());
            PdfPCell c1 = new PdfPCell(p1);

            //add next cell with price
            //calc price
            BigDecimal totalPrice = new BigDecimal(BigInteger.ZERO);
            for (PaymentPosition payPos : data) {
                if (payPos.getPayment().getId() == pp.getPayment().getId()) {
                    totalPrice = totalPrice.add(payPos.getTotalPrice());
                }
            }
            Paragraph p2 = new Paragraph(totalPrice.toPlainString());
            PdfPCell c2 = new PdfPCell(p2);

            c1.setBorder(Rectangle.NO_BORDER);
            c1.setBorderWidthTop(0.5f);
            c2.setBorder(Rectangle.NO_BORDER);
            c2.setBorderWidthTop(0.5f);

            expense.addCell(c1);
            expense.addCell(c2);
        }

        //payment position
        Paragraph p1 = new Paragraph("            " + pp.getQuantity() + "x: " + pp.getArticle().getName());
        PdfPCell c1 = new PdfPCell(p1);

        //add next cell with price
        Paragraph p2 = new Paragraph(pp.getTotalPriceAsString());
        PdfPCell c2 = new PdfPCell(p2);

        c1.setBorder(Rectangle.NO_BORDER);
        c2.setBorder(Rectangle.NO_BORDER);

        expense.addCell(c1);
        expense.addCell(c2);

        lastPaymentID = pp.getPayment().getId();
    }

    paragraph.add(expense);

    paragraph.setSpacingBefore(10f);

    return paragraph;
}

From source file:Valuacion.Reportes.java

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    // TODO add your handling code here:
    h = new Herramientas(usr, 0);
    h.session(sessionPrograma);/*from  ww w. j  a  v a2  s  .c o m*/
    if (t_datos.getRowCount() > 0) {
        javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
        jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.pdf)", new String[] { "pdf" }));
        String ruta = null;
        if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
            ruta = jF1.getSelectedFile().getAbsolutePath();
            if (ruta != null) {
                Session session = HibernateUtil.getSessionFactory().openSession();
                try {
                    DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
                    formatoPorcentaje.setMinimumFractionDigits(2);
                    session.beginTransaction().begin();
                    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
                            BaseFont.NOT_EMBEDDED);
                    //Orden ord=buscaApertura();
                    PDF reporte = new PDF();
                    Date fecha = new Date();
                    DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyyHH-mm-ss");//YYYY-MM-DD HH:MM:SS
                    String valor = dateFormat.format(fecha);

                    reporte.Abrir2(PageSize.LETTER.rotate(), "Valuacin", ruta + ".pdf");
                    Font font = new Font(Font.FontFamily.HELVETICA, 5, Font.BOLD);
                    BaseColor contenido = BaseColor.WHITE;
                    int centro = Element.ALIGN_CENTER;
                    int izquierda = Element.ALIGN_LEFT;
                    int derecha = Element.ALIGN_RIGHT;
                    float[] nuevos = new float[tam_pdf.size()];
                    for (int q = 0; q < tam_pdf.size(); q++) {
                        nuevos[q] = Float.parseFloat(tam_pdf.get(q).toString());
                    }

                    PdfPTable tabla = reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_LEFT);

                    cabecera(reporte, bf, tabla);
                    int ren = 0;
                    double dm = 0d, cam = 0d, min = 0d, med = 0d, max = 0d, pin = 0d, tot = 0d;
                    double cia = 0d, refacciones = 0d, autorizado = 0d, presupuesto = 0d, directo = 0d,
                            tot_m = 0d, compras = 0d, aut = 0d, mo_dir = 0d, cotizado = 0d;
                    for (int i = 0; i < t_datos.getRowCount(); i++) {
                        for (int j = 0; j < t_datos.getColumnCount(); j++) {
                            if (t_datos.getColumnName(j).compareTo("Cia/Seg") == 0
                                    || t_datos.getColumnName(j).compareTo("Costo Refacciones") == 0
                                    || t_datos.getColumnName(j).compareTo("Autorizado") == 0
                                    || t_datos.getColumnName(j).compareTo("M.O. Presup.") == 0
                                    || t_datos.getColumnName(j).compareTo("M.O. Directa") == 0
                                    || t_datos.getColumnName(j).compareTo("Tot M.O") == 0
                                    || t_datos.getColumnName(j).compareTo("Compras") == 0
                                    || t_datos.getColumnName(j).compareTo("Aut. Dir.") == 0
                                    || t_datos.getColumnName(j).compareTo("M.O Directa") == 0
                                    || t_datos.getColumnName(j).compareTo("Cotizado") == 0) {
                                if (t_datos.getValueAt(i, j) != null) {
                                    tabla.addCell(
                                            reporte.celda(formatoPorcentaje.format(t_datos.getValueAt(i, j)),
                                                    font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));

                                    if (t_datos.getColumnName(j).compareTo("Cia/Seg") == 0) {
                                        cia += (double) t_datos.getValueAt(i, j);
                                    }
                                    if (t_datos.getColumnName(j).compareTo("Costo Refacciones") == 0) {
                                        refacciones += (double) t_datos.getValueAt(i, j);
                                    }
                                    if (t_datos.getColumnName(j).compareTo("Autorizado") == 0) {
                                        autorizado += (double) t_datos.getValueAt(i, j);
                                    }
                                    if (t_datos.getColumnName(j).compareTo("M.O. Presup.") == 0) {
                                        presupuesto += (double) t_datos.getValueAt(i, j);
                                    }
                                    if (t_datos.getColumnName(j).compareTo("M.O. Directa") == 0) {
                                        directo += (double) t_datos.getValueAt(i, j);
                                    }
                                    if (t_datos.getColumnName(j).compareTo("Tot M.O") == 0) {
                                        tot_m += (double) t_datos.getValueAt(i, j);
                                    }
                                    if (t_datos.getColumnName(j).compareTo("Compras") == 0) {
                                        compras += (double) t_datos.getValueAt(i, j);
                                    }
                                    if (t_datos.getColumnName(j).compareTo("Aut. Dir.") == 0) {
                                        aut += (double) t_datos.getValueAt(i, j);
                                    }
                                    if (t_datos.getColumnName(j).compareTo("M.O Directa") == 0) {
                                        mo_dir += (double) t_datos.getValueAt(i, j);
                                    }
                                    if (t_datos.getColumnName(j).compareTo("Cotizado") == 0) {
                                        cotizado += (double) t_datos.getValueAt(i, j);
                                    }
                                } else
                                    tabla.addCell(reporte.celda("0.00", font, contenido, derecha, 0, 1,
                                            Rectangle.RECTANGLE));
                            } else {
                                if (t_datos.getValueAt(i, j) != null)
                                    tabla.addCell(reporte.celda("" + t_datos.getValueAt(i, j), font, contenido,
                                            izquierda, 0, 1, Rectangle.RECTANGLE));
                                else
                                    tabla.addCell(reporte.celda("", font, contenido, izquierda, 0, 1,
                                            Rectangle.RECTANGLE));
                            }
                        }
                        /*if(ren==38)
                        {
                            reporte.agregaObjeto(tabla);
                            reporte.writer.newPage();
                            tabla=reporte.crearTabla(nuevos.length, nuevos, 100, Element.ALIGN_LEFT);
                            cabecera(reporte, bf, tabla);
                            ren=-1;
                        }
                        ren++;*/
                    }
                    for (int j = 0; j < t_datos.getColumnCount(); j++) {
                        boolean entro = false;
                        if (t_datos.getColumnName(j).compareTo("Cia/Seg") == 0) {
                            tabla.addCell(reporte.celda(formatoPorcentaje.format(cia), font, contenido, derecha,
                                    0, 1, Rectangle.RECTANGLE));
                            entro = true;
                        }
                        if (t_datos.getColumnName(j).compareTo("Costo Refacciones") == 0) {
                            tabla.addCell(reporte.celda(formatoPorcentaje.format(refacciones), font, contenido,
                                    derecha, 0, 1, Rectangle.RECTANGLE));
                            entro = true;
                        }
                        if (t_datos.getColumnName(j).compareTo("Autorizado") == 0) {
                            tabla.addCell(reporte.celda(formatoPorcentaje.format(autorizado), font, contenido,
                                    derecha, 0, 1, Rectangle.RECTANGLE));
                            entro = true;
                        }
                        if (t_datos.getColumnName(j).compareTo("M.O. Presup.") == 0) {
                            tabla.addCell(reporte.celda(formatoPorcentaje.format(presupuesto), font, contenido,
                                    derecha, 0, 1, Rectangle.RECTANGLE));
                            entro = true;
                        }
                        if (t_datos.getColumnName(j).compareTo("M.O. Directa") == 0) {
                            tabla.addCell(reporte.celda(formatoPorcentaje.format(directo), font, contenido,
                                    derecha, 0, 1, Rectangle.RECTANGLE));
                            entro = true;
                        }
                        if (t_datos.getColumnName(j).compareTo("Tot M.O") == 0) {
                            tabla.addCell(reporte.celda(formatoPorcentaje.format(tot_m), font, contenido,
                                    derecha, 0, 1, Rectangle.RECTANGLE));
                            entro = true;
                        }
                        if (t_datos.getColumnName(j).compareTo("Compras") == 0) {
                            tabla.addCell(reporte.celda(formatoPorcentaje.format(compras), font, contenido,
                                    derecha, 0, 1, Rectangle.RECTANGLE));
                            entro = true;
                        }
                        if (t_datos.getColumnName(j).compareTo("Aut. Dir.") == 0) {
                            tabla.addCell(reporte.celda(formatoPorcentaje.format(aut), font, contenido, derecha,
                                    0, 1, Rectangle.RECTANGLE));
                            entro = true;
                        }
                        if (t_datos.getColumnName(j).compareTo("M.O Directa") == 0) {
                            tabla.addCell(reporte.celda(formatoPorcentaje.format(mo_dir), font, contenido,
                                    derecha, 0, 1, Rectangle.RECTANGLE));
                            entro = true;
                        }
                        if (t_datos.getColumnName(j).compareTo("Cotizado") == 0) {
                            tabla.addCell(reporte.celda(formatoPorcentaje.format(cotizado), font, contenido,
                                    derecha, 0, 1, Rectangle.RECTANGLE));
                            entro = true;
                        }
                        if (entro == false) {
                            tabla.addCell(
                                    reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.NO_BORDER));
                        }
                    }
                    tabla.setHeaderRows(1);
                    reporte.agregaObjeto(tabla);
                    reporte.cerrar();
                    reporte.visualizar2(ruta + ".pdf");
                } catch (Exception e) {
                    System.out.println(e);
                    e.printStackTrace();
                    JOptionPane.showMessageDialog(this,
                            "No se pudo realizar el reporte si el archivo esta abierto.");
                }
                if (session != null)
                    if (session.isOpen())
                        session.close();
            }
        }
    }
}

From source file:Valuacion.valuacion.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
     // TODO add your handling code here:
     //h=new Herramientas(user, 0);
     //h.session(sessionPrograma);
     Session session = HibernateUtil.getSessionFactory().openSession();
     try {//from  www  . ja  va 2 s  . c o m
         DecimalFormat formatoPorcentaje = new DecimalFormat("#,##0.00");
         DecimalFormat formatoDecimal = new DecimalFormat("####0.0");
         formatoPorcentaje.setMinimumFractionDigits(2);
         session.beginTransaction().begin();
         BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
         //Orden ord=buscaApertura();
         PDF reporte = new PDF();
         Date fecha = 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();
         reporte.Abrir(PageSize.LETTER, "Valuacin",
                 "reportes/" + ord.getIdOrden() + "/" + valor + "-valuacion.pdf");
         Font font = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL);
         BaseColor contenido = BaseColor.WHITE;
         int centro = Element.ALIGN_CENTER;
         int izquierda = Element.ALIGN_LEFT;
         int derecha = Element.ALIGN_RIGHT;
         float tam[] = new float[] { 15, 15, 60, 140, 14, 14, 14, 14, 14, 14, 25 };
         PdfPTable tabla = reporte.crearTabla(11, tam, 100, Element.ALIGN_LEFT);

         cabecera(reporte, bf, tabla);
         int ren = 0;
         double dm = 0d, cam = 0d, min = 0d, med = 0d, max = 0d, pin = 0d, tot = 0d;
         for (int i = 0; i < t_datos.getRowCount(); i++) {
             if (t_datos.getValueAt(i, 38).toString().compareTo("e") != 0) {
                 double suma = 0d;
                 double v = 0.0d;
                 tabla.addCell(reporte.celda("" + t_datos.getValueAt(i, 10).toString(), font, contenido,
                         izquierda, 0, 1, Rectangle.RECTANGLE));
                 tabla.addCell(reporte.celda(t_datos.getValueAt(i, 11).toString(), font, contenido, izquierda, 0,
                         1, Rectangle.RECTANGLE));
                 tabla.addCell(reporte.celda(t_datos.getValueAt(i, 2).toString(), font, contenido, izquierda, 0,
                         0, Rectangle.RECTANGLE));

                 tabla.addCell(reporte.celda(t_datos.getValueAt(i, 3).toString(), font, contenido, izquierda, 0,
                         0, Rectangle.RECTANGLE));

                 if (t_datos.getValueAt(i, 4) != null) {
                     v = Double.parseDouble(t_datos.getValueAt(i, 4).toString())
                             * Double.parseDouble(t_datos.getValueAt(i, 10).toString());
                     tabla.addCell(
                             reporte.celda(new BigDecimal(v).setScale(2, BigDecimal.ROUND_HALF_UP).toString(),
                                     font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                     suma += Double.parseDouble(t_datos.getValueAt(i, 4).toString());
                     dm += v;
                 } else
                     tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));

                 if (t_datos.getValueAt(i, 8) != null) {
                     v = Double.parseDouble(t_datos.getValueAt(i, 8).toString())
                             * Double.parseDouble(t_datos.getValueAt(i, 10).toString());
                     tabla.addCell(
                             reporte.celda(new BigDecimal(v).setScale(2, BigDecimal.ROUND_HALF_UP).toString(),
                                     font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                     suma += Double.parseDouble(t_datos.getValueAt(i, 8).toString());
                     cam += v;
                 } else
                     tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));

                 if (t_datos.getValueAt(i, 5) != null) {
                     v = Double.parseDouble(t_datos.getValueAt(i, 5).toString())
                             * Double.parseDouble(t_datos.getValueAt(i, 10).toString());
                     tabla.addCell(
                             reporte.celda(new BigDecimal(v).setScale(2, BigDecimal.ROUND_HALF_UP).toString(),
                                     font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                     suma += Double.parseDouble(t_datos.getValueAt(i, 5).toString());
                     min += v;
                 } else
                     tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));

                 if (t_datos.getValueAt(i, 6) != null) {
                     v = Double.parseDouble(t_datos.getValueAt(i, 6).toString())
                             * Double.parseDouble(t_datos.getValueAt(i, 10).toString());
                     tabla.addCell(
                             reporte.celda(new BigDecimal(v).setScale(2, BigDecimal.ROUND_HALF_UP).toString(),
                                     font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                     suma += Double.parseDouble(t_datos.getValueAt(i, 6).toString());
                     med += v;
                 } else
                     tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));

                 if (t_datos.getValueAt(i, 7) != null) {
                     v = Double.parseDouble(t_datos.getValueAt(i, 7).toString())
                             * Double.parseDouble(t_datos.getValueAt(i, 10).toString());
                     tabla.addCell(
                             reporte.celda(new BigDecimal(v).setScale(2, BigDecimal.ROUND_HALF_UP).toString(),
                                     font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                     suma += Double.parseDouble(t_datos.getValueAt(i, 7).toString());
                     max += v;
                 } else
                     tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                 if (t_datos.getValueAt(i, 9) != null) {
                     v = Double.parseDouble(t_datos.getValueAt(i, 9).toString())
                             * Double.parseDouble(t_datos.getValueAt(i, 10).toString());
                     tabla.addCell(
                             reporte.celda(new BigDecimal(v).setScale(2, BigDecimal.ROUND_HALF_UP).toString(),
                                     font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));
                     suma += Double.parseDouble(t_datos.getValueAt(i, 9).toString());
                     pin += v;
                 } else
                     tabla.addCell(reporte.celda("", font, contenido, derecha, 0, 1, Rectangle.RECTANGLE));

                 suma *= ord.getCompania().getImporteHora();
                 suma *= Double.parseDouble(t_datos.getValueAt(i, 10).toString());
                 tabla.addCell(reporte.celda(formatoPorcentaje.format(suma), font, contenido, derecha, 0, 1,
                         Rectangle.RECTANGLE));
                 tot += suma;
                 /*if(ren==38)
                 {
                 reporte.agregaObjeto(tabla);
                 reporte.writer.newPage();
                        
                 tabla=reporte.crearTabla(11, tam, 100, Element.ALIGN_LEFT);
                 cabecera(reporte, bf, tabla);
                 ren=-1;
                 }
                 ren++;*/
             }
         }
         Double tot_horas = dm + cam + min + med + max + pin;
         tabla.addCell(reporte.celda(
                 "Costo M.O:$" + formatoPorcentaje.format(ord.getCompania().getImporteHora())
                         + "     Total de Horas:" + formatoDecimal.format(tot_horas),
                 font, contenido, derecha, 4, 1, Rectangle.RIGHT));
         tabla.addCell(reporte.celda("" + formatoDecimal.format(dm), font, contenido, derecha, 0, 1,
                 Rectangle.RECTANGLE));
         tabla.addCell(reporte.celda("" + formatoDecimal.format(cam), font, contenido, derecha, 0, 1,
                 Rectangle.RECTANGLE));
         tabla.addCell(reporte.celda("" + formatoDecimal.format(min), font, contenido, derecha, 0, 1,
                 Rectangle.RECTANGLE));
         tabla.addCell(reporte.celda("" + formatoDecimal.format(med), font, contenido, derecha, 0, 1,
                 Rectangle.RECTANGLE));
         tabla.addCell(reporte.celda("" + formatoDecimal.format(max), font, contenido, derecha, 0, 1,
                 Rectangle.RECTANGLE));
         tabla.addCell(reporte.celda("" + formatoDecimal.format(pin), font, contenido, derecha, 0, 1,
                 Rectangle.RECTANGLE));
         tabla.addCell(reporte.celda(formatoPorcentaje.format(tot), font, contenido, derecha, 0, 1,
                 Rectangle.RECTANGLE));
         tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 4, 1, Rectangle.NO_BORDER));
         tabla.addCell(reporte.celda(" ", font, contenido, izquierda, 7, 1, Rectangle.TOP));
         tabla.setHeaderRows(2);

         PdfPTable tabla1 = reporte.crearTabla(11, tam, 100, Element.ALIGN_LEFT);
         tabla1.addCell(reporte.celda("OBSERVACIONES", font, contenido, izquierda, 11, 1, Rectangle.NO_BORDER));
         tabla1.addCell(reporte.celda(" ", font, contenido, izquierda, 11, 1, Rectangle.BOTTOM));
         tabla1.addCell(reporte.celda(" ", font, contenido, izquierda, 11, 1, Rectangle.BOTTOM));
         tabla1.addCell(reporte.celda(" ", font, contenido, izquierda, 11, 1, Rectangle.BOTTOM));
         tabla1.addCell(reporte.celda(" ", font, contenido, izquierda, 11, 1, Rectangle.BOTTOM));

         reporte.agregaObjeto(tabla);
         reporte.agregaObjeto(tabla1);
         reporte.cerrar();
         reporte.visualizar("reportes/" + ord.getIdOrden() + "/" + valor + "-valuacion.pdf");
     } catch (Exception e) {
         e.printStackTrace();
         JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte si el archivo esta abierto.");
     }
     if (session != null)
         if (session.isOpen()) {
             session.flush();
             session.clear();
             session.close();
         }
 }

From source file:WeeklyReport.Sections.Commodities.java

public PdfPTable commoditySectionIntroduction() {
    PdfPTable table = new PdfPTable(1);
    table.setHorizontalAlignment(Element.ALIGN_MIDDLE);
    table.setWidthPercentage(100f);/*from w  w w. j a v a2s  . c om*/
    table.setSpacingBefore(10f);

    cell = new PdfPCell(new Phrase("COMMODITIES", SECTION_HEADING));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    // Get the top two commodities from the HashMap
    Map<String, String> m = new CargoTypeData().topTwoCommodities();
    //ArrayList to add the commodities to
    ArrayList<String> commodities = new ArrayList<>();
    m.entrySet().stream().forEach((entry) -> {
        commodities.add(entry.getKey());
    });

    cell = new PdfPCell(new Phrase("During week " + new ReportingDates().reportPeriod() + " a total of "
            + new CustomerQuoteData().totalQuotes()
            + " were generated through RQS. Of these quotes the top two commodity classes quoted were "
            + commodities.get(0) + " and " + commodities.get(1)
            + ". The below table depicts the top ten commodities quoted during week "
            + new ReportingDates().reportPeriod() + ".", TEXT_FONT));
    cell.setColspan(1);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);

    return table;
}

From source file:WeeklyReport.Sections.CoverPage.java

public PdfPTable coverTable() {
    table = new PdfPTable(1);
    cell = new PdfPCell(new Phrase("RQS Week " + REPORT_WEEK + " Quoting Report", TITLE_FONT));
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    cell.setBorder(Rectangle.NO_BORDER);
    table.addCell(cell);//from ww w  .  j  a  va  2 s .  c om

    return table;
}