Example usage for com.itextpdf.text.pdf PdfPCell setPadding

List of usage examples for com.itextpdf.text.pdf PdfPCell setPadding

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf PdfPCell setPadding.

Prototype

public void setPadding(float padding) 

Source Link

Document

Sets the padding of the contents in the cell (space between content and border).

Usage

From source file:Export.GrossSarary.java

public static void criaDoc(String user) {
    OutputStream outputStraem;//from   w  w  w.  ja va2  s  . c o m
    try {
        Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                10f);
        Font fontCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoBP = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                9.5f);
        Font fontCorpoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                13f);
        Font fontCorpoTitile = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                11f);
        Font fontCabecalhoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                16f, Font.UNDERLINE);

        SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss");
        File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Relatorio");
        ff.mkdirs();
        String Ddata = sdf1.format(new Date());
        ff = new File(ff.getAbsoluteFile() + "/" + "Gross Salary " + Ddata + ".pdf");
        outputStraem = new FileOutputStream(ff);

        String reString = "../Documentos/" + user + "/Relatorio/Gross Salary " + Ddata + ".pdf";

        PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 15f, 85f });
        PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1);
        PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1);

        PdfPTable pTableNull = new PdfPTable(1);
        PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontCorpo));
        cellNull.setBorder(0);
        pTableNull.addCell(cellNull);

        PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontCabecalhoNG));
        pCellNomeEmpresa.setBorder(0);

        PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO, fontCabecalhoN));
        pCellNomeEndereco.setBorder(0);

        PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAIXAPOSTAL, fontCabecalhoN));
        pCellCaixaPostal.setBorder(0);

        PdfPCell pCellTeleFax = new PdfPCell(
                new Phrase(ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN));
        pCellTeleFax.setBorder(0);

        PdfPCell pCellSociedade = new PdfPCell(new Phrase(ConfigDoc.Empresa.SOCIEDADE, fontCabecalhoN));
        pCellSociedade.setBorder(0);

        Image imageEmpresa = Image.getInstance("logo.png");
        imageEmpresa.scaleToFit(120f, 85f);

        pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa);
        pTableEmpresaInforImpres1.addCell(pCellNomeEndereco);
        pTableEmpresaInforImpres1.addCell(pCellCaixaPostal);
        pTableEmpresaInforImpres1.addCell(pCellTeleFax);
        pTableEmpresaInforImpres1.addCell(pCellSociedade);

        PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1);
        cellTabela3.setBorder(0);

        pTableEmpresaInforImpres5.addCell(cellTabela3);

        PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5);
        cellTabela5.setBorder(0);

        PdfPCell cellTabela6 = new PdfPCell(imageEmpresa);
        cellTabela6.setBorder(0);
        pTableEmpresaPricipal.setWidthPercentage(97);
        pTableEmpresaPricipal.addCell(cellTabela6);
        pTableEmpresaPricipal.addCell(cellTabela5);

        Document documento = new Document(PageSize.A4.rotate());
        PdfWriter writer = PdfWriter.getInstance(documento, outputStraem);

        //Table Principal
        PdfPTable pTableTitile = new PdfPTable(new float[] { 100 });
        PdfPTable pTableTablePrincipal = new PdfPTable(
                new float[] { 16.875f, 11.875f, 11.875f, 11.875f, 11.875f, 11.875f, 11.875f, 11.875f });
        pTableTablePrincipal.setWidthPercentage(100f);

        PdfPCell pCellTable = new PdfPCell(new Phrase("Categoria".toUpperCase(), fontCorpoTitile));
        pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableTablePrincipal.addCell(pCellTable);

        //Table principal
        PdfPTable tableCell;
        for (int i = 1; i <= 7; i++) {
            tableCell = new PdfPTable(new float[] { 100 });

            pCellTable = new PdfPCell(new Phrase("NIVEL", fontCorpoTitile));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            tableCell.addCell(pCellTable);

            pCellTable = new PdfPCell(new Phrase(i + "", fontCorpoTitile));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            tableCell.addCell(pCellTable);

            pTableTablePrincipal.addCell(tableCell);
        }

        de = getList();

        for (DadosEstrutura de1 : de) {
            pCellTable = new PdfPCell(new Phrase(de1.categoria, fontCorpoN));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            pTableTablePrincipal.addCell(pCellTable);

            pCellTable = new PdfPCell(new Phrase(de1.set1, fontCorpo));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableTablePrincipal.addCell(pCellTable);

            pCellTable = new PdfPCell(new Phrase(de1.set2, fontCorpo));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableTablePrincipal.addCell(pCellTable);

            pCellTable = new PdfPCell(new Phrase(de1.set3, fontCorpo));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableTablePrincipal.addCell(pCellTable);

            pCellTable = new PdfPCell(new Phrase(de1.set4, fontCorpo));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableTablePrincipal.addCell(pCellTable);

            pCellTable = new PdfPCell(new Phrase(de1.set5, fontCorpo));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableTablePrincipal.addCell(pCellTable);

            pCellTable = new PdfPCell(new Phrase(de1.set6, fontCorpo));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableTablePrincipal.addCell(pCellTable);

            pCellTable = new PdfPCell(new Phrase(de1.set7, fontCorpo));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableTablePrincipal.addCell(pCellTable);
        }

        //Titulo de Table
        pCellTable = new PdfPCell(new Phrase("Estrutura de salrio Grosso".toUpperCase(), fontCorpoNG));
        pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pCellTable.setBorder(PdfPCell.NO_BORDER);
        pCellTable.setPadding(15f);
        pTableTitile.addCell(pCellTable);

        pCellTable = new PdfPCell(new Phrase("Mensal".toUpperCase(), fontCorpoNG));
        pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pCellTable.setBorder(PdfPCell.NO_BORDER);
        pTableTitile.addCell(pCellTable);

        @SuppressWarnings("UnusedAssignment")
        PdfPTable pTableInf = null;
        PdfPTable pTableInfTile = new PdfPTable(new float[] { 6, 18.5f, 18.5f, 18.5f, 18f, 20f });
        PdfPTable pTableInfReal = new PdfPTable(new float[] { 100f });
        pTableInfTile.setWidthPercentage(95f);
        pTableInfReal.setWidthPercentage(95f);

        pTableInfTile.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        pTableInfReal.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);

        pCellTable = new PdfPCell(new Phrase("NIVEL", fontCorpoN));
        pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableInfTile.addCell(pCellTable);

        pCellTable = new PdfPCell(new Phrase("SAL?RIO BASE", fontCorpoN));
        pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableInfTile.addCell(pCellTable);

        pCellTable = new PdfPCell(new Phrase("SUBSIDIO ALMOO", fontCorpoN));
        pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableInfTile.addCell(pCellTable);

        pCellTable = new PdfPCell(new Phrase("SUBSIDIO ALOGAMENTO", fontCorpoN));
        pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableInfTile.addCell(pCellTable);

        pCellTable = new PdfPCell(new Phrase("SUBSIDIO TRANSPORTE", fontCorpoN));
        pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableInfTile.addCell(pCellTable);

        pCellTable = new PdfPCell(new Phrase("TOTAL", fontCorpoN));
        pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableInfTile.addCell(pCellTable);

        HashMap<String, ArrayList<Categoria>> outherAr = GrossSarary.getCatList();
        int si = outherAr.size(), i = 0;
        for (Map.Entry<String, ArrayList<Categoria>> eSet : outherAr.entrySet()) {

            pTableInf = new PdfPTable(new float[] { 6, 18.5f, 18.5f, 18.5f, 18f, 20f });
            pTableInf.setWidthPercentage(95f);
            pTableInf.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);

            pCellTable = new PdfPCell(new Phrase(eSet.getKey(), fontCorpoNG));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            pCellTable.setBorder(PdfPCell.NO_BORDER);
            pCellTable.setColspan(6);
            pTableInf.addCell(pCellTable);

            pCellTable = new PdfPCell(new Phrase(" ", fontCorpoN));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            pCellTable.setColspan(6);
            pCellTable.setBorder(PdfPCell.NO_BORDER);
            pTableInf.addCell(pCellTable);

            pCellTable = new PdfPCell(pTableInfTile);
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            pCellTable.setColspan(6);
            pCellTable.setBorder(PdfPCell.NO_BORDER);
            pTableInf.addCell(pCellTable);

            for (Categoria ca : eSet.getValue()) {
                pCellTable = new PdfPCell(new Phrase(ca.nivel, fontCorpo));
                pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
                pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                pTableInf.addCell(pCellTable);

                pCellTable = new PdfPCell(new Phrase(toConverterToMoeda(ca.salarioBase), fontCorpo));
                pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                pCellTable.setPaddingRight(10f);
                pTableInf.addCell(pCellTable);

                pCellTable = new PdfPCell(new Phrase(toConverterToMoeda(ca.subsidioAlmoco), fontCorpo));
                pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                pCellTable.setPaddingRight(10f);
                pTableInf.addCell(pCellTable);

                pCellTable = new PdfPCell(new Phrase(toConverterToMoeda(ca.subsidioAlogamento), fontCorpo));
                pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                pCellTable.setPaddingRight(10f);
                pTableInf.addCell(pCellTable);

                pCellTable = new PdfPCell(new Phrase(toConverterToMoeda(ca.subsidioTransporte), fontCorpo));
                pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                pCellTable.setPaddingRight(10f);
                pTableInf.addCell(pCellTable);

                pCellTable = new PdfPCell(new Phrase(toConverterToMoeda(ca.total), fontCorpo));
                pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                pCellTable.setPaddingRight(10f);
                pTableInf.addCell(pCellTable);
            }

            pCellTable = new PdfPCell(new Phrase(" ", fontCorpoN));
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            pCellTable.setBorder(PdfPCell.NO_BORDER);
            pCellTable.setColspan(6);

            i++;
            if (si == i) {
                pTableInf.addCell(pCellTable);
                pTableInf.addCell(pCellTable);
                pTableInf.addCell(pCellTable);
            }

            pCellTable = new PdfPCell(pTableInf);
            pCellTable.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            pCellTable.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            pCellTable.setBorder(PdfPCell.NO_BORDER);
            pTableInfReal.addCell(pCellTable);

        }

        documento.open();
        documento.add(pTableEmpresaPricipal);
        documento.add(pTableNull);
        documento.add(pTableTitile);
        documento.add(pTableNull);
        documento.add(pTableTablePrincipal);
        //                documento.add(pTableNull);
        documento.newPage();
        documento.add(pTableInfReal);
        documento.close();

        RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')");

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

