Example usage for com.itextpdf.text Paragraph setAlignment

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

Introduction

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

Prototype

public void setAlignment(int alignment) 

Source Link

Document

Sets the alignment of this paragraph.

Usage

From source file:sistema.audizio.relatorio.Relatorio.java

public void gerar(Cliente cliente, Processo processo, Veiculo veiculo, Cidade cidade, Bairro bairro,
        Assessoria assesoria)//from  w  w  w.  j  av  a2s. com
        throws DocumentException, FileNotFoundException, BadElementException, IOException {

    String local = "c:\\sistema\\audisio\\relatorios\\" + cliente.getNome() + "-N P-" + processo.getProcesso()
            + ".pdf";

    Document document = new Document();
    //PdfWriter.getInstance(document, new FileOutputStream("C:\\Users\\ZipNet\\Desktop\\Pdf's\\teste.pdf"));
    PdfWriter.getInstance(document, new FileOutputStream(local));
    document.open();

    Font f = new Font(FontFamily.COURIER, 15, Font.NORMAL);
    Font fgrande = new Font(FontFamily.HELVETICA, 25, Font.ITALIC);

    Image img = Image.getInstance("c:/sistema/audisio/imagens/relatorio.png");
    img.setAlignment(Element.ALIGN_LEFT);

    Paragraph titulo = new Paragraph("Relatrio de processo", fgrande);
    Paragraph Clienteente = new Paragraph("DADOS CLIENTE");
    Paragraph Processocesso = new Paragraph("DADOS PROCESSO");
    Paragraph veiculolo = new Paragraph("DADOS VE?CULO");

    titulo.setAlignment(Paragraph.ALIGN_RIGHT);
    Clienteente.setAlignment(Paragraph.ALIGN_CENTER);
    Processocesso.setAlignment(Paragraph.ALIGN_CENTER);
    veiculolo.setAlignment(Paragraph.ALIGN_CENTER);

    document.add(img);
    document.add(titulo);
    document.add(new Paragraph(" "));
    document.add(Clienteente);
    document.add(
            new Paragraph("______________________________________________________________________________"));

    document.add(new Paragraph("Nome..: " + cliente.getNome(), f));
    document.add(new Paragraph("Celular..: " + cliente.getCelular(), f));
    document.add(new Paragraph("Cep..: " + cliente.getCep(), f));
    document.add(new Paragraph("Cpf..: " + cliente.getCpf(), f));
    document.add(new Paragraph("Uf: " + cliente.getEstado(), f));
    document.add(new Paragraph("Endereo..: " + cliente.getEndereco() + ", " + cliente.getNum() + ", "
            + bairro.getNome() + ", " + cidade.getNome(), f));
    document.add(new Paragraph("E-mail..: " + cliente.getEmail(), f));
    document.add(new Paragraph(" "));
    document.add(veiculolo);
    document.add(
            new Paragraph("______________________________________________________________________________"));
    document.add(new Paragraph(" "));
    document.add(new Paragraph("Marca..: " + veiculo.getMarca(), f));
    document.add(new Paragraph("Modelo..: " + veiculo.getModelo(), f));
    document.add(new Paragraph("Placa..: " + veiculo.getPlaca(), f));
    document.add(new Paragraph("Estado..: " + veiculo.getEstado(), f));
    document.add(new Paragraph(" "));
    document.add(Processocesso);
    document.add(
            new Paragraph("______________________________________________________________________________"));
    document.add(new Paragraph(" "));
    document.add(new Paragraph("Processo..: " + processo.getProcesso(), f));
    document.add(new Paragraph("Data inicio..: " + processo.getData_inicio(), f));
    document.add(new Paragraph("Data trmino..: " + processo.getData_termino(), f));
    document.add(new Paragraph("Comarca..: " + processo.getComarca(), f));
    document.add(new Paragraph("Vara..: " + processo.getVara(), f));
    document.add(new Paragraph("Assesoria..: " + assesoria.getNome(), f));
    document.add(new Paragraph("Advogado..: " + assesoria.getNome_advogado(), f));
    document.close();
    JOptionPane.showMessageDialog(null, "RELATRIO CRIADO COM SUCESSO!\n" + local);

    try {
        java.awt.Desktop.getDesktop().open(new File(local));
    } catch (IOException ex) {
        Logger.getLogger(Cadastro.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:sistema.Minuta.java

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

    try {/*from  w w  w . j  a  v a 2  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:sistemacontrole.MainWindow.java

public void GerarPDFFuncao() throws BadElementException, IOException {
    try {//  w w  w. ja v  a2 s .co  m
        //Define as fontes
        Font fontOBS = new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.NORMAL);
        Font fontTITULO2 = new Font(Font.FontFamily.TIMES_ROMAN, 13, Font.NORMAL);
        Font fontTITULO = new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD);
        fontTITULO.setColor(BaseColor.RED);

        Font fontDADO = new Font(Font.FontFamily.TIMES_ROMAN, 9, Font.NORMAL);
        Document doc = new Document(PageSize.A4.rotate());

        // adiciona imagem ao pdf
        Image Logotipo = Image.getInstance("./src/Imagens/imagem_pdf.png");
        Logotipo.scalePercent((float) 47.5);
        PdfPTable tabelaGrfico = new PdfPTable(2);
        for (int i = 1; i < this.registro; i++) {
            Image LogotipoI = Image.getInstance("./Raw_Data/PainelEntrada" + i + ".jpg");
            Image LogotipoI2 = Image.getInstance("./Raw_Data/PainelSaida" + i + ".jpg");
            tabelaGrfico.addCell(LogotipoI);
            tabelaGrfico.addCell(LogotipoI2);
        }

        int count = this.tabelaDetalhes.getRowCount();

        PdfWriter.getInstance(doc, new FileOutputStream(TelaPDF.CampoNome.getText() + ".pdf"));
        doc.open();
        PdfPTable pdfTable = new PdfPTable(this.tabelaDetalhes.getColumnCount());
        //adding table headers
        for (int i = 0; i < 15; i++) {
            pdfTable.addCell(new Paragraph(this.tabelaDetalhes.getColumnName(i), fontTITULO));
        }

        PdfPTable pdfTableAuxiliar = new PdfPTable(this.tabelaDetalhes.getColumnCount());

        String[][] valores = new String[15][15];
        for (int i = 0; i < 15; i++) {
            for (int j = 0; j < 15; j++) {
                valores[i][j] = "";
            }
        }

        Object[] obj = null;
        int contador = 1;
        for (int i = 0; i < count; i++) {
            for (int j = 0; j < 15; j++) {
                try {
                    System.out.println("Valor: " + tabelaDetalhes.getModel().getValueAt(i, j).toString()
                            + "Contado: " + contador);
                    valores[i][j] = tabelaDetalhes.getModel().getValueAt(i, j).toString();

                } catch (Exception e) {
                    System.out.println("ERRO  DEU  contador: " + contador);
                    contador++;
                }

            }

        }

        for (int i = 0; i < count; i++) {
            for (int j = 0; j < 15; j++) {
                pdfTableAuxiliar.addCell(new Paragraph(valores[i][j], fontDADO));
            }
        }

        Paragraph title = new Paragraph("Sistema de Controle de Tanques - TC Control" + "\n\n", fontTITULO2);
        title.setAlignment(Paragraph.ALIGN_CENTER);

        Calendar calendar = new GregorianCalendar();
        Date trialTime = new Date();
        calendar.setTime(trialTime);
        Paragraph DIA = new Paragraph("Data: " + calendar.get(Calendar.DATE) + "/"
                + (calendar.get(Calendar.MONTH) + 1) + "/" + calendar.get(Calendar.YEAR));
        Paragraph HORA = new Paragraph("Hora: " + calendar.get(Calendar.HOUR_OF_DAY) + ":"
                + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND));
        DIA.setAlignment(Paragraph.ALIGN_RIGHT);
        HORA.setAlignment(Paragraph.ALIGN_RIGHT);
        Paragraph espaco = new Paragraph("\n");
        Paragraph aviso = new Paragraph("\nGraficos dos Testes ordenados:");
        aviso.setAlignment(Paragraph.ALIGN_CENTER);

        Paragraph autores = new Paragraph(
                "\n" + "Desenvolvedores: @AlexandeLUZ - @AndersonDIAS - @HigoBESSA - @JaimeDANTAS", fontDADO);
        autores.setAlignment(Paragraph.ALIGN_CENTER);

        Paragraph obs = new Paragraph("\n" + "Observaes: " + TelaPDF.observacoes.getText(), fontOBS);
        obs.setAlignment(Paragraph.ALIGN_CENTER);

        //PARTE DO CASCATA DO TANQUE 1

        Paragraph cascataTitulo = new Paragraph("Parmetros do Tanque 1 (Escravo):  ", fontTITULO2);
        cascataTitulo.setAlignment(Paragraph.ALIGN_CENTER);

        //PdfPTable pdfTableCascata = new PdfPTable(5);
        //                if(cascata){
        //                   
        //                   Paragraph KP = new Paragraph("\n" +
        //                    "Kp" ,fontTITULO);
        //                   pdfTableCascata.addCell(KP);
        //                   Paragraph KD = new Paragraph("\n" +
        //                    "Kd" ,fontTITULO);
        //                   pdfTableCascata.addCell(KD);
        //                   Paragraph KI = new Paragraph("\n" +
        //                    "Ki" ,fontTITULO);
        //                   pdfTableCascata.addCell(KI);
        //                   Paragraph TI = new Paragraph("\n" +
        //                    "Ti" ,fontTITULO);
        //                   pdfTableCascata.addCell(TI);
        //                   Paragraph TD = new Paragraph("\n" +
        //                    "Td" ,fontTITULO);
        //                   pdfTableCascata.addCell(TD);
        //                   Paragraph KP_VALOR = new Paragraph((this.kp_t1),fontDADO);
        //                   Paragraph KD_VALOR = new Paragraph((this.kd_t1),fontDADO);
        //                   Paragraph KI_VALOR = new Paragraph((this.ki_t1),fontDADO);
        //                   Paragraph TI_VALOR = new Paragraph((this.ti_t1),fontDADO);
        //                   Paragraph TD_VALOR = new Paragraph((this.td_t1),fontDADO);
        //                   pdfTableCascata.addCell(KP_VALOR);
        //                   pdfTableCascata.addCell(KD_VALOR);
        //                   pdfTableCascata.addCell(KI_VALOR);
        //                   pdfTableCascata.addCell(TI_VALOR);
        //                   pdfTableCascata.addCell(TD_VALOR);
        //
        //                }

        doc.add(Logotipo);
        doc.add(title);
        doc.add(pdfTable);
        doc.add(pdfTableAuxiliar);
        if (cascata) {
            doc.add(cascataTitulo);
            doc.add(espaco);
            doc.add(pdfTableCascata);
        }
        doc.add(obs);
        doc.add(aviso);
        //doc.add(espaco);
        doc.add(tabelaGrfico);
        doc.add(espaco);
        doc.add(espaco);
        doc.add(DIA);
        doc.add(HORA);
        doc.add(autores);

        doc.close();
        System.out.println("done");
        mostrarAviso("Arquivo criado com sucesso!");
        TelaPDF.setVisible(false);
    } catch (DocumentException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        mostrarErro("Erro ao gerar PDF!");
    } catch (FileNotFoundException ex) {
        Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        mostrarErro("Erro ao gerar PDF!");

    }

}

From source file:src.GUI.PDFGEN.java

License:Open Source License

public void PDFAB(String Headline, int AmountExer, GUISETTINGSPDF k) {
    Document Doc = new Document();
    Rectangle Rec = new Rectangle(PageSize.A4);
    Doc.setPageSize(Rec);/*  w w  w .  j a  v a 2  s  .c  o  m*/
    try {
        F = File.createTempFile("Blatt", ".pdf");
        PdfWriter.getInstance(Doc, new FileOutputStream(F));
        Doc.open();
        Paragraph Para = new Paragraph(Headline, FONTS.FontHeader());
        Para.setAlignment(Element.ALIGN_CENTER);
        Doc.add(Para);
        First = new MEMORY();
        Current = First;
        GUISETTINGSPDF D = k;
        //Image Img = Image.getInstance("Logo");
        //Doc.add(Img);
        for (int i = 1; i <= AmountExer; i++) {
            List = new List(List.ORDERED, List.ALPHABETICAL);
            for (int c = 0; c < k.taskNumber; c++) {
                TERM Term = new TERM(k.aoAddition, k.aoSubtraction, k.aoMultiplication, k.aoDivision,
                        k.bracketDepht, k.Substitutions, k.Digits, k.decimalPlaces, k.justPositive);
                Current.writeExercise(Term.infix() + "=");
                Current.writeSolution(Double.parseDouble(Term.getSolution()));
                List.add(new ListItem(Current.readExercise()));
                Current.Next = new MEMORY();
                Current = Current.Next;
            }
            Doc.add(new Paragraph(" \n Aufgabe " + i, FONTS.Font()));
            k = k.next;
            Doc.add(List);
        }
        Doc.close();
        Desktop.getDesktop().open(F);
        PDFLB(AmountExer, D);
        Desktop.getDesktop().open(G);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:src.GUI.PDFGEN.java

License:Open Source License

private void PDFLB(int AmountExer, GUISETTINGSPDF k) {
    Document Doc = new Document();
    Rectangle Rec = new Rectangle(PageSize.A4);
    Doc.setPageSize(Rec);// w w  w  .j  av  a  2 s.  com
    try {
        G = File.createTempFile("Blatt", ".pdf");
        PdfWriter.getInstance(Doc, new FileOutputStream(G));
        Doc.open();
        Paragraph Para = new Paragraph("Lsungsblatt", FONTS.FontHeader());
        Para.setAlignment(Element.ALIGN_CENTER);
        Doc.add(Para);
        for (int i = 1; i <= AmountExer; i++) {
            List = new List(List.ORDERED, List.ALPHABETICAL);
            for (int c = 0; c < k.taskNumber; c++) {
                String S = First.readExercise() + First.readSolution();
                List.add(new ListItem(S));
                First = First.Next;
            }
            Doc.add(new Paragraph(" \n Aufgabe" + i, FONTS.Font()));
            Doc.add(List);
            k = k.next;
        }
        Doc.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:storehausimport.SaveToPdf.java

public boolean save(String inputFilePath, String outputFilePath) throws Exception {
    if (outputFilePath.isEmpty()) {
        throw new Exception("Trkst parametrs outputFilePath");
    }//from   w  ww  .ja v  a  2 s .com
    if (inputFilePath.isEmpty()) {
        throw new Exception("Trkst parametrs inputFilePath");
    }
    File inputFile = new File(inputFilePath);
    Document pdfDoc = new Document();
    try {
        PdfWriter writer = PdfWriter.getInstance(pdfDoc, new FileOutputStream(outputFilePath));
        pdfDoc.open();
        pdfDoc.setMarginMirroring(true);
        pdfDoc.setMargins(36, 72, 108, 180);
        pdfDoc.topMargin();

        BaseFont helvetica = BaseFont.createFont("Helvetica", BaseFont.CP1257, BaseFont.NOT_EMBEDDED);
        Font normal_font = new Font(helvetica, 10, Font.NORMAL);
        Font bold_font = new Font();
        bold_font.setStyle(Font.BOLD);
        bold_font.setSize(10);
        pdfDoc.add(new Paragraph("\n"));
        if (inputFile.exists()) {
            iStream = new FileInputStream(inputFile);
            in = new DataInputStream(iStream);
            is = new InputStreamReader(in);
            br = new BufferedReader(is);
            String strLine;
            while ((strLine = br.readLine()) != null) {
                Paragraph para = new Paragraph(strLine + "\n", normal_font);
                para.setAlignment(Element.ALIGN_LEFT);
                pdfDoc.add(para);
            }
        } else {
            pdfDoc.close();
            throw new Exception("Trkst parametrs inputFilePath");
        }
        pdfDoc.close();
    } catch (Exception ex) {
        throw new Exception(ex);
    }
    return true;
}

From source file:superlaskuttaja.logiikka.PdfExtractor.java

private void muodostaDokumentti(Document document, String laskunNumero, PdfWriter writer)
        throws DocumentException, SQLException, ParseException {
    document.open();/*ww w  .ja  v a  2 s  .  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:Tables.Printer.java

public void header(Document doc, String reportType) throws DocumentException {
    String companyInfo = "NJEIFORBI ACCOUNTS BOOK \nFINANCIAL REPORTS";

    Paragraph newLine = new Paragraph("\n");
    doc.add(newLine);/*from   www . j  a va  2s.c  om*/

    // add the paragraph to the document            

    /*new heading*/
    //adding the company logo.
    try {
        Image img = Image.getInstance(this.companyLogo);
        img.scaleAbsolute(80f, 80f);
        img.setAlt("Unity Systems");
        img.setAlignment(Element.ALIGN_CENTER);

        //            Image img = Image.getInstance(this.companyLogo);

        /*with the next 3 lines oc code, the image will align at the center of the page.*/
        //            img.setAbsolutePosition(
        //                (PageSize.A4.getWidth() - img.getScaledWidth()) / 2,
        //                (PageSize.A4.getHeight() - img.getScaledHeight()) / 2);

        doc.add(img);
    } catch (IOException | DocumentException ex) {
        Dialogs.create().title("Logo Not found").message(
                "The Company's logo has not been located. So the printout will be without the logo of the company")
                .showError();
        ex.printStackTrace();
    }

    Paragraph companyName = new Paragraph(companyInfo, this.companyNameFont);
    Paragraph reportTitle = new Paragraph(reportType, this.reportTitleFont);

    companyName.setAlignment(Element.ALIGN_CENTER);
    reportTitle.setAlignment(Element.ALIGN_CENTER);
    newLine.setAlignment(Element.ALIGN_CENTER);

    doc.add(companyName);
    doc.add(reportTitle);
    doc.add(newLine);

    /*new heading ends*/

}

From source file:Tables.PrinterClass.java

/***************HEADINGS HEADINGS HEADINGS */

private void makeCompanyHeading(Document doc) throws DocumentException, BadElementException, IOException {

    //adding the company logo.
    try {//from   www .jav  a 2  s.c  o m
        Image img = Image.getInstance(this.companyLogo);
        img.scaleAbsolute(80f, 80f);
        img.setAlt("Unity Systems");
        img.setAlignment(Element.ALIGN_CENTER);

        //            Image img = Image.getInstance(this.companyLogo);

        /*with the next 3 lines oc code, the image will align at the center of the page.*/
        //            img.setAbsolutePosition(
        //                (PageSize.A4.getWidth() - img.getScaledWidth()) / 2,
        //                (PageSize.A4.getHeight() - img.getScaledHeight()) / 2);

        doc.add(img);
    } catch (IOException | DocumentException ex) {
        Dialogs.create().title("Logo Not found").message(
                "The Company's logo has not been located. So the printout will be without the logo of the company")
                .showError();
        ex.printStackTrace();
    }

    Paragraph companyName = new Paragraph(this.companyName, this.companyNameFont);
    Paragraph newLine = new Paragraph("\n");
    Paragraph companyLocation = new Paragraph(
            this.companyLocation + "\n" + this.companyPoBox + "\n " + this.companyTel, this.companySubInfoFont);

    companyName.setAlignment(Element.ALIGN_CENTER);
    companyLocation.setAlignment(Element.ALIGN_CENTER);
    newLine.setAlignment(Element.ALIGN_CENTER);

    doc.add(companyName);
    doc.add(companyLocation);
    doc.add(newLine);

}

From source file:ui.MainDriver.java

public void printTicket() {

    for (int t = 0; t < currentTicketList.size(); t++) {
        String myCodeText = currentTicketList.get(t).getTicketID() + " %0A "
                + currentTicketList.get(t).getBooking().getBookingID() + " - "
                + currentTicketList.get(t).getSchedule().getRoute().getDestination() + " - "
                + currentTicketList.get(t).getPassengerName() + " - "
                + currentTicketList.get(t).getPassengerContactNo() + " - "
                + currentTicketList.get(t).getSeatNo();
        String filePath = "src/ticket/" + currentTicketList.get(t).getTicketID() + ".png";
        int size = 165;
        String fileType = "png";
        File myFile = new File(filePath);
        try {/*from www .  ja va  2  s  .c  o  m*/
            Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<>();
            hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
            QRCodeWriter qrCodeWriter = new QRCodeWriter();
            BitMatrix byteMatrix = qrCodeWriter.encode(myCodeText, BarcodeFormat.QR_CODE, size, size, hintMap);
            int width = byteMatrix.getWidth();
            BufferedImage image = new BufferedImage(width, width, BufferedImage.TYPE_INT_RGB);
            image.createGraphics();

            Graphics2D graphics = (Graphics2D) image.getGraphics();
            graphics.setColor(Color.WHITE);
            graphics.fillRect(0, 0, width, width);
            graphics.setColor(Color.BLACK);

            for (int i = 0; i < width; i++)
                for (int j = 0; j < width; j++)
                    if (byteMatrix.get(i, j))
                        graphics.fillRect(i, j, 1, 1);

            ImageIO.write(image, fileType, myFile);
        } catch (WriterException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        Document document = new Document();
        try {
            PdfWriter.getInstance(document,
                    new FileOutputStream("src/ticketpdf/" + currentTicketList.get(t).getTicketID() + "DATE"
                            + new SimpleDateFormat("ddMMyyHHmmss").format(new Date()) + ".pdf"));
            document.open();

            Phrase p1 = new Phrase();
            Paragraph para = new Paragraph();
            com.itextpdf.text.Font font = new com.itextpdf.text.Font(com.itextpdf.text.Font.FontFamily.COURIER,
                    32, com.itextpdf.text.Font.BOLDITALIC);
            com.itextpdf.text.Font timesRomanfont = new com.itextpdf.text.Font(
                    com.itextpdf.text.Font.FontFamily.TIMES_ROMAN, 16, com.itextpdf.text.Font.BOLD);
            Chunk cc = new Chunk("#################################################################",
                    timesRomanfont);
            p1.add(cc);
            p1.add(Chunk.NEWLINE);
            p1.add(Chunk.NEWLINE);
            Chunk c = new Chunk("CJH BUS EXPRESS SDN. BHD.", font);
            p1.add(c);
            p1.add(Chunk.NEWLINE);
            p1.add(Chunk.NEWLINE);
            p1.add(cc);
            para.setAlignment(Element.ALIGN_CENTER);
            para.add(p1);
            document.add(para);

            Image image1 = Image.getInstance(filePath);
            document.add(image1);

            Phrase phrase = new Phrase();
            Paragraph paragraph = new Paragraph();

            Chunk c1 = new Chunk("Ticket ID                       : " + currentTicketList.get(t).getTicketID(),
                    timesRomanfont);
            phrase.add(c1);
            phrase.add(Chunk.NEWLINE);

            Chunk c2 = new Chunk(
                    "Booking ID                    : " + currentTicketList.get(t).getBooking().getBookingID(),
                    timesRomanfont);
            phrase.add(c2);
            phrase.add(Chunk.NEWLINE);

            Chunk c3 = new Chunk(
                    "Destination                    : "
                            + currentTicketList.get(t).getSchedule().getRoute().getDestination(),
                    timesRomanfont);
            phrase.add(c3);
            phrase.add(Chunk.NEWLINE);

            Chunk cDate = new Chunk(
                    "Departure Date             : " + currentTicketList.get(t).getSchedule().getDepartureDate(),
                    timesRomanfont);
            phrase.add(cDate);
            phrase.add(Chunk.NEWLINE);

            Chunk cTime = new Chunk(
                    "Departure Time            : " + currentTicketList.get(t).getSchedule().getDepartureTime(),
                    timesRomanfont);
            phrase.add(cTime);
            phrase.add(Chunk.NEWLINE);

            Chunk c4 = new Chunk("Passenger Name            : " + currentTicketList.get(t).getPassengerName(),
                    timesRomanfont);
            phrase.add(c4);
            phrase.add(Chunk.NEWLINE);

            Chunk c5 = new Chunk("Passenger Contact No   : " + currentTicketList.get(t).getPassengerContactNo(),
                    timesRomanfont);
            phrase.add(c5);
            phrase.add(Chunk.NEWLINE);

            Chunk c6 = new Chunk("Seat No                           : " + currentTicketList.get(t).getSeatNo(),
                    timesRomanfont);
            phrase.add(c6);
            phrase.add(Chunk.NEWLINE);

            if (reprintCounter == true) {
                Chunk cR = new Chunk("--- REPRINT ---", timesRomanfont);
                phrase.add(cR);
                phrase.add(Chunk.NEWLINE);
            }

            Chunk c7 = new Chunk("#################################################################",
                    timesRomanfont);
            phrase.add(c7);

            paragraph.add(phrase);
            document.add(paragraph);

            document.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

        //            try {
        //                PdfReader reader = new PdfReader("src/ticketpdf/" + currentTicketList.get(t).getTicketID() + "DATE" + new SimpleDateFormat("ddMMyyHHmmss").format(new Date()) + ".pdf");
        //                int n = reader.getNumberOfPages();
        //                PdfStamper stamp = new PdfStamper(reader, new FileOutputStream("src/ticketpdfWM/" + currentTicketList.get(t).getTicketID() + "WMDATE" + new SimpleDateFormat("ddMMyyHHmmss").format(new Date()) + ".pdf"));
        //                int i = 0;
        //                PdfContentByte under;
        //                Image img = Image.getInstance("src/images/b1.jpg");
        //                img.setAbsolutePosition(200, 400);
        //                while (i < n) {
        //                  i++;
        //                  under = stamp.getUnderContent(i);
        //                  under.addImage(img);
        //                }
        //                stamp.close();
        //            }
        //            catch (Exception de) {
        //                de.printStackTrace();
        //            }
    }
}