From source file:Export.TableOfSalary.java

public static void ciarDoc(String user, String idProcesso, String data) {
    FileOutputStream outputStraem;
    try {// w  w w .  j a  v  a  2s. co m
        Font fontCabecalhoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                9f);
        Font fontCorpo = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f);
        Font fontCorpoN = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 7f);
        Font fontCabecalhoNG = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED,
                16f, Font.UNDERLINE);

        SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss");
        File ff = new File(ConfigDoc.Fontes.getDiretorio() + "/" + user + "/Relatorio");
        ff.mkdirs();
        String Ddata = sdf1.format(new Date());
        ff = new File(ff.getAbsoluteFile() + "/" + "Tabela de Salrio " + Ddata + ".pdf");
        outputStraem = new FileOutputStream(ff);
        String reString = "../Documentos/" + user + "/Relatorio/Tabela de Salrio " + Ddata + ".pdf";

        PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 7f, 93f });
        PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1);
        PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1);
        PdfPTable pTableNull = new PdfPTable(1);

        PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontCorpo));
        cellNull.setBorder(0);
        pTableNull.addCell(cellNull);
        PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontCabecalhoNG));
        pCellNomeEmpresa.setBorder(0);
        PdfPCell pCellNomeEndereco = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO, fontCabecalhoN));
        pCellNomeEndereco.setBorder(0);
        PdfPCell pCellCaixaPostal = new PdfPCell(new Phrase(ConfigDoc.Empresa.CAIXAPOSTAL, fontCabecalhoN));
        pCellCaixaPostal.setBorder(0);
        PdfPCell pCellTeleFax = new PdfPCell(
                new Phrase(ConfigDoc.Empresa.TELEFAX + " " + ConfigDoc.Empresa.EMAIL, fontCabecalhoN));
        pCellTeleFax.setBorder(0);
        PdfPCell pCellSociedade = new PdfPCell(new Phrase(ConfigDoc.Empresa.SOCIEDADE, fontCabecalhoN));
        pCellSociedade.setBorder(0);

        Image imageEmpresa = Image.getInstance("logo.png");
        imageEmpresa.scaleToFit(120f, 85f);

        pTableEmpresaInforImpres1.addCell(pCellNomeEmpresa);
        pTableEmpresaInforImpres1.addCell(pCellNomeEndereco);
        pTableEmpresaInforImpres1.addCell(pCellCaixaPostal);
        pTableEmpresaInforImpres1.addCell(pCellTeleFax);
        pTableEmpresaInforImpres1.addCell(pCellSociedade);

        PdfPCell cellTabela3 = new PdfPCell(pTableEmpresaInforImpres1);
        cellTabela3.setBorder(0);
        pTableEmpresaInforImpres5.addCell(cellTabela3);
        PdfPCell cellTabela5 = new PdfPCell(pTableEmpresaInforImpres5);
        cellTabela5.setBorder(0);
        PdfPCell cellTabela6 = new PdfPCell(imageEmpresa);
        cellTabela6.setBorder(0);

        pTableEmpresaPricipal.setWidthPercentage(97);
        pTableEmpresaPricipal.addCell(cellTabela6);
        pTableEmpresaPricipal.addCell(cellTabela5);
        Document documento = new Document(PageSize.A3.rotate());

        PdfWriter writer = PdfWriter.getInstance(documento, outputStraem);

        PdfPTable pTableDados = new PdfPTable(new float[] { 2.5f, 7.5f, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
                4, 4, 4, 4, 4, 4, 4, 4, 4, 4 });
        pTableDados.setWidthPercentage(105);

        /**
         * primeira linha de titulo inicio
         */
        PdfPCell cellDados;
        Paragraph pTitile = new Paragraph();

        //            SimpleDateFormat sdfPT = new SimpleDateFormat("MMMM yyyy",new Locale("pt", "BR"));
        pTitile.add(new Paragraph(ConfigDoc.Empresa.NOME + "\n" + "TABELA SAL?RIO REFERENTE A " + data,
                fontCorpoN));

        cellDados = new PdfPCell(pTitile);
        cellDados.setColspan(10);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("F\nSOC. SEGU. 4%", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("G", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("H", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("I", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("IMPOSTO\n18% : 20%", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        for (int j = 0; j < 8; j++) {
            cellDados = new PdfPCell(new Phrase(" ", fontCorpo));
            pTableDados.addCell(cellDados);
        }

        cellDados = new PdfPCell(new Phrase("6\nSOC. SEGU.", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase(" ", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableDados.addCell(cellDados);
        /**
         * primeira linha de titulo Fim
         */

        /**
         * Segunda linha de titulo Inicio
         */
        for (int j = 0; j < 3; j++) {
            cellDados = new PdfPCell(new Phrase(" ", fontCorpo));
            pTableDados.addCell(cellDados);
        }

        cellDados = new PdfPCell(new Phrase("A", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("B", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("C", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("D", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("E", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("SUBSIDIO DE", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("VALOR A SER", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("F=(E*4%)", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("G=(E-F)", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase(" ", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("I=G+", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("J=", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableDados.addCell(cellDados);

        for (int j = 0; j < 4; j++) {
            cellDados = new PdfPCell(new Phrase(" ", fontCorpo));
            pTableDados.addCell(cellDados);
        }

        cellDados = new PdfPCell(new Phrase("SUBSIDIO DE", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("k=E-(F+G)", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("PYT", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase(" ", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("I", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableDados.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("J", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableDados.addCell(cellDados);

        /**
         * Segunda linha de titulo Fim
         */
        /**
         * Terceira linha de titulo Inicio
         */
        for (int i = 0; i < 25; i++) {
            cellDados = new PdfPCell(new Phrase(getTitile(i), fontCorpoN));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cellDados.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            pTableDados.addCell(cellDados);
        }
        /**
         * Terceira linha de titulo FIM
         */
        ArrayList<Processo> ps = getListData(idProcesso);

        for (Processo p : ps) {
            cellDados = new PdfPCell(new Phrase(p.CODIGO1, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.NOME2, fontCorpo));
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.DIAS3, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.S_BASE4, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.S_ALOJAMENTO5, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.S_TRANSPORTE6, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.S_ALMOCO7, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.TT_SEM8, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.ALMOCOLIVREIMPOSTO9, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.TRIBUTADO10, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.SSFUNCIONARIO11, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.MENOS_SS_FUNCIONARIO12, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.COMISOES13, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.TOTAL_E_COMISAO14, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.IRS15, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.PARCELABATER16, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.IRSAPURADO17, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.SITUAFAMILIAR18, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.IRSLIQUIDO19, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.ALMOCO20, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.SALARIOLIQUIDO21, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.AVANCO22, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.NETOUT23, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.SSEMPRESA24, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(p.TOTAL25, fontCorpo));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableDados.addCell(cellDados);
        }

        PdfPTable pTableRodape = new PdfPTable(new float[] { 33.333333333f, 33.333333333f, 33.333333333f });
        PdfPTable pTableSegurancaSocial = new PdfPTable(
                new float[] { 35f, 21.666666667f, 21.666666667f, 21.666666667f });
        pTableSegurancaSocial.setWidthPercentage(75f);

        PdfPTable pTableImpostoSalario = new PdfPTable(new float[] { 25f, 25f, 25f, 25f });
        pTableImpostoSalario.setWidthPercentage(75f);

        PdfPTable pTableNetSalaryPayble = new PdfPTable(new float[] { 70f, 30f });
        pTableNetSalaryPayble.setWidthPercentage(75f);

        PdfPTable pTableAssinatura = new PdfPTable(new float[] { 25f, 25f, 25f, 25f });

        /**
         * segurano social inicio
         */
        cellDados = new PdfPCell(new Phrase("SEGURANA SOCIAL", fontCorpoN));
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setPaddingTop(8.5f);
        pTableRodape.addCell(cellDados);
        /**
         * segurano social Fim
         */

        /**
         * IMPOSTO DE SAL?RIO inicio
         */
        cellDados = new PdfPCell(new Phrase("IMPOSTO DE SAL?RIO", fontCorpoN));
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setPaddingTop(8.5f);
        pTableRodape.addCell(cellDados);
        /**
         * IMPOSTO DE SAL?RIO Fim
         */

        /**
         * NET SALARY PAYABLE incial
         */
        cellDados = new PdfPCell(new Phrase("NET SALARY PAYABLE", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setPaddingTop(8.5f);
        pTableRodape.addCell(cellDados);
        /**
         * NET SALARY PAYABLE Fim
         */

        /**
         * segurano social inicio
         */
        cellDados = new PdfPCell(new Phrase(" ", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setBorder(PdfPCell.NO_BORDER);
        pTableSegurancaSocial.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("4%", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableSegurancaSocial.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("6%", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableSegurancaSocial.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("TOTAL", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableSegurancaSocial.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("TOTAL", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableSegurancaSocial.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase(
                Moeda.format(Double.valueOf(psList.get(0).SSFUNCIONARIO11.replace(',', '.'))), fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        pTableSegurancaSocial.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase(
                Moeda.format(Double.valueOf(psList.get(0).SSEMPRESA24.replace(',', '.'))), fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableSegurancaSocial.addCell(cellDados);

        cellDados = new PdfPCell(
                new Phrase(Moeda.format((Double.valueOf(psList.get(0).SSFUNCIONARIO11.replace(',', '.'))
                        + Double.valueOf(psList.get(0).SSEMPRESA24.replace(',', '.')))), fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableSegurancaSocial.addCell(cellDados);
        pTableSegurancaSocial.setComplete(true);

        cellDados = new PdfPCell(pTableSegurancaSocial);
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setPadding(8.5f);
        //            cellDados.setCalculatedHeight(100);
        pTableRodape.addCell(cellDados);
        /**
         * segurano social Fim
         */

        /**
         * IMPOSTO DE SAL?RIO inicio
         */
        cellDados = new PdfPCell(new Phrase("TOTAL", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableImpostoSalario.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase(" ", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableImpostoSalario.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase(" ", fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableImpostoSalario.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase(
                Moeda.format(Double.valueOf(psList.get(0).IRSLIQUIDO19.replace(',', '.'))), fontCorpoN));
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        pTableImpostoSalario.addCell(cellDados);
        pTableImpostoSalario.setComplete(true);

        cellDados = new PdfPCell(pTableImpostoSalario);
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cellDados.setCalculatedHeight(100);
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setPadding(8.5f);
        pTableRodape.addCell(cellDados);
        /**
         * IMPOSTO DE SAL?RIO Fim
         */

        /**
         * NET SALARY PAYABLE incial
         */
        for (Map.Entry<String, TotalBank> entrySet : tbs.entrySet()) {

            cellDados = new PdfPCell(
                    new Phrase(((entrySet.getValue().nome.isEmpty()) ? "INDEFINIDO" : entrySet.getValue().nome),
                            fontCorpoN));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
            pTableNetSalaryPayble.addCell(cellDados);

            cellDados = new PdfPCell(new Phrase(Moeda.format(entrySet.getValue().value), fontCorpoN));
            cellDados.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            pTableNetSalaryPayble.addCell(cellDados);

        }

        cellDados = new PdfPCell(pTableNetSalaryPayble);
        cellDados.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        //            cellDados.setCalculatedHeight(100);
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setPadding(8.5f);
        pTableRodape.addCell(cellDados);
        /**
         * NET SALARY PAYABLE Fim
         */

        /**
         * Asssinatura inicio
         */
        cellDados = new PdfPCell(new Phrase("VISTO\nRESPONS?VEL CONTABILIDADE", fontCorpoN));
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        cellDados.setPaddingBottom(20.f);
        pTableAssinatura.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("VISTO\nDIRETOR ADMINISTRATIVO & FINANCEIRO", fontCorpoN));
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        cellDados.setPaddingBottom(20.f);
        pTableAssinatura.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("VISTO\nDIRETOR GERAL", fontCorpoN));
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        cellDados.setPaddingBottom(20.f);
        pTableAssinatura.addCell(cellDados);

        cellDados = new PdfPCell(new Phrase("VISTO\nAUDITOR INTERNO", fontCorpoN));
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        cellDados.setPaddingBottom(20.f);
        pTableAssinatura.addCell(cellDados);

        cellDados = new PdfPCell(
                new Phrase("______________________________________________________", fontCorpoN));
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        cellDados.setPaddingBottom(5.f);
        pTableAssinatura.addCell(cellDados);

        cellDados = new PdfPCell(
                new Phrase("______________________________________________________", fontCorpoN));
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        pTableAssinatura.addCell(cellDados);

        cellDados = new PdfPCell(
                new Phrase("______________________________________________________", fontCorpoN));
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        pTableAssinatura.addCell(cellDados);

        cellDados = new PdfPCell(
                new Phrase("______________________________________________________", fontCorpoN));
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        pTableAssinatura.addCell(cellDados);

        cellDados = new PdfPCell(pTableAssinatura);
        cellDados.setBorder(PdfPCell.NO_BORDER);
        cellDados.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
        cellDados.setColspan(3);
        pTableRodape.addCell(cellDados);
        /**
         * Asssinatura fim
         */

        cellDados = new PdfPCell(pTableRodape);
        cellDados.setColspan(25);
        pTableDados.addCell(cellDados);

        documento.open();
        documento.add(pTableEmpresaPricipal);
        documento.add(pTableDados);
        documento.close();

        psList = new ArrayList<>();
        tbs = new LinkedHashMap<>();

        RequestContext.getCurrentInstance().execute("openAllDocument('" + reString + "')");

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

From source file:file.PDFWriter.java

License:Open Source License

/**
 * Add the page number and line to the PDF
 * @param splitLines the array of line segments to print
 * @param page the page number the line was on
 * @throws DocumentException //from   w  ww .  ja v  a2 s .  c  o  m
 */
private void addLineTableToPDF(String[] splitLines, String page) throws DocumentException {
    PdfPTable lineTable = new PdfPTable(2);
    PdfPCell pageCell = new PdfPCell(new Paragraph("Page: " + page, lineFont));
    pageCell.setPadding(20);
    pageCell.setPaddingLeft(0);
    pageCell.setBorder(PdfPCell.NO_BORDER);
    Chunk lineSegment1 = new Chunk(splitLines[0]);
    lineSegment1.setFont(lineFont);
    Chunk error1 = new Chunk(splitLines[1]);
    error1.setFont(lineFontBold);
    Chunk lineSegment2 = new Chunk(splitLines[2]);
    lineSegment2.setFont(lineFont);
    Chunk error2 = new Chunk(splitLines[3]);
    error2.setFont(lineFontBold);
    Chunk lineSegment3 = new Chunk(splitLines[4]);
    lineSegment3.setFont(lineFont);

    Phrase line = new Phrase(lineSegment1);
    line.add(error1);
    line.add(lineSegment2);
    line.add(error2);
    line.add(lineSegment3);

    PdfPCell lineCell = new PdfPCell(line);
    lineCell.setPadding(20);
    lineCell.setBorder(PdfPCell.NO_BORDER);
    lineTable.setWidthPercentage(100);
    lineTable.setWidths(new int[] { 2, 10 });
    lineTable.setSpacingBefore(1f);
    lineTable.setSpacingAfter(1f);

    lineTable.addCell(pageCell);
    lineTable.addCell(lineCell);
    document.add(lineTable);
    document.add(Chunk.NEWLINE);
}

From source file:file.PDFWriter.java

License:Open Source License

/**
 * Make the initial header to the PDF, with the date and character
 * @throws DocumentException/*from  w ww .  j a  v  a2 s.  c o  m*/
 */
public void makePDFHeader() throws DocumentException {
    PdfPTable headerTable = new PdfPTable(2);
    headerTable.setWidthPercentage(100);

    PdfPCell dateCell = new PdfPCell(new Paragraph(
            "Date: " + date.monthOfYear().getAsString() + "/" + date.dayOfMonth().getAsString(), lineFont));
    dateCell.setHorizontalAlignment(Element.ALIGN_LEFT);
    dateCell.setBorder(PdfPCell.NO_BORDER);
    dateCell.setPadding(0.3f);
    PdfPCell characterCell = new PdfPCell(new Paragraph("Character: " + role.getName(), lineFont));
    characterCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    characterCell.setBorder(PdfPCell.NO_BORDER);

    headerTable.addCell(dateCell);
    headerTable.addCell(characterCell);
    document.add(headerTable);
    document.add(Chunk.NEWLINE);
    document.add(Chunk.NEWLINE);
}

From source file:fll.web.playoff.ScoresheetGenerator.java

License:Open Source License

public void writeFile(final OutputStream out, final boolean orientationIsPortrait) throws DocumentException {

    // This creates our new PDF document and declares its orientation
    Document pdfDoc;//from   www . j a v a  2 s  .co  m
    if (orientationIsPortrait) {
        pdfDoc = new Document(PageSize.LETTER); // portrait
    } else {
        pdfDoc = new Document(PageSize.LETTER.rotate()); // landscape
    }
    PdfWriter.getInstance(pdfDoc, out);

    // Measurements are always in points (72 per inch)
    // This sets up 1/2 inch margins side margins and 0.35in top and bottom
    // margins
    pdfDoc.setMargins(0.5f * POINTS_PER_INCH, 0.5f * POINTS_PER_INCH, 0.35f * POINTS_PER_INCH,
            0.35f * POINTS_PER_INCH);
    pdfDoc.open();

    // Header cell with challenge title to add to both scoresheets
    final Paragraph titleParagraph = new Paragraph();
    final Chunk titleChunk = new Chunk(m_pageTitle,
            FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14, Font.NORMAL, BaseColor.WHITE));
    titleParagraph.setAlignment(Element.ALIGN_CENTER);
    titleParagraph.add(titleChunk);

    titleParagraph.add(Chunk.NEWLINE);
    final Chunk swVersionChunk = new Chunk("SW version: " + Version.getVersion(),
            FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE));
    titleParagraph.add(swVersionChunk);
    if (null != m_revision) {

        final Chunk revisionChunk = new Chunk(" Descriptor revision: " + m_revision,
                FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE));

        titleParagraph.add(revisionChunk);
    }

    final PdfPCell head = new PdfPCell();
    head.setColspan(2);
    head.setBorder(1);
    head.setPaddingTop(0);
    head.setPaddingBottom(3);
    head.setBackgroundColor(new BaseColor(64, 64, 64));
    head.setVerticalAlignment(Element.ALIGN_TOP);
    head.addElement(titleParagraph);

    // Cells for score field, and 2nd check initials
    final Phrase des = new Phrase("Data Entry Score _______", ARIAL_8PT_NORMAL);
    final PdfPCell desC = new PdfPCell(des);
    desC.setBorder(0);
    desC.setPaddingTop(9);
    desC.setPaddingRight(36);
    desC.setHorizontalAlignment(Element.ALIGN_RIGHT);
    final Phrase sci = new Phrase("2nd Check Initials _______", ARIAL_8PT_NORMAL);
    final PdfPCell sciC = new PdfPCell(sci);
    sciC.setBorder(0);
    sciC.setPaddingTop(9);
    sciC.setPaddingRight(36);
    sciC.setHorizontalAlignment(Element.ALIGN_RIGHT);

    // Create a table with a grid cell for each scoresheet on the page
    PdfPTable wholePage = getTableForPage(orientationIsPortrait);
    wholePage.setWidthPercentage(100);
    for (int i = 0; i < m_numSheets; i++) {
        if (i > 0 && (orientationIsPortrait || (i % 2) == 0)) {
            pdfDoc.newPage();
            wholePage = getTableForPage(orientationIsPortrait);
            wholePage.setWidthPercentage(100);
        }

        // This table is a single score sheet
        final PdfPTable scoreSheet = new PdfPTable(2);
        // scoreSheet.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.BOTTOM
        // | Rectangle.RIGHT | Rectangle.TOP); //FIXME DEBUG should be NO_BORDER
        scoreSheet.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        scoreSheet.getDefaultCell().setPaddingRight(1);
        scoreSheet.getDefaultCell().setPaddingLeft(0);

        scoreSheet.addCell(head);

        final PdfPTable teamInfo = new PdfPTable(7);
        teamInfo.setWidthPercentage(100);
        teamInfo.setWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, .9f });

        // Time label cell
        final Paragraph timeP = new Paragraph("Time:", ARIAL_10PT_NORMAL);
        timeP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell timeLc = new PdfPCell(scoreSheet.getDefaultCell());
        timeLc.addElement(timeP);
        teamInfo.addCell(timeLc);
        // Time value cell
        final Paragraph timeV = new Paragraph(null == m_time[i] ? SHORT_BLANK : m_time[i], COURIER_10PT_NORMAL);
        final PdfPCell timeVc = new PdfPCell(scoreSheet.getDefaultCell());
        timeVc.addElement(timeV);
        teamInfo.addCell(timeVc);

        // Table label cell
        final Paragraph tblP = new Paragraph("Table:", ARIAL_10PT_NORMAL);
        tblP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell tblLc = new PdfPCell(scoreSheet.getDefaultCell());
        tblLc.addElement(tblP);
        teamInfo.addCell(tblLc);
        // Table value cell
        final Paragraph tblV = new Paragraph(m_table[i], COURIER_10PT_NORMAL);
        final PdfPCell tblVc = new PdfPCell(scoreSheet.getDefaultCell());
        tblVc.addElement(tblV);
        teamInfo.addCell(tblVc);

        // Round number label cell
        final Paragraph rndP = new Paragraph("Round:", ARIAL_10PT_NORMAL);
        rndP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell rndlc = new PdfPCell(scoreSheet.getDefaultCell());
        rndlc.addElement(rndP);
        teamInfo.addCell(rndlc);
        // Round number value cell
        final Paragraph rndV = new Paragraph(m_round[i], COURIER_10PT_NORMAL);
        final PdfPCell rndVc = new PdfPCell(scoreSheet.getDefaultCell());
        // rndVc.setColspan(2);
        rndVc.addElement(rndV);
        teamInfo.addCell(rndVc);

        final PdfPCell temp1 = new PdfPCell(scoreSheet.getDefaultCell());
        // temp1.setColspan(2);
        temp1.addElement(new Paragraph("Judge ____", ARIAL_8PT_NORMAL));
        teamInfo.addCell(temp1);

        // Team number label cell
        final Paragraph nbrP = new Paragraph("Team #:", ARIAL_10PT_NORMAL);
        nbrP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell nbrlc = new PdfPCell(scoreSheet.getDefaultCell());
        nbrlc.addElement(nbrP);
        teamInfo.addCell(nbrlc);
        // Team number value cell
        final Paragraph nbrV = new Paragraph(null == m_number[i] ? SHORT_BLANK : String.valueOf(m_number[i]),
                COURIER_10PT_NORMAL);
        final PdfPCell nbrVc = new PdfPCell(scoreSheet.getDefaultCell());
        nbrVc.addElement(nbrV);
        teamInfo.addCell(nbrVc);

        // Team division label cell
        final Paragraph divP = new Paragraph(m_divisionLabel[i], ARIAL_10PT_NORMAL);
        divP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell divlc = new PdfPCell(scoreSheet.getDefaultCell());
        divlc.addElement(divP);
        divlc.setColspan(2);
        teamInfo.addCell(divlc);
        // Team division value cell
        final Paragraph divV = new Paragraph(m_division[i], COURIER_10PT_NORMAL);
        final PdfPCell divVc = new PdfPCell(scoreSheet.getDefaultCell());
        divVc.setColspan(2);
        divVc.addElement(divV);
        teamInfo.addCell(divVc);

        final PdfPCell temp2 = new PdfPCell(scoreSheet.getDefaultCell());
        // temp2.setColspan(2);
        temp2.addElement(new Paragraph("Team ____", ARIAL_8PT_NORMAL));
        teamInfo.addCell(temp2);

        // Team name label cell
        final Paragraph nameP = new Paragraph("Team Name:", ARIAL_10PT_NORMAL);
        nameP.setAlignment(Element.ALIGN_RIGHT);
        final PdfPCell namelc = new PdfPCell(scoreSheet.getDefaultCell());
        namelc.setColspan(2);
        namelc.addElement(nameP);
        teamInfo.addCell(namelc);
        // Team name value cell
        final Paragraph nameV = new Paragraph(m_name[i], COURIER_10PT_NORMAL);
        final PdfPCell nameVc = new PdfPCell(scoreSheet.getDefaultCell());
        nameVc.setColspan(5);
        nameVc.addElement(nameV);
        teamInfo.addCell(nameVc);

        // add team info cell to the team table
        final PdfPCell teamInfoCell = new PdfPCell(scoreSheet.getDefaultCell());
        teamInfoCell.addElement(teamInfo);
        teamInfoCell.setColspan(2);

        scoreSheet.addCell(teamInfoCell);

        if (null != m_goalsTable) {
            final PdfPCell goalCell = new PdfPCell(m_goalsTable);
            goalCell.setBorder(0);
            goalCell.setPadding(0);
            goalCell.setColspan(2);
            scoreSheet.addCell(goalCell);
        }

        scoreSheet.addCell(desC);
        scoreSheet.addCell(sciC);

        if (null != m_copyright) {
            final Phrase copyright = new Phrase("\u00A9" + m_copyright, f6i);
            final PdfPCell copyrightC = new PdfPCell(scoreSheet.getDefaultCell());
            copyrightC.addElement(copyright);
            copyrightC.setBorder(0);
            copyrightC.setHorizontalAlignment(Element.ALIGN_CENTER);
            copyrightC.setColspan(2);

            scoreSheet.addCell(copyrightC);
        }

        // the cell in the whole page table that will contain the single score
        // sheet
        final PdfPCell scoresheetCell = new PdfPCell(scoreSheet);
        scoresheetCell.setBorder(0);
        scoresheetCell.setPadding(0);

        // Interior borders between scoresheets on a page
        if (!orientationIsPortrait) {
            if (i % 2 == 0) {
                scoresheetCell.setPaddingRight(0.1f * POINTS_PER_INCH);
            } else {
                scoresheetCell.setPaddingLeft(0.1f * POINTS_PER_INCH);
            }
        }

        // Add the current scoresheet to the page
        wholePage.addCell(scoresheetCell);

        // Add the current table of scoresheets to the document
        if (orientationIsPortrait || (i % 2 != 0)) {
            pdfDoc.add(wholePage);
        }
    }

    // Add a blank cells to complete the table of the last page
    if (!orientationIsPortrait && m_numSheets % 2 != 0) {
        final PdfPCell blank = new PdfPCell();
        blank.setBorder(0);
        wholePage.addCell(blank);
        pdfDoc.add(wholePage);
    }

    pdfDoc.close();
}

From source file:fr.ybonnel.breizhcamppdf.PdfRenderer.java

License:Apache License

private void addLegend(Set<String> tracksInPage) throws DocumentException {
    PdfPTable legend = new PdfPTable(tracksInPage.size() + 1);
    legend.setWidthPercentage(100f);//from   w  w  w  .j  a va  2 s  .  c  o m
    PdfPCell cellTitle = new PdfPCell(new Phrase("Lgende : ", speakerFont));
    cellTitle.setBorder(Rectangle.NO_BORDER);
    cellTitle.setHorizontalAlignment(Element.ALIGN_CENTER);
    cellTitle.setPadding(2);
    legend.addCell(cellTitle);

    for (String track : tracksInPage) {
        PdfPCell color = new PdfPCell(new Phrase(track, speakerFont));
        color.setHorizontalAlignment(Element.ALIGN_CENTER);
        color.setPadding(2);
        color.setBackgroundColor(mapTrack.get(track));
        legend.addCell(color);
    }
    tracksInPage.clear();
    document.add(legend);
}

From source file:gov.nih.nci.firebird.service.registration.AbstractPdfWriterGenerator.java

License:Open Source License

PdfPCell createCell() {
    PdfPCell cell = new PdfPCell();
    cell.setPadding(CELL_PADDING_POINTS);
    cell.disableBorderSide(Rectangle.BOX);
    return cell;
}

From source file:it.vige.magazzino.pdf.Format1DocumentReceipt.java

License:Apache License

@Model
public void build(Receipt receipt) throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle("messages");

    Document document = new Document();
    ByteArrayOutputStream bytesOS = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, bytesOS);
    document.open();//ww  w  .j a v a  2  s .c om

    Font normalFont = new Font();
    Font headerFont = FontFactory.getFont(FontFactory.TIMES, 9);

    PdfContentByte canvas = writer.getDirectContentUnder();
    List<Data> imagesJar = receipt.getJar().getFiles();

    if (imagesJar != null && imagesJar.size() > 0) {
        Image image1 = Image.getInstance(imagesJar.get(0).getData());
        image1.setAbsolutePosition(166, 738);
        image1.scalePercent(60);
        document.add(image1);
        if (imagesJar.size() > 1) {
            Image image2 = Image.getInstance(imagesJar.get(1).getData());
            image2.setAbsolutePosition(326, 748);
            image2.scalePercent(40);
            document.add(image2);
        }
    }

    Phrase phrase1 = new Phrase(receipt.getJar().getRagSoc1(), normalFont);
    Phrase phrase2 = new Phrase(
            receipt.getJar().getAddress().getAddress() + " " + receipt.getJar().getAddress().getCivicNumber(),
            normalFont);
    Phrase phrase3 = new Phrase("Loc. " + receipt.getJar().getAddress().getTown() + " - "
            + receipt.getJar().getAddress().getCap() + " " + receipt.getJar().getAddress().getCity() + " ("
            + receipt.getJar().getAddress().getProvince() + ")", normalFont);
    Phrase phrase4 = new Phrase("Tel. " + receipt.getJar().getAddress().getPhone() + " r.a.Fax "
            + receipt.getJar().getAddress().getFax(), normalFont);
    Phrase phrase5 = new Phrase(
            receipt.getJar().getAddress().getSite() + " E-mail: " + receipt.getJar().getAddress().getEmail(),
            normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase1, 36, 784, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase2, 36, 774, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase3, 36, 764, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase4, 36, 754, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase5, 36, 744, 0);

    Phrase phrase6 = new Phrase(bundle.getString("magazzino_iva") + " " + receipt.getJar().getIva(),
            normalFont);
    Phrase phrase7 = new Phrase(bundle.getString("magazzino_capsoc") + " " + receipt.getJar().getCapSoc()
            + " - " + bundle.getString("magazzino_reapi") + " n. " + receipt.getJar().getReaPI(), normalFont);
    Phrase phrase8 = new Phrase("Reg. Impr. PI n. " + receipt.getJar().getIva(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase6, 36, 724, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase7, 36, 714, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase8, 36, 704, 0);

    Phrase phrase9 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase10 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase11 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase12 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase13 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase14 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase15 = new Phrase("prova 4: prova 4", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase9, 36, 664, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase10, 36, 654, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase11, 36, 644, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase12, 36, 634, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase13, 36, 624, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase14, 36, 614, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase15, 36, 604, 0);

    List<Data> imagesCustomer = receipt.getCustomer().getFiles();

    if (imagesCustomer != null && imagesCustomer.size() > 0) {
        Image image3 = Image.getInstance(imagesCustomer.get(0).getData());
        image3.setAbsolutePosition(212, 664);
        image3.scalePercent(40);
        document.add(image3);
    }

    Phrase phrase16 = new Phrase(receipt.getCustomer().getName(), normalFont);
    Phrase phrase17 = new Phrase(receipt.getCustomer().getAddress().getAddress() + ", "
            + receipt.getCustomer().getAddress().getCivicNumber(), normalFont);
    Phrase phrase18 = new Phrase(
            receipt.getCustomer().getAddress().getCap() + " " + receipt.getCustomer().getAddress().getCity()
                    + " " + receipt.getCustomer().getAddress().getProvince(),
            normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase16, 206, 644, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase17, 206, 624, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase18, 206, 604, 0);

    Phrase phrase19 = new Phrase("prova", normalFont);
    Phrase phrase20 = new Phrase("prova", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase19, 316, 694, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase20, 356, 694, 0);

    Phrase phrase21 = new Phrase(
            bundle.getString("customer_code").toUpperCase() + " " + bundle.getString("customer").toUpperCase(),
            headerFont);
    Phrase phrase22 = new Phrase(bundle.getString("pdf_partita_iva").toUpperCase(), headerFont);
    Phrase phrase23 = new Phrase(bundle.getString("pdf_agent").toUpperCase(), headerFont);
    Phrase phrase24 = new Phrase(bundle.getString("pdf_number_receipt").toUpperCase(), headerFont);
    Phrase phrase25 = new Phrase(
            bundle.getString("receipt_date").toUpperCase() + " " + bundle.getString("receipt").toUpperCase(),
            headerFont);
    Phrase phrase26 = new Phrase(bundle.getString("pdf_number_page").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase21, 24, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase22, 100, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase23, 176, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase24, 390, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase25, 466, 540, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase26, 542, 540, 0);

    Phrase phrase27 = new Phrase("aaqaqaq", normalFont);
    Phrase phrase28 = new Phrase("cddcddcd", normalFont);
    Phrase phrase29 = new Phrase("cnjcndkd", normalFont);
    Phrase phrase30 = new Phrase(receipt.getCodeReceipt() + "", normalFont);
    Phrase phrase31 = new Phrase(receipt.getDate(), normalFont);
    Phrase phrase32 = new Phrase("tgsb", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase27, 36, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase28, 106, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase29, 176, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase30, 396, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase31, 470, 530, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase32, 546, 530, 0);

    Phrase phrase33 = new Phrase("aaqaqaq", headerFont);
    Phrase phrase34 = new Phrase("cddcddcd", headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase33, 24, 513, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase34, 264, 513, 0);

    Phrase phrase35 = new Phrase("cnjcndkd", normalFont);
    Phrase phrase36 = new Phrase("dddedreqq", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase35, 36, 503, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase36, 276, 503, 0);

    Phrase phrase37 = new Phrase(bundle.getString("article_code").toUpperCase(), headerFont);
    Phrase phrase38 = new Phrase(bundle.getString("article_description").toUpperCase(), headerFont);
    Phrase phrase39 = new Phrase(bundle.getString("article_um").toUpperCase(), headerFont);
    Phrase phrase40 = new Phrase(bundle.getString("pdf_number_articles").toUpperCase(), headerFont);
    Phrase phrase41 = new Phrase(bundle.getString("article_prize").toUpperCase(), headerFont);
    Phrase phrase42 = new Phrase(bundle.getString("pdf_reduction").toUpperCase(), headerFont);
    Phrase phrase43 = new Phrase(bundle.getString("pdf_amount").toUpperCase(), headerFont);
    Phrase phrase44 = new Phrase(bundle.getString("pdf_iva").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase37, 47, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase38, 126, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase39, 286, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase40, 324, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase41, 373, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase42, 440, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase43, 488, 480, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase44, 552, 480, 0);

    Phrase phrase45 = null;
    Phrase phrase46 = null;
    Phrase phrase47 = null;
    Phrase phrase48 = null;
    Phrase phrase49 = null;
    Phrase phrase50 = null;
    Phrase phrase51 = null;
    Phrase phrase52 = null;

    int i = 0;
    for (i = 0; i < 70; i = i + 15) {
        phrase45 = new Phrase("dgbsbb", normalFont);
        phrase46 = new Phrase("323232", normalFont);
        phrase47 = new Phrase("bbg", normalFont);
        phrase48 = new Phrase("wefwe", normalFont);
        phrase49 = new Phrase("ewrew", normalFont);
        phrase50 = new Phrase("ewr5", normalFont);
        phrase51 = new Phrase("dsadasd", normalFont);
        phrase52 = new Phrase("ds", normalFont);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase45, 59, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase46, 126, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase47, 280, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase48, 306, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase49, 368, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase50, 436, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase51, 480, 460 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase52, 556, 460 - i, 0);
    }

    int j = 298;
    if (i - 298 < 0)
        i = 298;
    else {
        j = i;
        i = 460 - i;
    }

    Phrase phrase81 = new Phrase(receipt.getCause(), normalFont);
    Phrase phrase82 = new Phrase(receipt.getDescription(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase81, 59, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase82, 326, i, 0);

    Phrase phrase53 = new Phrase(bundle.getString("pdf_total_goods").toUpperCase(), headerFont);
    Phrase phrase54 = new Phrase(bundle.getString("pdf_reduction").toUpperCase(), headerFont);
    Phrase phrase55 = new Phrase(bundle.getString("pdf_total_net").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase53, 26, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase54, 104, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase55, 182, i - 30, 0);

    Phrase phrase56 = new Phrase("opoppp", normalFont);
    Phrase phrase57 = new Phrase("2ws", normalFont);
    Phrase phrase58 = new Phrase("78900", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase56, 96, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase57, 176, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase58, 252, i - 50, 0);

    Phrase phrase59 = new Phrase(bundle.getString("pdf_expiries").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase59, 36, i - 70, 0);

    Phrase phrase60 = new Phrase("78900", normalFont);
    Phrase phrase61 = new Phrase("opoppp", normalFont);
    Phrase phrase62 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase60, 166, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase61, 166, i - 110, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase62, 166, i - 130, 0);

    Phrase phrase63 = new Phrase("78900", normalFont);
    Phrase phrase64 = new Phrase("opoppp", normalFont);
    Phrase phrase65 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase63, 256, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase64, 256, i - 110, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase65, 256, i - 130, 0);

    Phrase phrase66 = new Phrase(bundle.getString("pdf_transport").toUpperCase(), headerFont);
    Phrase phrase67 = new Phrase(bundle.getString("pdf_caching").toUpperCase(), headerFont);
    Phrase phrase68 = new Phrase(bundle.getString("pdf_various_costs").toUpperCase(), headerFont);
    Phrase phrase69 = new Phrase(bundle.getString("pdf_stamps").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase66, 260, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase67, 340, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase68, 418, i - 30, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase69, 496, i - 30, 0);

    Phrase phrase70 = new Phrase("2ws", normalFont);
    Phrase phrase71 = new Phrase("78900", normalFont);
    Phrase phrase72 = new Phrase("opoppp", normalFont);
    Phrase phrase73 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase70, 300, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase71, 390, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase72, 468, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase73, 546, i - 50, 0);

    Phrase phrase74 = new Phrase(bundle.getString("article_imponible").toUpperCase(), headerFont);
    Phrase phrase75 = new Phrase(bundle.getString("pdf_tax").toUpperCase(), headerFont);
    Phrase phrase76 = new Phrase(bundle.getString("pdf_total_receipt").toUpperCase(), headerFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase74, 260, i - 70, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase75, 352, i - 70, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase76, 484, i - 70, 0);

    Phrase phrase77 = new Phrase("2ws", normalFont);
    Phrase phrase78 = new Phrase("78900", normalFont);
    Phrase phrase79 = new Phrase("opoppp", normalFont);
    Phrase phrase80 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase77, 310, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase78, 352, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase79, 450, i - 90, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase80, 536, i - 110, 0);

    PdfPTable table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    PdfPCell cell = new PdfPCell();
    cell.setPadding(127);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(6);
    table.getDefaultCell().setPadding(5);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 7, 7, 20, 7, 7, 3 });
    cell = new PdfPCell();
    cell.setPadding(14);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(2);
    table.getDefaultCell().setPadding(5);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 15.5f, 20 });
    cell = new PdfPCell();
    cell.setPadding(14);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(3);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(100);
    table.setWidths(new float[] { 23.5f, 2, 5, 6, 4, 7, 3 });
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(j * 8 - 2279);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(5);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(17);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(5);
    table.setWidths(new float[] { 10.5f, 4, 6, 4 });
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.setPadding(48);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    document.close();

    HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
    response.setContentType("application/pdf");
    response.addHeader("Content-disposition",
            "attachment; filename=\"" + bundle.getString("receipt") + "-" + receipt.getDate() + ".pdf\"");

    ServletOutputStream os = response.getOutputStream();
    os.write(bytesOS.toByteArray());
    os.flush();
    os.close();

    facesContext.responseComplete();
}

From source file:it.vige.magazzino.pdf.Format2DocumentReceipt.java

License:Apache License

@Model
public void build(Receipt receipt) throws Exception {
    ResourceBundle bundle = ResourceBundle.getBundle("messages");

    Document document = new Document();
    ByteArrayOutputStream bytesOS = new ByteArrayOutputStream();
    PdfWriter writer = PdfWriter.getInstance(document, bytesOS);

    document.open();//  w  w w  . j ava 2  s . c om

    Font normalFont = new Font();

    PdfContentByte canvas = writer.getDirectContentUnder();
    List<Data> imagesJar = receipt.getJar().getFiles();

    if (imagesJar != null && imagesJar.size() > 0) {
        Image image1 = Image.getInstance(imagesJar.get(0).getData());
        image1.setAbsolutePosition(36, 742);
        image1.scalePercent(60);
        document.add(image1);
    }

    Phrase phrase1 = new Phrase(bundle.getString("pdf_number_receipt"), normalFont);
    Phrase phrase2 = new Phrase(receipt.getCodeReceipt() + "", normalFont);
    Phrase phrase3 = new Phrase(bundle.getString("receipt_date"), normalFont);
    Phrase phrase4 = new Phrase(receipt.getDate(), normalFont);
    Phrase phrase5 = new Phrase(receipt.getCause(), normalFont);
    Phrase phrase6 = new Phrase(receipt.getDescription(), normalFont);
    Phrase phrase7 = new Phrase(bundle.getString("customer_code") + " " + bundle.getString("customer"),
            normalFont);
    Phrase phrase8 = new Phrase("prova 4: prova 4", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase1, 286, 797, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase2, 386, 797, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase3, 286, 777, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase4, 386, 777, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase5, 286, 757, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase6, 386, 757, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase7, 286, 737, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase8, 386, 737, 0);

    Phrase phrase9 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase10 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase11 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase12 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase13 = new Phrase(bundle.getString("pdf_tel"), normalFont);
    Phrase phrase14 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase15 = new Phrase(bundle.getString("pdf_partita_iva_short"), normalFont);
    Phrase phrase16 = new Phrase("prova 4: prova 4", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase9, 36, 718, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase10, 136, 718, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase11, 36, 698, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase12, 136, 698, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase13, 36, 678, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase14, 136, 678, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase15, 36, 658, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase16, 136, 658, 0);

    Phrase phrase17 = new Phrase("Ditta", normalFont);
    Phrase phrase18 = new Phrase("prova 2: prova 2", normalFont);
    Phrase phrase19 = new Phrase("prova 3: prova 3", normalFont);
    Phrase phrase20 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase21 = new Phrase("prova 4: prova 4", normalFont);
    Phrase phrase22 = new Phrase(bundle.getString("pdf_partita_iva_short"), normalFont);
    Phrase phrase23 = new Phrase("prova 2: ", normalFont);
    Phrase phrase24 = new Phrase(bundle.getString("pdf_cod_fisc"), normalFont);
    Phrase phrase25 = new Phrase("prova 2: ", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase17, 236, 736, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase18, 236, 708, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase19, 236, 688, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase20, 236, 668, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase21, 386, 668, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase22, 236, 648, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase23, 286, 648, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase24, 356, 648, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase25, 416, 648, 0);

    Phrase phrase26 = new Phrase(bundle.getString("article_code"), normalFont);
    Phrase phrase27 = new Phrase(bundle.getString("article_description"), normalFont);
    Phrase phrase28 = new Phrase(bundle.getString("pdf_number_articles"), normalFont);
    Phrase phrase29 = new Phrase(bundle.getString("article_prize"), normalFont);
    Phrase phrase30 = new Phrase(bundle.getString("pdf_reduction"), normalFont);
    Phrase phrase31 = new Phrase(bundle.getString("pdf_amount"), normalFont);
    Phrase phrase32 = new Phrase(bundle.getString("pdf_iva"), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase26, 59, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase27, 146, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase28, 208, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase29, 280, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase30, 353, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase31, 422, 618, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase32, 498, 618, 0);

    Phrase phrase33 = null;
    Phrase phrase34 = null;
    Phrase phrase35 = null;
    Phrase phrase36 = null;
    Phrase phrase37 = null;
    Phrase phrase38 = null;
    Phrase phrase39 = null;

    int i = 0;
    for (i = 0; i < 70; i = i + 15) {
        phrase33 = new Phrase("dsadasd", normalFont);
        phrase34 = new Phrase("dgbsbb", normalFont);
        phrase35 = new Phrase("323232", normalFont);
        phrase36 = new Phrase("bbgdbdfbdb", normalFont);
        phrase37 = new Phrase("wefwew", normalFont);
        phrase38 = new Phrase("ewrew", normalFont);
        phrase39 = new Phrase("ewr5", normalFont);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase33, 59, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase34, 136, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase35, 196, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase36, 266, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase37, 351, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase38, 416, 598 - i, 0);
        ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase39, 496, 598 - i, 0);
    }
    int j = 298;
    if (i - 298 < 0)
        i = 298;
    else {
        j = i;
        i = 588 - i;
    }
    Phrase phrase40 = new Phrase(bundle.getString("pdf_references").toUpperCase(), normalFont);
    Phrase phrase41 = new Phrase(bundle.getString("pdf_delivery").toUpperCase(), normalFont);
    Phrase phrase42 = new Phrase(bundle.getString("pdf_payments").toUpperCase(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase40, 105, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase41, 206, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase42, 316, i, 0);

    Phrase phrase43 = new Phrase("opoppp", normalFont);
    Phrase phrase44 = new Phrase("2ws", normalFont);
    Phrase phrase45 = new Phrase("78900", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase43, 59, i - 20, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase44, 186, i - 20, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, phrase45, 276, i - 20, 0);

    Phrase phrase46 = new Phrase(bundle.getString("pdf_sign_producer").toUpperCase(), normalFont);
    Phrase phrase47 = new Phrase(bundle.getString("pdf_sign_receiver").toUpperCase(), normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase46, 154, i - 40, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase47, 321, i - 40, 0);

    Phrase phrase48 = new Phrase(bundle.getString("article_imponible"), normalFont);
    Phrase phrase49 = new Phrase("opoppp", normalFont);
    Phrase phrase50 = new Phrase(bundle.getString("pdf_tax"), normalFont);
    Phrase phrase51 = new Phrase("78900", normalFont);
    Phrase phrase52 = new Phrase(bundle.getString("pdf_total_receipt"), normalFont);
    Phrase phrase53 = new Phrase("2ws", normalFont);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase48, 356, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase49, 566, i, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase50, 356, i - 25, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase51, 566, i - 25, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, phrase52, 356, i - 50, 0);
    ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, phrase53, 566, i - 50, 0);

    PdfPTable table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    PdfPCell cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 47, 18, 18, 17 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(3);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(3);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 38, 48, 14 });
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(40);
    table.addCell(cell);
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    table.addCell(cell);
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(1);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    cell = new PdfPCell();
    cell.disableBorderSide(PdfPCell.RIGHT);
    cell.disableBorderSide(PdfPCell.LEFT);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    cell.disableBorderSide(PdfPCell.TOP);
    cell.setPadding(3);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 16, 12, 11, 17, 12, 16, 16 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(10);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(7);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 16, 12, 11, 17, 12, 16, 16 });
    cell = new PdfPCell();
    cell.enableBorderSide(PdfPCell.RIGHT);
    cell.enableBorderSide(PdfPCell.LEFT);
    cell.enableBorderSide(PdfPCell.BOTTOM);
    cell.enableBorderSide(PdfPCell.TOP);
    cell.setPadding(j * 8 - 2234);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(5);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 20, 20, 20, 20, 20 });
    cell = new PdfPCell();
    cell.setPadding(20);
    table.addCell(cell);
    table.addCell(cell);
    table.addCell(cell);
    cell.disableBorderSide(PdfPCell.BOTTOM);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    table = new PdfPTable(4);
    table.getDefaultCell().setPadding(50);
    table.setWidthPercentage(105);
    table.setWidths(new float[] { 30, 30, 20, 20 });
    cell = new PdfPCell();
    cell.setPadding(20);
    table.addCell(cell);
    table.addCell(cell);
    cell.disableBorderSide(PdfPCell.TOP);
    table.addCell(cell);
    table.addCell(cell);
    document.add(table);

    document.close();

    HttpServletResponse response = (HttpServletResponse) extCtx.getResponse();
    response.setContentType("application/pdf");
    response.addHeader("Content-disposition",
            "attachment; filename=\"" + bundle.getString("receipt") + "-" + receipt.getDate() + ".pdf\"");

    ServletOutputStream os = response.getOutputStream();
    os.write(bytesOS.toByteArray());
    os.flush();
    os.close();

    facesContext.responseComplete();
}

From source file:itext_result.Main.java

private int developScreeningSheet() {
    new SwingWorker<Object, Object>() {
        String filename;/*from w ww . j a va2 s .  c o  m*/

        @Override
        protected void done() {

            // ConsoleMsg("Printing PROFILE SHEET IN PROGRESS.. ");
        }

        public PdfPCell createBarcode(PdfWriter writer, String code) throws DocumentException, IOException {
            BarcodeEAN barcode = new BarcodeEAN();
            barcode.setCodeType(Barcode.EAN8);
            barcode.setCode(code);
            PdfPCell cell = new PdfPCell(
                    barcode.createImageWithBarcode(writer.getDirectContent(), BaseColor.BLACK, BaseColor.GRAY),
                    true);
            cell.setPadding(10);
            return cell;
        }

        class ImageContent implements PdfPTableEvent {

            protected com.itextpdf.text.Image content;

            public ImageContent(com.itextpdf.text.Image content) {
                this.content = content;
            }

            public void tableLayout(PdfPTable table, float[][] widths, float[] heights, int headerRows,
                    int rowStart, PdfContentByte[] canvases) {
                try {
                    PdfContentByte canvas = canvases[PdfPTable.TEXTCANVAS];
                    float x = widths[3][1] + 10;
                    float y = heights[3] - 10 - content.getScaledHeight();
                    content.setAbsolutePosition(x, y);
                    canvas.addImage(content);
                } catch (DocumentException e) {
                    throw new ExceptionConverter(e);
                }
            }
        }

        @Override
        protected Object doInBackground() throws Exception {
            //   System.err.println(" Roll No Received ....." + rollno);
            Document doc = new Document();
            try {
                PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("12345" + ".pdf"));
                doc.open();
                doc.addTitle("Recruitment PET Sheett - " + "Created By SOS : ");
                doc.addSubject("Confidential Report Eyes Only");
                doc.addKeywords("");
                doc.addAuthor("SOS");
                doc.addCreator("SOS");

                // A4 = 210mm x 297mm ~ 605points x 855points
                doc.setPageSize(PageSize.A5);
                doc.setMargins(15f, 15f, 15f, 15f);

                /////////////////////////////////////////////////////////////
                int pageno = 1;

                for (int i = 0; i == pageno; i++) {

                    //    doc.add(imageRight);
                }

                PdfContentByte cb = writer.getDirectContent();
                //DONE
                BarcodeEAN codeEAN = new BarcodeEAN();
                codeEAN.setCodeType(Barcode.EAN8);
                Barcode128 code128 = new Barcode128();
                code128.setCode(String.valueOf("123456"));

                Barcode128 code128_jacket = new Barcode128();
                code128_jacket.setCode(String.valueOf("10345"));

                codeEAN.setCode(String.valueOf("123456"));
                com.itextpdf.text.Image imageEAN = code128.createImageWithBarcode(cb, null, null);
                // imageEAN.scalePercent(10f);
                //464f, 725f
                //  imageEAN.setAbsolutePosition(474f, 662f);

                int i = 1;
                while (i <= pageno) {
                    doc.newPage();
                    //   cb.addImage(imageRight);
                    //   cb.addImage(imageEAN);
                    i++;
                }

                com.itextpdf.text.Image carcode = code128_jacket.createImageWithBarcode(cb, null, null);
                carcode.scaleAbsolute(100f, 35f);
                carcode.setAbsolutePosition(500f, 600f);
                writer.addDirectImageSimple(carcode);
                //     cb.addImage(carcode);

                com.itextpdf.text.Image carcode2 = code128.createImageWithBarcode(cb, null, null);
                carcode2.scaleAbsolute(100f, 35f);
                carcode2.setAbsolutePosition(450f, 760f);
                writer.addDirectImageSimple(carcode2);
                //    cb.addImage(carcode2);

                Image image1 = Image.getInstance("jklogo.gif");

                PdfPTable table = new PdfPTable(1);
                table.setWidthPercentage(99);
                table.addCell(image1);
                doc.add(table);
                table = new PdfPTable(4);
                table.setWidthPercentage(99);

                float[] columnWidths = { 6, 2 };
                PdfPTable CandidateTable = new PdfPTable(columnWidths);
                Font f = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK);
                Font fsmall = new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL, GrayColor.BLACK);
                PdfPCell rollno = new PdfPCell(new Phrase("Roll No# " + String.valueOf("123456"), fsmall));
                PdfPCell cname = new PdfPCell(new Phrase("Name #" + String.valueOf("John Doe"), fsmall));
                //                    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
                //                    String today = formatter.format(cInfo.getDob());
                PdfPCell dob = new PdfPCell(new Phrase("DOB#" + String.valueOf("12-03-1989"), fsmall));
                PdfPCell fname = new PdfPCell(new Phrase("F/H Name #" + String.valueOf("Big John"), fsmall));
                PdfPCell type = new PdfPCell(new Phrase("Total Time  #" + String.valueOf("350.00"), fsmall));

                //  String scrtoday = formatter.format(cInfo.getScreeningdate());
                //  System.out.println("Today : " + today);
                PdfPCell scrdate = new PdfPCell(new Phrase("Laps  #" + String.valueOf("4"), fsmall));
                PdfPCell cell = new PdfPCell(new Phrase(" ", fsmall));

                rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                cname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                rollno.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                dob.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                fname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                type.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                scrdate.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                cell.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);

                CandidateTable.addCell(rollno);
                CandidateTable.addCell(cell);
                CandidateTable.addCell(cname);
                CandidateTable.addCell(cell);
                CandidateTable.addCell(dob);
                CandidateTable.addCell(cell);

                PdfPTable CandidateOtherTable = new PdfPTable(columnWidths);
                CandidateOtherTable.addCell(fname);
                CandidateOtherTable.addCell(cell);
                CandidateOtherTable.addCell(scrdate);
                CandidateOtherTable.addCell(cell);
                CandidateOtherTable.addCell(type);
                CandidateOtherTable.addCell(cell);

                PdfPCell race_start_time = new PdfPCell(new Phrase("Start Time :XX-XX-XX ", fsmall));
                PdfPCell race_end_time = new PdfPCell(new Phrase("End Time :XX-XX-XX", fsmall));
                PdfPCell race_total_time = new PdfPCell(new Phrase("Total Time : 350.00   ", fsmall));
                race_start_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                race_end_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                race_total_time.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);

                PdfPTable CandidateRaceDetails = new PdfPTable(columnWidths);
                CandidateRaceDetails.addCell(race_start_time);
                CandidateRaceDetails.addCell(cell);
                CandidateRaceDetails.addCell(race_end_time);
                CandidateRaceDetails.addCell(cell);
                CandidateRaceDetails.addCell(race_total_time);
                CandidateRaceDetails.addCell(cell);

                PdfPTable tablewith3cells = new PdfPTable(3);
                //1 St Col for Roll No Name and DOB
                tablewith3cells.addCell(CandidateTable);
                //2 nd Col for Father Name sCREEning Date Gurkha 
                tablewith3cells.addCell(CandidateOtherTable);
                //3rd Col for Barcode to be Printed
                tablewith3cells.addCell(CandidateRaceDetails);
                // Setting the Width here to 101
                tablewith3cells.setWidthPercentage(99);
                doc.add(tablewith3cells);

                PdfPTable userArea = new PdfPTable(1);
                userArea.setWidthPercentage(99);
                userArea.addCell(" \n \n Congratulations \n \n ");

                doc.add(userArea);

                PdfPTable footerCSBC = new PdfPTable(2);
                footerCSBC.setWidthPercentage(99);

                PdfPCell height_box = new PdfPCell(new Phrase("Height  \n\n\n", f));
                height_box.setBorder(com.itextpdf.text.Rectangle.BOX);
                PdfPCell chest_box = new PdfPCell(new Phrase("Chest  \n\n\n", f));
                chest_box.setBorder(com.itextpdf.text.Rectangle.BOX);
                PdfPCell chest_exp_box = new PdfPCell(new Phrase("Chest Exp  \n\n\n", f));
                chest_exp_box.setBorder(com.itextpdf.text.Rectangle.BOX);
                PdfPCell pushup_box = new PdfPCell(new Phrase("Pushup  \n\n\n", f));
                pushup_box.setBorder(com.itextpdf.text.Rectangle.BOX);

                //CSignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX);
                // ASignatureBox.setBorder(com.itextpdf.text.Rectangle.BOX);
                footerCSBC.addCell(height_box);
                footerCSBC.addCell(chest_box);
                footerCSBC.addCell(chest_exp_box);
                footerCSBC.addCell(pushup_box);

                doc.add(footerCSBC);

                float[] columnWidths_ForBarcode = { 6, 3 };
                PdfPTable terminalinfo = new PdfPTable(columnWidths_ForBarcode);
                // terminalinfo.setWidthPercentage(99);
                String computername = InetAddress.getLocalHost().getHostName();
                System.out.println(computername);
                PdfPCell pcname = new PdfPCell(new Phrase("\t Jacket \n\n ", f));

                String UserMatchScore = "\t Barcode\n\n";

                PdfPCell score = new PdfPCell(new Phrase(UserMatchScore, f));
                PdfPCell barcode = new PdfPCell(carcode2);
                PdfPCell jacketnumber = new PdfPCell(carcode);
                pcname.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                score.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                barcode.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);
                jacketnumber.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);

                terminalinfo.addCell(score);
                terminalinfo.addCell(pcname);
                terminalinfo.addCell(barcode);
                terminalinfo.addCell(jacketnumber);

                doc.add(terminalinfo);

                PdfPCell eula_notice = new PdfPCell(new Phrase("  ", f));
                eula_notice.setBorder(com.itextpdf.text.Rectangle.NO_BORDER);

                cell.setHorizontalAlignment(Element.ALIGN_CENTER);

                PdfPTable eula_notice_table = new PdfPTable(1);
                eula_notice_table.setWidthPercentage(25);
                eula_notice_table.addCell(eula_notice);

                doc.add(eula_notice_table);

            } catch (Exception e) {
                System.err.println(e.getMessage());

                // ConsoleMsg(e.getMessage());
            } finally {
                doc.close();
                doc.close();
                doc.close();
            }

            //ConsoleMsg("PDF... GENERATED");
            return null;
            //    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }.execute();

    return 0;
}