Example usage for com.itextpdf.text Document setMargins

List of usage examples for com.itextpdf.text Document setMargins

Introduction

In this page you can find the example usage for com.itextpdf.text Document setMargins.

Prototype


public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom) 

Source Link

Document

Sets the margins.

Usage

From source file:Export.SeguroViagem.java

public String criarDoc(ViagemBean vb, String numCriente, String user, String arquivo, Contrato c) {
    try {// w  w  w. ja  v a2s  .c  o m
        PdfPTable pTablePrincaipal;
        //            PdfPTable pTableSegu1;
        PdfPTable pTableSegu2;
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss");
        SimpleDateFormat sdfPot = new SimpleDateFormat("dd/MM/yyyy");

        Font fontCorpoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 7.9f);
        Font fontCorpo = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7.9f);

        //            PdfPTable pTableLinha = new PdfPTable(1);
        //            pTableLinha.setWidthPercentage(95);
        //            PdfPCell linha= new PdfPCell(new Phrase(" "));
        //            
        //            linha.setBorderWidthTop(0.5f);
        //            linha.setBorderWidthBottom(0);
        //            linha.setBorderWidthLeft(0);
        //            linha.setBorderWidthRight(0);
        //            pTableLinha.addCell(linha);
        Document documento = new Document();
        documento.setPageSize(PageSize.A4);
        documento.setMargins(20f, 20f, 138f, 5f);
        File ff = new File(arquivo + "/" + user + "/Seguro Viagem/");
        ff.mkdirs();
        String Ddata = sdf.format(new Date());
        ff = new File(ff.getAbsoluteFile() + "/" + "Doc Seguro Viagem " + Ddata + ".pdf");
        reString = "../Documentos/" + user + "/Seguro Viagem/" + "Doc Seguro Viagem " + Ddata + ".pdf";
        outputStraem = new FileOutputStream(ff);
        PdfWriter writer = PdfWriter.getInstance(documento, outputStraem);

        if (MarcaDAgua.isSimulation) {
            MarcaDAgua.SimulacaoVertical v = new MarcaDAgua.SimulacaoVertical();
            writer.setPageEvent(v);
        }

        if (MarcaDAgua.isCanceled) {
            MarcaDAgua.AnulacaoVertical v = new MarcaDAgua.AnulacaoVertical();
            writer.setPageEvent(v);
        }

        documento.open();

        int total = vb.getInfoPessoaSegurada().size();
        for (int i = 0; i < total; i++) {

            pTablePrincaipal = new PdfPTable(1);
            pTablePrincaipal.setWidthPercentage(98f);
            //                pTableSegu1 = new PdfPTable(1);
            //                pTableSegu1.setWidthPercentage(95);
            pTableSegu2 = new PdfPTable(new float[] { 55f, 45f });
            pTableSegu2.setWidthPercentage(100f);

            //                PdfPCell cellTitulo= new PdfPCell(new Phrase("Lista Pessoas Seguradas",fontCabecalhoN));
            //                cellTitulo.setBorder(0);
            PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontCorpo));
            cellNull.setBorder(0);

            //                if(((i)%6)==0)
            //                {
            //                    pTableSegu1.addCell(cellTitulo);
            //                    pTableSegu1.addCell(cellNull);
            //                }
            //                
            Paragraph pCl = new Paragraph();
            pCl.add(new Phrase("Nome do Segurado: ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getNomePessoaSegurada().toUpperCase(),
                    fontCorpoN));
            PdfPCell cellNome = new PdfPCell(pCl);
            cellNome.setColspan(2);
            cellNome.setBorder(0);
            pTableSegu2.addCell(cellNome);

            //                PdfPCell cellNum= new PdfPCell(new Phrase(""+(i+1),fontCorpo));
            //                cellNum.setBorder(0);
            //                cellNum.setHorizontalAlignment(Element.ALIGN_RIGHT);
            //                pTableSegu2.addCell(cellNum);
            pCl = new Paragraph();
            pCl.add(new Phrase("Endereo: ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getEndereco().toUpperCase(), fontCorpoN));
            PdfPCell cellEndereco = new PdfPCell(pCl);
            cellEndereco.setBorder(0);
            pTableSegu2.addCell(cellEndereco);
            pTableSegu2.addCell(cellNull);

            pCl = new Paragraph();
            pCl.add(new Phrase("Data e Local Nascimento: ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getDataNascFormatada(), fontCorpoN));
            pCl.add(new Phrase(" em ", fontCorpo));
            pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getLocalNascimento(), fontCorpoN));
            PdfPCell cellNascDaNascloc = new PdfPCell(pCl);
            cellNascDaNascloc.setBorder(0);

            pCl = new Paragraph();
            pCl.add(new Phrase("Sexo: ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getSexo(), fontCorpoN));
            pCl.add(new Phrase("   Tel.N ", fontCorpo));
            pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getTelefone(), fontCorpoN));
            PdfPCell cellSexo = new PdfPCell(pCl);
            cellSexo.setBorder(0);
            pTableSegu2.addCell(cellNascDaNascloc);
            pTableSegu2.addCell(cellSexo);

            pCl = new Paragraph();
            pCl.add(new Phrase("Apolice: ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getNumApolice(), fontCorpoN));
            PdfPCell cellApolice = new PdfPCell(pCl);
            cellApolice.setBorder(0);

            pCl = new Paragraph();
            pCl.add(new Phrase("Cliente: ".toUpperCase(), fontCorpo));

            String[] codCliente = vb.getInfoPessoaSegurada().get(i).getNumApolice().split("/");

            pCl.add(new Phrase(((codCliente.length == 2) ? "TIN " + codCliente[1] : "TIN "), fontCorpoN));
            PdfPCell cellCliente = new PdfPCell(pCl);
            cellCliente.setBorder(0);
            pTableSegu2.addCell(cellApolice);
            pTableSegu2.addCell(cellCliente);

            pCl = new Paragraph();
            pCl.add(new Phrase("Durao: ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getNumDias() + " DIAS", fontCorpoN));
            PdfPCell cellDuracao = new PdfPCell(pCl);
            cellDuracao.setBorder(0);

            pCl = new Paragraph();
            pCl.add(new Phrase("Perodo: de ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(sdfPot.format(vb.getInfoPessoaSegurada().get(i).getDataInicio()), fontCorpoN));
            pCl.add(new Phrase("  ", fontCorpo));
            pCl.add(new Phrase(((vb.getInfoPessoaSegurada().get(i).getDataFim() != null)
                    ? sdfPot.format(vb.getInfoPessoaSegurada().get(i).getDataFim())
                    : " "), fontCorpoN));
            PdfPCell cellPeriodo = new PdfPCell(pCl);
            cellPeriodo.setBorder(0);
            pTableSegu2.addCell(cellDuracao);
            pTableSegu2.addCell(cellPeriodo);

            pCl = new Paragraph();
            pCl.add(new Phrase("Data de Emisso: ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(sdfPot.format(c.getDataContrato()), fontCorpoN));
            PdfPCell cellDataEmissao = new PdfPCell(pCl);
            cellDataEmissao.setBorder(0);

            pCl = new Paragraph();
            pCl.add(new Phrase("Destino: ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(
                    ClienteDao.paisesSelected(vb.getInfoPessoaSegurada().get(i).getPaisDestino().toUpperCase())
                            + "    ",
                    fontCorpoN));
            pCl.add(new Phrase("N de Pessoas: ", fontCorpo));
            pCl.add(new Phrase((i + 1) + "", fontCorpoN));
            PdfPCell cellDestino = new PdfPCell(pCl);
            cellDestino.setBorder(0);
            pTableSegu2.addCell(cellDataEmissao);
            pTableSegu2.addCell(cellDestino);

            pCl = new Paragraph();
            pCl.add(new Phrase("Meio de Identificao: ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(
                    ((vb.getInfoPessoaSegurada().get(i).getTipoDoc().toUpperCase().equals("PASSAPORTE"))
                            ? "PASS"
                            : (vb.getInfoPessoaSegurada().get(i).getTipoDoc().toUpperCase()
                                    .equals("BILHETE IDENTIDADE") ? "BI"
                                            : vb.getInfoPessoaSegurada().get(i).getTipoDoc().toUpperCase())),
                    fontCorpoN));
            pCl.add(new Phrase("   N ", fontCorpo));
            pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getNumDoc(), fontCorpoN));
            PdfPCell cellEmiDocNum = new PdfPCell(pCl);
            cellEmiDocNum.setBorder(0);

            pCl = new Paragraph();
            pCl.add(new Phrase("Emitido em: ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getLocalEmissao().toUpperCase() + " ",
                    fontCorpoN));
            pCl.add(new Phrase("em ", fontCorpo));
            pCl.add(new Phrase(vb.getInfoPessoaSegurada().get(i).getDataEmissaoFormatada(), fontCorpoN));
            PdfPCell cellEmiDoc = new PdfPCell(pCl);
            cellEmiDoc.setBorder(0);
            pTableSegu2.addCell(cellEmiDocNum);
            pTableSegu2.addCell(cellEmiDoc);

            pCl = new Paragraph();
            pCl.add(new Phrase("Outras Informaes: ".toUpperCase(), fontCorpo));
            pCl.add(new Phrase(
                    ((vb.getInfoPessoaSegurada().get(i).getOutrasInformacoes() == null) ? " "
                            : vb.getInfoPessoaSegurada().get(i).getOutrasInformacoes().toUpperCase()),
                    fontCorpoN));
            PdfPCell cellOutraInf = new PdfPCell(pCl);
            cellOutraInf.setColspan(2);
            cellOutraInf.setBorder(0);
            pTableSegu2.addCell(cellOutraInf);

            //                PdfPCell cellSegui1 = new PdfPCell();
            //                cellSegui1.addElement(pTableSegu1);
            //                cellSegui1.setBorder(0);
            PdfPCell cellSegui2 = new PdfPCell();
            cellSegui2.addElement(pTableSegu2);
            cellSegui2.setBorder(0);

            //                PdfPCell cellSeguiT = new PdfPCell();
            //                cellSeguiT.addElement(pTableLinha);
            //                cellSeguiT.setBorder(0);
            //                pTablePrincaipal.addCell(cellSegui1);
            pTablePrincaipal.addCell(cellSegui2);

            //                if((i+1)<total&&((i+1)%6)!=0)
            //                    pTablePrincaipal.addCell(cellSeguiT);
            //                
            documento.add(pTablePrincaipal);
            //                
            //                System.err.println((((i+1)%6)==0)+" "+(i+1));
            if ((i + 1) != total) {
                documento.newPage();
            }

        }

        documento.close();
        return reString;

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

From source file:Export.SeguroViatura.java

public String criarDoc(String numApolice, String numCliente, Contrato c, VeiculoBean vb, String user,
        String arquivo) {/*from   w  w  w .ja  v a  2  s .  c o m*/
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss");

        Font fontCabecalhoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 10.5f);
        Font fontCorpo = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoTabT = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 6.5f);
        Font fontCorpoTab = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 6.5f);
        Font fontCorpoP = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f);
        Font fontCorpoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9f);
        Font fontCorpoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.5f);
        Font fontCorpoNGT = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 10f);
        Font fontCabecalhoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f,
                Font.UNDERLINE);
        Font fontUK = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f, Font.ITALIC);
        Font fontUKb = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 6f, Font.ITALIC);

        PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 25f, 75f });
        pTableEmpresaPricipal.setWidthPercentage(88f);
        PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1);
        //            PdfPTable pTableEmpresaInforImpres2 = 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(Empresa.NOME, fontCabecalhoNG));
        pCellNomeEmpresa.setBorder(0);

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

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

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

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

        PdfPCell pCellPolice = new PdfPCell(new Phrase(Empresa.APOLICE + numApolice, fontCabecalhoN));
        pCellPolice.setBorder(0);

        Image imageEmpresa = Image.getInstance("logo.png");
        imageEmpresa.scaleToFit(190f, 100f);

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

        pTableEmpresaInforImpres1.addCell(pCellPolice);

        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.addCell(cellTabela6);
        pTableEmpresaPricipal.addCell(cellTabela5);

        PdfPTable pTableSeguro = new PdfPTable(1);
        pTableSeguro.setWidthPercentage(88f);
        PdfPTable pTableCliente = new PdfPTable(1);
        pTableCliente.setWidthPercentage(88f);

        PdfPTable pTableTitulo = new PdfPTable(1);
        pTableTitulo.setWidthPercentage(88f);

        Paragraph paTitulo = new Paragraph();
        Paragraph pTitulo = new Paragraph("resumo de aplice para Automvel".toUpperCase(), fontCorpoNGT);
        Paragraph pTituloUk = new Paragraph("\nthe motor policy sumay".toUpperCase(), fontUKb);
        paTitulo.add(pTitulo);
        paTitulo.add(pTituloUk);

        PdfPCell cellTitulo = new PdfPCell(paTitulo);
        cellTitulo.setBorder(0);
        cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
        pTableTitulo.addCell(cellTitulo);

        ClienteI ci = new ClienteI(numCliente);
        Paragraph para = new Paragraph();
        Paragraph phrase = new Paragraph("1 - Informaes Do Cliente".toUpperCase(), fontCorpoNG);
        Paragraph paraUK = new Paragraph("\n1 - Customer information".toUpperCase(), fontUKb);

        para.add(phrase);
        para.add(paraUK);

        PdfPCell cellTituloTsbleSegurado = new PdfPCell(para);
        cellTituloTsbleSegurado.setBorder(0);

        Paragraph pCl = new Paragraph();
        pCl.add(new Phrase(ci.getNOMEL_(), fontCorpo));
        pCl.add(new Phrase(ci.getNOME_(), fontCorpoN));
        pCl.add(new Phrase("\nNAME:", fontUK));
        PdfPCell cellNome = new PdfPCell(new Phrase(pCl));
        cellNome.setBorder(0);

        pCl = new Paragraph();
        pCl.add(new Phrase(ci.getENDERECOL_(), fontCorpo));
        pCl.add(new Phrase(ci.getENDERECO_(), fontCorpoN));
        pCl.add(new Phrase("\nADDRESS:", fontUK));
        PdfPCell cellEndereco = new PdfPCell(pCl);
        cellEndereco.setBorder(0);

        /**
        pCl = new Paragraph();
        pCl.add(new Phrase("   " +ci.getNUNCLIENTEL_(),fontCorpo));
        pCl.add(new Phrase(ci.getNUNCLIENTE_(),fontCorpoN));
        PdfPCell cellNCliente = new PdfPCell( pCl );
        cellNCliente.setBorder(0);
        * */

        pCl = new Paragraph();
        pCl.add(new Phrase(ci.getPROFISSAOL_(), fontCorpo));
        pCl.add(new Phrase(ci.getPROFISSAO_(), fontCorpoN));
        pCl.add(new Phrase("\nPROFISSION/OCCUPATION/ACTIVITY AREA:", fontUK));
        PdfPCell cellProfissao = new PdfPCell(pCl);
        cellProfissao.setBorder(0);

        pCl = new Paragraph();
        pCl.add(new Phrase(ci.getLOCALTRABALHOL_(), fontCorpo));
        pCl.add(new Phrase(ci.getLOCALTRABALHO_(), fontCorpoN));
        pCl.add(new Phrase("\nPLACE OF WORK", fontUK));
        PdfPCell cellLocalTrabalho = new PdfPCell(pCl);
        cellLocalTrabalho.setBorder(0);

        cellNome.setPaddingTop(7f);
        cellNome.setPaddingBottom(7f);
        cellNome.setBorder(0);

        cellEndereco.setPaddingTop(7f);
        cellEndereco.setPaddingBottom(7f);
        cellEndereco.setBorder(0);

        //            PdfPCell cellNCliente= new PdfPCell( new Phrase("   "+ci.getNUNCLIENTE(),fontCorpo));cellNome.setPaddingTop(5f);
        //            cellNCliente.setPaddingTop(7f);
        //            cellNCliente.setPaddingBottom(7f);
        //            cellNCliente.setBorder(0);

        cellProfissao.setPaddingTop(7f);
        cellProfissao.setPaddingBottom(7f);
        cellProfissao.setBorder(0);

        cellLocalTrabalho.setPaddingTop(7f);
        cellLocalTrabalho.setPaddingBottom(7f);
        cellLocalTrabalho.setBorder(0);

        pTableCliente.addCell(cellTituloTsbleSegurado);
        pTableCliente.addCell(cellNome);
        pTableCliente.addCell(cellEndereco);
        //            pTableCliente.addCell(cellNCliente);
        pTableCliente.addCell(cellProfissao);
        pTableCliente.addCell(cellLocalTrabalho);

        para = new Paragraph();
        Paragraph p = new Paragraph("3 - Premio E Cobertura".toUpperCase(), fontCorpoNG);
        Paragraph p1 = new Paragraph("\n3 - PREMIUM AND COVER".toUpperCase(), fontUKb);
        para.add(p);
        para.add(p1);

        PdfPCell cellTiltuloSegro = new PdfPCell(para);
        cellTiltuloSegro.setPaddingTop(7f);
        cellTiltuloSegro.setPaddingBottom(7f);
        cellTiltuloSegro.setBorder(0);

        //            PdfPCell cellApolice= new PdfPCell( new Phrase("   N Aplice: ".toUpperCase()+numApolice,fontCorpo));
        //            cellApolice.setPaddingTop(7f);
        //            cellApolice.setPaddingBottom(7f);
        //            cellApolice.setBorder(0);
        Paragraph pTotalSegurado = new Paragraph();
        pTotalSegurado.add(new Phrase("Prmio: ".toUpperCase().toUpperCase(), fontCorpo));
        /**
         * *
         * ildo - premio liquido ->
         */
        pTotalSegurado.add(new Phrase(
                ((c.getPremioLiquidoMoeda() == null /*&& vb.getVeiculo().getTipoCobertura().equals("41") */ )
                        ? " "
                        : c.getPremioLiquidoMoeda() + " " + c.getSigla()),
                fontCorpoN));
        pTotalSegurado.add(new Phrase("\nPREMIUM", fontUK));
        PdfPCell cellTotalSegurado = new PdfPCell(pTotalSegurado);
        cellTotalSegurado.setPaddingTop(7f);
        cellTotalSegurado.setPaddingBottom(7f);
        cellTotalSegurado.setBorder(0);

        Paragraph pExcesso = new Paragraph();
        pExcesso.add(new Phrase("Excesso: ".toUpperCase(), fontCorpo));
        pExcesso.add(new Phrase((c.getFranquia() == null) ? "No aplicvel".toUpperCase() : c.getFranquia(),
                fontCorpoN));
        pExcesso.add(new Phrase("\nEXCESS: ", fontUK));
        PdfPCell cellExcesso = new PdfPCell(pExcesso);
        cellExcesso.setPaddingTop(7f);
        cellExcesso.setPaddingBottom(7f);
        cellExcesso.setBorder(0);

        //            PdfPCell cellValor1Preminio= new PdfPCell( new Phrase("   Valor Primeiro Premio: ".toUpperCase()+((c.getPrimeiroPremio()==null)?" ":c.getPrimeiroPremio()),fontCorpo));
        //            cellValor1Preminio.setPaddingTop(7f);
        //            cellValor1Preminio.setPaddingBottom(7f);
        //            cellValor1Preminio.setBorder(0);
        //            
        //            PdfPCell cellTotalPremioAnual= new PdfPCell( new Phrase("   Valor Premio Anual: ".toUpperCase()+((c.getPremioAnual()==null)?" ":c.getPremioAnual()),fontCorpo));
        //            cellTotalPremioAnual.setPaddingTop(7f);
        //            cellTotalPremioAnual.setPaddingBottom(7f);
        //            cellTotalPremioAnual.setBorder(0);
        //            PdfPCell cellPeriodo= new PdfPCell( new Phrase("   Periodo Do Seguro: ".toUpperCase()+((c.getDataInicio()!= null) ? sdf.format(c.getDataInicio()): " " )+"  "+((c.getDataFim()!= null) ? sdf.format(c.getDataFim()): " " ),fontCorpo));
        //            cellPeriodo.setPaddingTop(7f);
        //            cellPeriodo.setPaddingBottom(7f);
        //            cellPeriodo.setBorder(0)
        Paragraph pDataRenovacao = new Paragraph();
        pDataRenovacao.add(new Phrase("Data Renovao de Seguro: ".toUpperCase(), fontCorpo));
        pDataRenovacao.add(new Phrase(((c.getDataRenovacao() != null) ? sdf.format(c.getDataRenovacao()) : " "),
                fontCorpoN));
        pDataRenovacao.add(new Phrase("\nRENEWAL DATE OF COVER", fontUK));
        PdfPCell cellDataRenovacao = new PdfPCell(pDataRenovacao);
        cellDataRenovacao.setPaddingTop(7f);
        cellDataRenovacao.setPaddingBottom(7f);
        cellDataRenovacao.setBorder(0);

        Paragraph pTipoCobert = new Paragraph();
        pTipoCobert.add(new Phrase("Tipo De Cobertura: ".toUpperCase(), fontCorpo));
        pTipoCobert
                .add(new Phrase(
                        ((vb.getVeiculo().getTipoCobertura() != null)
                                ? (vb.getVeiculo().getTipoCobertura().equals("41")
                                        ? "Contra Terceiros".toUpperCase()
                                        : (vb.getVeiculo().getTipoCobertura().equals("42")
                                                ? "CONTRA Todos os riscos".toUpperCase()
                                                : (vb.getVeiculo().getTipoCobertura().equals("43")
                                                        ? "Compreensivo limitado".toUpperCase()
                                                        : vb.getVeiculo().getTipoCobertura())))
                                : " "),
                        fontCorpoN));
        pTipoCobert.add(new Phrase("\nTYPE OF CAVER", fontUK));
        PdfPCell cellTipoCobert = new PdfPCell(pTipoCobert);
        cellTipoCobert.setPaddingTop(7f);
        cellTipoCobert.setPaddingBottom(7f);
        cellTipoCobert.setBorder(0);

        Paragraph pLimiteArea = new Paragraph();
        pLimiteArea.add(new Phrase("Limite de rea geogrfica: ".toUpperCase(), fontCorpo));
        pLimiteArea.add(new Phrase("so Tom e principe".toUpperCase(), fontCorpoN));
        pLimiteArea.add(new Phrase("\nLIMIT OF GEOGRAPHICAL AREA".toUpperCase(), fontUK));
        PdfPCell cellLimiteArea = new PdfPCell(pLimiteArea);
        cellLimiteArea.setPaddingTop(7f);
        cellLimiteArea.setPaddingBottom(7f);
        cellLimiteArea.setBorder(0);

        Paragraph pLeis = new Paragraph();
        pLeis.add(new Phrase("legislao: ".toUpperCase(), fontCorpo));
        pLeis.add(new Phrase("artigos 1  36, lei n 30/2000 da repblica democrtica de stp".toUpperCase(),
                fontCorpoN));
        pLeis.add(new Phrase("\nLEGISLATION: ", fontUK));
        pLeis.add(new Phrase("ARTICLES 1 TO 36, LAW NO 30/2000 OF THE DEMOCRATIC REPUBLIC OF STP", fontUKb));
        PdfPCell cellLeis = new PdfPCell(pLeis);
        cellLeis.setPaddingTop(7f);
        cellLeis.setPaddingBottom(7f);
        cellLeis.setBorder(0);

        pTableSeguro.addCell(cellTiltuloSegro);
        //            pTableSeguro.addCell(cellApolice);
        pTableSeguro.addCell(cellTotalSegurado);
        //            pTableSeguro.addCell(cellValor1Preminio);
        //            pTableSeguro.addCell(cellTotalPremioAnual);
        pTableSeguro.addCell(cellExcesso);
        pTableSeguro.addCell(cellDataRenovacao);
        pTableSeguro.addCell(cellTipoCobert);
        pTableSeguro.addCell(cellLimiteArea);
        pTableSeguro.addCell(cellLeis);

        PdfPTable pTableDadosTitulo = new PdfPTable(1);
        pTableDadosTitulo.setWidthPercentage(88f);

        para = new Paragraph();
        Phrase PDadosTitulo = new Phrase("2 - Informaes do(s) Veculo(s)".toUpperCase(), fontCorpoN);
        Phrase PDadosTitulos = new Phrase("\n2 - VEHICLE (S) INFORMATIONS".toUpperCase(), fontUKb);
        para.add(PDadosTitulo);
        para.add(PDadosTitulos);
        PdfPCell cellDadosTitulo = new PdfPCell(para);

        cellDadosTitulo.setBorder(0);
        pTableDadosTitulo.addCell(cellDadosTitulo);
        pTableDadosTitulo.addCell(cellNull);

        PdfPTable pTableDados = new PdfPTable(new float[] { 13.5f, 13.5f, 14, 17, 16, 12, 14 });
        pTableDados.setWidthPercentage(88f);

        para = new Paragraph();
        Phrase PMarca = new Phrase("Marca".toUpperCase(), fontCorpoTabT);
        Phrase PMarcaUK = new Phrase("\nMARK".toUpperCase(), fontUK);
        para.add(PMarca);
        para.add(PMarcaUK);

        PdfPCell cellMarca = new PdfPCell(para);
        cellMarca.setPaddingTop(5f);
        cellMarca.setPaddingBottom(5f);
        cellMarca.setHorizontalAlignment(Element.ALIGN_CENTER);

        para = new Paragraph();
        Paragraph PModelo = new Paragraph("Modelo".toUpperCase(), fontCorpoTabT);
        Paragraph PModeloUK = new Paragraph("\nMODEL".toUpperCase(), fontUK);
        para.add(PModelo);
        para.add(PModeloUK);

        PdfPCell cellModelo = new PdfPCell(para);
        cellModelo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellModelo.setPaddingTop(5f);
        cellModelo.setPaddingBottom(5f);

        para = new Paragraph();
        Phrase PMatricula = new Phrase("NO DE MATR?CULA".toUpperCase(), fontCorpoTabT);
        Phrase PMatriculaUK = new Phrase("\nREG. NUMBER".toUpperCase(), fontUK);
        para.add(PMatricula);
        para.add(PMatriculaUK);

        PdfPCell cellMatricula = new PdfPCell(para);
        cellMatricula.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellMatricula.setPaddingTop(5f);
        cellMatricula.setPaddingBottom(5f);

        para = new Paragraph();
        Phrase PChasii = new Phrase("No. de chissi/Motor".toUpperCase(), fontCorpoTabT);
        Phrase PChasiiUK = new Phrase("\nchissiS/ENGINE NO.".toUpperCase(), fontUK);
        para.add(PChasii);
        para.add(PChasiiUK);

        PdfPCell cellChasii = new PdfPCell(para);
        cellChasii.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellChasii.setPaddingTop(5f);
        cellChasii.setPaddingBottom(5f);

        para = new Paragraph();
        Phrase PAnoFabricoCompra = new Phrase("ano de Fabrico/Compra".toUpperCase(), fontCorpoTabT);
        Phrase PAnoFabricoCompraUK = new Phrase("\nYear of Manufacture/PURCHASE".toUpperCase(), fontUK);
        para.add(PAnoFabricoCompra);
        para.add(PAnoFabricoCompraUK);

        PdfPCell cellAnoFabricoCompra = new PdfPCell(para);
        cellAnoFabricoCompra.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellAnoFabricoCompra.setPaddingTop(5f);
        cellAnoFabricoCompra.setPaddingBottom(5f);

        para = new Paragraph();
        Phrase PTotalLuagares = new Phrase("lotao".toUpperCase(), fontCorpoTabT);
        Phrase PTotalLuagaresUK = new Phrase("\nSTOCKING", fontUK);
        para.add(PTotalLuagares);
        para.add(PTotalLuagaresUK);

        PdfPCell cellTotalLuagares = new PdfPCell(para);
        cellTotalLuagares.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTotalLuagares.setPaddingTop(5f);
        cellTotalLuagares.setPaddingBottom(5f);

        para = new Paragraph();
        Phrase PDadosValorSeguro = new Phrase("Estimativa / Valor Segurado".toUpperCase(), fontCorpoTabT);
        Phrase PDadosValorSeguroUK = new Phrase("\nEstimation / Amount Insured".toUpperCase(), fontUK);
        para.add(PDadosValorSeguro);
        para.add(PDadosValorSeguroUK);

        PdfPCell cellDadosValorSeguro = new PdfPCell(para);
        cellDadosValorSeguro.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellDadosValorSeguro.setPaddingTop(5f);
        cellDadosValorSeguro.setPaddingBottom(5f);

        pTableDados.addCell(cellMarca);
        pTableDados.addCell(cellModelo);
        pTableDados.addCell(cellMatricula);
        pTableDados.addCell(cellChasii);
        pTableDados.addCell(cellAnoFabricoCompra);
        pTableDados.addCell(cellTotalLuagares);
        pTableDados.addCell(cellDadosValorSeguro);

        int total = vb.getInfo().size();
        for (int i = 0; i < total; i++) {
            cellMarca = new PdfPCell(
                    new Phrase((vb.getInfo().get(i).getMarca() == null) ? " " : vb.getInfo().get(i).getMarca(),
                            fontCorpoTab));
            cellMarca.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellModelo = new PdfPCell(new Phrase(
                    (vb.getInfo().get(i).getModelo() == null) ? " " : vb.getInfo().get(i).getModelo(),
                    fontCorpoTab));
            cellModelo.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellMatricula = new PdfPCell(
                    new Phrase(((vb.getInfo().get(i).getNumeroMatricula() == null) ? ".........."
                            : vb.getInfo().get(i).getNumeroMatricula()), fontCorpoTab));
            cellMatricula.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellDadosValorSeguro = new PdfPCell(new Phrase(
                    ((vb.getInfo().get(i).getValorAtual() == null
                            || vb.getInfo().get(i).getValorAtual().isEmpty()
                            || vb.getVeiculo().getTipoCobertura().equals("41")) ? " NA "
                                    : Moeda.format(Double.valueOf(vb.getInfo().get(i).getValorAtual()))),
                    fontCorpoTab));
            cellDadosValorSeguro.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellAnoFabricoCompra = new PdfPCell(new Phrase(((vb.getInfo().get(i).getAnoFabrico() == null
                    || (vb.getInfo().get(i).getAnoFabrico().isEmpty())) ? "......."
                            : vb.getInfo().get(i).getAnoFabrico())
                    + "/"
                    + ((vb.getInfo().get(i).getAnoCompra() == null
                            || (vb.getInfo().get(i).getAnoCompra().isEmpty())) ? "......."
                                    : vb.getInfo().get(i).getAnoCompra()),
                    fontCorpoTab));
            cellAnoFabricoCompra.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellTotalLuagares = new PdfPCell(
                    new Phrase(vb.getInfo().get(i).getCapacidade() + " LUGARES", fontCorpoTab));
            cellTotalLuagares.setHorizontalAlignment(Element.ALIGN_CENTER);
            cellChasii = new PdfPCell(new Phrase(vb.getInfo().get(i).getChassi() + " ", fontCorpoTab));
            cellChasii.setHorizontalAlignment(Element.ALIGN_CENTER);

            float pad = getPadding(total);

            cellMarca.setPaddingTop(pad);
            cellMarca.setPaddingBottom(pad);
            pTableDados.addCell(cellMarca);

            cellModelo.setPaddingTop(pad);
            cellModelo.setPaddingBottom(pad);
            pTableDados.addCell(cellModelo);

            cellMatricula.setPaddingTop(pad);
            cellMatricula.setPaddingBottom(pad);
            pTableDados.addCell(cellMatricula);

            cellChasii.setPaddingTop(pad);
            cellChasii.setPaddingBottom(pad);
            pTableDados.addCell(cellChasii);

            cellAnoFabricoCompra.setPaddingTop(pad);
            cellAnoFabricoCompra.setPaddingBottom(pad);
            pTableDados.addCell(cellAnoFabricoCompra);

            cellTotalLuagares.setPaddingTop(pad);
            cellTotalLuagares.setPaddingBottom(pad);
            pTableDados.addCell(cellTotalLuagares);

            cellDadosValorSeguro.setPaddingTop(pad);
            cellDadosValorSeguro.setPaddingBottom(pad);
            pTableDados.addCell(cellDadosValorSeguro);
        }

        //            PdfPTable pTableAssinaturaTitulo= new PdfPTable(1);
        //            pTableAssinaturaTitulo.setWidthPercentage(88f);
        //            PdfPTable pTableAssinatura= new PdfPTable( new float[]{50f,50f});
        //            pTableAssinatura.setWidthPercentage(88f);
        //            PdfPCell cellAssinatora= new PdfPCell(new Phrase("Assinaturas".toUpperCase(),fontCorpoN));
        //            cellAssinatora.setBorder(0);
        //            cellAssinatora.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            PdfPCell celllinha1= new PdfPCell(new Phrase("____________________________________________".toUpperCase(),fontCorpo));
        //            celllinha1.setBorder(0);
        //            celllinha1.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            PdfPCell celllinha2= new PdfPCell(new Phrase("____________________________________________".toUpperCase(),fontCorpo));
        //            celllinha2.setBorder(0);
        //            celllinha2.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            PdfPCell celllinha11= new PdfPCell(new Phrase("para nicon Seguro sa stp".toUpperCase(),fontCorpoP));
        //            celllinha11.setBorder(0);
        //            celllinha11.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            PdfPCell celllinha21= new PdfPCell(new Phrase("o segurado ".toUpperCase(),fontCorpoP));
        //            celllinha21.setBorder(0);
        //            celllinha21.setHorizontalAlignment(Element.ALIGN_CENTER);
        //            pTableAssinaturaTitulo.addCell(cellAssinatora);
        //            pTableAssinatura.addCell(celllinha1);
        //            pTableAssinatura.addCell(celllinha2);
        //            pTableAssinatura.addCell(celllinha11);
        //            pTableAssinatura.addCell(celllinha21);
        Document documento = new Document();
        documento.setPageSize(PageSize.A4);
        documento.setMargins(20f, 20f, 35f, 5f);

        //            File ff= new File("Documentos\\"+user+"\\Seguro Automovel\\");
        //            ff.mkdirs();
        //            ff =new File(ff.getAbsoluteFile()+"\\"+"Formulario Seguro Automovel "+sdf1.format(new Date())+".pdf");
        File ff = new File(arquivo + "/" + user + "/Seguro Automovel/");

        ff.mkdirs();
        String Ddata = sdf1.format(new Date());
        ff = new File(ff.getAbsoluteFile() + "/" + "Formulario Seguro Automovel " + Ddata + ".pdf");

        reString = "../Documentos/" + user + "/Seguro Automovel/" + "Formulario Seguro Automovel " + Ddata
                + ".pdf";

        OutputStream outputStraem = new FileOutputStream(ff);
        PdfWriter writer = PdfWriter.getInstance(documento, outputStraem);

        if (MarcaDAgua.isSimulation) {
            MarcaDAgua.SimulacaoVertical v = new MarcaDAgua.SimulacaoVertical();
            writer.setPageEvent(v);
        }

        if (MarcaDAgua.isCanceled) {
            MarcaDAgua.AnulacaoVertical v = new MarcaDAgua.AnulacaoVertical();
            writer.setPageEvent(v);
        }

        PdfPTable pTableLinha = new PdfPTable(1);
        pTableLinha.setWidthPercentage(88f);
        PdfPCell cellLinha = new PdfPCell(new Phrase(
                "----------------------------------------------------------------------------------------------------------------------",
                fontCorpo));
        cellLinha.setBorder(0);
        pTableLinha.addCell(cellLinha);
        cellLinha.setPaddingTop(-9f);
        pTableLinha.addCell(cellLinha);

        PdfPTable pTableApoliceAndPeriodo = new PdfPTable(new float[] { 40, 60 });
        pTableApoliceAndPeriodo.setWidthPercentage(88f);

        Paragraph pApolice = new Paragraph();
        pApolice.add(new Phrase("N Aplice: ".toUpperCase(), fontCorpo));
        pApolice.add(new Phrase(numApolice, fontCorpoN));
        pApolice.add(new Phrase("\nPOLICY NO:", fontUK));
        PdfPCell cellApolice = new PdfPCell(pApolice);
        //            cellApolice.setPaddingTop(-2);
        //            cellApolice.setPaddingBottom(4.5f);
        cellApolice.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableApoliceAndPeriodo.addCell(cellApolice);

        Paragraph pPeriodo = new Paragraph();
        pPeriodo.add(new Phrase("Periodo Do Seguro: ".toUpperCase(), fontCorpo));
        pPeriodo.add(new Phrase(((c.getDataInicio() != null) ? sdf.format(c.getDataInicio()) : " ") + "  "
                + ((c.getDataFim() != null) ? sdf.format(c.getDataFim()) : " "), fontCorpoN));
        pPeriodo.add(new Phrase("\nPERIOD OF INSURANCE:", fontUK));
        PdfPCell cellPeriodo = new PdfPCell(pPeriodo);
        //            cellPeriodo.setPaddingTop(-2);
        //            cellPeriodo.setPaddingBottom(4.5f);
        cellPeriodo.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        pTableApoliceAndPeriodo.addCell(cellPeriodo);

        documento.open();
        documento.add(pTableEmpresaPricipal);
        documento.add(pTableNull);
        documento.add(pTableTitulo);
        documento.add(pTableNull);
        documento.add(pTableApoliceAndPeriodo);
        documento.add(pTableNull);
        documento.add(pTableCliente);
        documento.add(pTableNull);
        documento.add(pTableLinha);
        documento.add(pTableNull);
        documento.add(pTableDadosTitulo);
        documento.add(pTableDados);
        documento.add(pTableNull);
        documento.add(pTableLinha);
        documento.add(pTableNull);
        documento.add(pTableSeguro);
        //            documento.add(pTableNull);
        //            documento.add(pTableAssinaturaTitulo);
        //            documento.add(pTableNull);
        //            documento.add(pTableNull);
        //            documento.add(pTableAssinatura);
        documento.close();

        //           PrintPdf printPdf = new PrintPdf(ff.getAbsolutePath(), ff.getAbsolutePath(), 0, 595f,842f,"Enviar Para o OneNote 2013",1); 
        //           //PrintPdf printPdf = new PrintPdf(ff.getAbsolutePath(), ff.getAbsolutePath(), 0, 595f,842f,"Hewlett-Packard HP LaserJet P2035",1); 
        //             
        //            printPdf.print();
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(SeguroAPG.class.getName()).log(Level.SEVERE, null, ex);
    } catch (DocumentException ex) {
        Logger.getLogger(SeguroAPG.class.getName()).log(Level.SEVERE, null, ex);
    }
    return reString;
}

From source file:eyeofthetiger.utils.PDFDossardGenerator.java

public void createPdf(List<Participant> participants, OutputStream out) throws IOException, DocumentException {
    sortParticipants(participants);/*from   w  ww. ja v a 2 s .c om*/

    Document document = new Document(PageSize.A4.rotate());
    float margin = CentimeterToUserSpace(marginCm);
    document.setMargins(margin, margin, margin, margin);
    PdfWriter writer = PdfWriter.getInstance(document, out);
    document.open();
    PdfContentByte cb = writer.getDirectContent();

    PdfReader pdfBackgroundReader = null;
    PdfImportedPage backgroundPage = null;
    if (pdfBackground != null && (new File(pdfBackground)).exists() && (new File(pdfBackground)).isFile()) {
        pdfBackgroundReader = new PdfReader(pdfBackground);
        backgroundPage = writer.getImportedPage(pdfBackgroundReader, 1);
    }

    float documentTop = document.top();
    float documentBottom = document.bottom();
    float documentHeight = documentTop - documentBottom;
    float left = document.left();
    float right = document.right();
    float width = right - left;
    float height = documentTop - documentBottom;

    //cb.rectangle(left, documentBottom, width, documentHeight);
    //cb.stroke();

    boolean logoLeftExist = (new File(logoLeft)).exists() && (new File(logoLeft)).isFile();
    boolean logoRightExist = (new File(logoRight)).exists() && (new File(logoRight)).isFile();

    float imgLeftRight = left;
    float imgLeftBottom = documentTop;
    float imgRightLeft = right;
    float imgRighBottom = documentTop;
    Image imgLeft = null;
    Image imgRight = null;
    if (exportLogos) {
        if (logoLeftExist) {
            imgLeft = Image.getInstance(logoLeft);
            float h = imgLeft.getHeight();
            float w = imgLeft.getWidth();
            float nw = width * logoLeftWidth;
            float nh = (h / w) * nw;
            imgLeft.scaleAbsolute(nw, nh);
            //img.scaleAbsoluteHeight(img.getScaledWidth() / xyRatio);
            imgLeft.setAbsolutePosition(left, documentTop - imgLeft.getScaledHeight());
            //cb.addImage(img);   

            imgLeftRight = imgLeft.getAbsoluteX() + imgLeft.getScaledWidth();
            imgLeftBottom = imgLeft.getAbsoluteY();
        }

        if (logoRightExist) {
            imgRight = Image.getInstance(logoRight);
            float h = imgRight.getHeight();
            float w = imgRight.getWidth();
            float nw = width * logoRightWidth;
            float nh = (h / w) * nw;
            imgRight.scaleAbsolute(nw, nh);
            imgRight.setAbsolutePosition(right - imgRight.getScaledWidth(),
                    documentTop - imgRight.getScaledHeight());
            //cb.addImage(imgRight);
            imgRightLeft = imgRight.getAbsoluteX();
            imgRighBottom = imgRight.getAbsoluteY();
        }

    }

    float nameHeightPercent = 0.35f;
    float groupHeightPercent = 0.25f;

    float nameTop = documentTop;
    float nameBottom = nameTop;
    if (exportName) {
        nameBottom = nameTop - (documentHeight * nameHeightPercent);
    }
    float groupeTop = nameBottom;
    float groupeBottom = nameBottom;
    if (exportGroup) {
        groupeBottom = groupeTop - (documentHeight * groupHeightPercent);
    }
    float barcodeTop = groupeBottom;
    float barcodeBottom = documentBottom;

    ColumnText columnText;

    for (Participant participant : participants) {

        if (backgroundPage != null) {
            //cb.addTemplate(backgroundPage, 1f, 0, 0, 1, 0, 0); //TODO
            cb.addTemplate(backgroundPage, 0, 0);
        }

        float nameFontSize = 65f;
        float groupFontSize = 45f;
        float renseignementFontSize = 35f;

        if (imgLeft != null) {
            cb.addImage(imgLeft);
        }
        if (imgRight != null) {
            cb.addImage(imgRight);
        }

        if (exportName) {
            columnText = new ColumnText(cb);
            columnText.setAlignment(Rectangle.ALIGN_CENTER);

            if (imgLeftRight != -1 && imgLeftBottom != -1) {
                float[] leftBorder = null;
                if (imgLeftBottom < nameBottom) {
                    leftBorder = new float[] { imgLeftRight, nameTop, imgLeftRight, nameBottom, left,
                            nameBottom };
                } else {
                    leftBorder = new float[] { imgLeftRight, nameTop, imgLeftRight, imgLeftBottom, left,
                            imgLeftBottom, left, nameBottom };
                }

                float[] rightBorder = null;
                if (imgRighBottom < nameBottom) {
                    rightBorder = new float[] { imgRightLeft, nameTop, imgRightLeft, nameBottom, right,
                            nameBottom };
                } else {
                    rightBorder = new float[] { imgRightLeft, nameTop, imgRightLeft, imgRighBottom, right,
                            imgRighBottom, right, nameBottom };
                }

                columnText.setColumns(leftBorder, rightBorder);
            } else {
                columnText.setSimpleColumn(left, nameTop, right, nameBottom);
            }
            //cb.rectangle(left, nameBottom, width, (nameTop - nameBottom));
            //cb.stroke();

            columnText.setExtraParagraphSpace(0f);
            columnText.setAdjustFirstLine(false);
            columnText.setIndent(0);

            String txt = participant.getNom().toUpperCase() + " " + participant.getPrenom();

            float previousPos = columnText.getYLine();
            columnText.setLeading(nameFontSize);
            columnText.setText(createCleanPhrase(txt, nameFontSize, true));
            while (nameFontSize > 1 && ColumnText.hasMoreText(columnText.go(true))) {
                nameFontSize = nameFontSize - 0.5f;
                columnText.setLeading(nameFontSize);
                columnText.setText(createCleanPhrase(txt, nameFontSize, true));
                columnText.setYLine(previousPos);
            }

            columnText.setLeading(nameFontSize);
            columnText.setText(createCleanPhrase(txt, nameFontSize, true));
            columnText.setYLine(previousPos);
            columnText.go(false);

        }

        if (exportGroup) {
            columnText = new ColumnText(cb);
            columnText.setAlignment(Rectangle.ALIGN_CENTER);

            columnText.setSimpleColumn(document.left(), groupeTop, document.right(), groupeBottom);
            float groupeHeight = groupeTop - groupeBottom;
            //cb.rectangle(document.left(), groupeTop - groupeHeight, document.right() - document.left(), groupeHeight);
            //cb.stroke();

            columnText.setExtraParagraphSpace(0f);
            columnText.setAdjustFirstLine(false);
            columnText.setIndent(0);
            columnText.setFollowingIndent(0);

            String txt1 = participant.getGroupe();
            String txt2 = exportRenseignement ? "\n" + participant.getRenseignements() : null;

            float previousPos = columnText.getYLine();
            columnText.setText(null);
            columnText.setLeading(groupFontSize);
            columnText.addText(createCleanPhrase(txt1, groupFontSize, true));
            columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false));
            while (groupFontSize > 1 && ColumnText.hasMoreText(columnText.go(true))) {
                groupFontSize = groupFontSize - 0.5f;
                renseignementFontSize = renseignementFontSize - 0.5f;
                columnText.setText(null);
                columnText.setLeading(groupFontSize);
                columnText.addText(createCleanPhrase(txt1, groupFontSize, true));
                columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false));
                columnText.setYLine(previousPos);
            }

            columnText.setText(null);
            columnText.setLeading(groupFontSize);
            columnText.addText(createCleanPhrase(txt1, groupFontSize, true));
            columnText.addText(createCleanPhrase(txt2, renseignementFontSize, false));
            columnText.setYLine(previousPos);
            columnText.go(false);
        }

        {
            columnText = new ColumnText(cb);

            float topMargin = 12f;
            columnText.setSimpleColumn(left, barcodeTop - topMargin, right, barcodeBottom);
            float barcodeHeight = (barcodeTop - topMargin) - barcodeBottom;
            //cb.rectangle(left, barcodeTop - barcodeHeight, width, barcodeHeight);
            //cb.stroke();

            columnText.setExtraParagraphSpace(0f);
            columnText.setAdjustFirstLine(false);
            columnText.setIndent(0);

            float previousPos = columnText.getYLine();
            columnText.setText(null);
            columnText.addElement(createCleanBarcode(cb, participant.getNumero(), width, barcodeHeight));
            columnText.go(false);
        }

        document.newPage();

    }

    document.close();

    if (pdfBackgroundReader != null) {
        pdfBackgroundReader.close();
    }
}

From source file:facturacion.pdf.FacturaPdf.java

private Document getDocument() {
    Document document = new Document(new Rectangle(getConvertCmsToPoints(26), getConvertCmsToPoints(30)));
    document.setMargins(0, 0, 80, 1);
    return document;
}

From source file:fll.util.PdfUtils.java

License:Open Source License

/**
 * Common code for document creation. Sets margins and page event handler.
 * This method opens the document./*from w  ww. java2s. c om*/
 * 
 * @throws DocumentException
 */
private static void commonPdfDocCreate(final OutputStream out, final PdfPageEvent pageHandler,
        final Document pdfDoc) throws DocumentException {
    final PdfWriter writer = PdfWriter.getInstance(pdfDoc, out);
    writer.setPageEvent(pageHandler);

    // Measurements are always in points (72 per inch) - This sets up 1/2 inch
    // margins
    pdfDoc.setMargins(0.5f * 72, 0.5f * 72, 0.5f * 72, 0.5f * 72);

    pdfDoc.open();
}

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;
    if (orientationIsPortrait) {
        pdfDoc = new Document(PageSize.LETTER); // portrait
    } else {//from  w w w  .  j a  va2  s  .c o m
        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:Funciones.PedidoPDF.java

public PedidoPDF(String id, java.awt.Image imagen, String directorio)
        throws FileNotFoundException, DocumentException, IOException {
    this.idpedido = id;
    this.directorio = directorio;
    this.archivo = new File(directorio);
    Document documento = new Document(PageSize.A6);
    FileOutputStream ficheroPdf = new FileOutputStream(archivo);
    PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);
    documento.setMargins(0, 0, 1, 0);
    documento.open();/*from  www. java  2  s. com*/
    int width = imagen.getWidth(null);
    int height = imagen.getHeight(null);
    int type = BufferedImage.TYPE_3BYTE_BGR;
    BufferedImage bi = new BufferedImage(width, height, type);
    Graphics2D g2d = bi.createGraphics();
    g2d.drawImage(imagen, 0, 0, null);
    g2d.dispose();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(bi, "png", baos);
    baos.flush();
    byte[] imageInByte = baos.toByteArray();
    baos.close();
    Image image = Image.getInstance(imageInByte);
    PdfPTable tablaimagen = new PdfPTable(1);
    tablaimagen.setWidths(new int[] { 350 });
    tablaimagen.addCell(image);
    documento.add(tablaimagen);
    documento.close();
    ejecutarPDF();
}

From source file:Funciones.TicketPDF.java

public TicketPDF(String id, int idcliente, String directorio)
        throws FileNotFoundException, DocumentException, IOException {
    try {//w w w .  j a  v a2 s .c o m
        this.directorio = directorio;
        String nombrecliente = "";
        this.idpedido = id;
        this.cliente = llenarVector(
                "SELECT nombre,direccion,telefono FROM clientes WHERE idclientes='" + idcliente + "';");
        //TODO 
        ResultSet consultanumdetalle = bd
                .consultar("SELECT cantidad FROM pedidos WHERE idpedidos='" + id + "'");
        while (consultanumdetalle.next()) {
            this.cantidadlineas = consultanumdetalle.getInt("cantidad");
        }
        ResultSet consultadetalle1 = bd.consultar(
                "SELECT P.nombre FROM pizzas P, detalleventas D WHERE D.pizzas_idpizzas=P.idpizzas AND D.pedidos_idpedidos='"
                        + id + "'");
        lineas = new String[cantidadlineas][2];
        String[] linea1 = new String[cantidadlineas];
        String[] linea2 = new String[cantidadlineas];
        int z = 0;
        while (consultadetalle1.next()) {
            linea1[z] = consultadetalle1.getString(1);
            z++;
        }
        ResultSet consultadetalle2 = bd.consultar(
                "SELECT P.precio FROM pizzas P, detalleventas D WHERE D.pizzas_idpizzas=P.idpizzas AND D.pedidos_idpedidos='"
                        + id + "'");
        z = 0;
        while (consultadetalle2.next()) {
            linea2[z] = consultadetalle2.getString(1);
            z++;
        }
        System.out.println(cantidadlineas);
        for (int a = 0; a < linea1.length; a++) {
            System.out.println(a);
            System.out.println(linea1[a]);
            System.out.println(linea2[a]);
            lineas[a][0] = linea1[a];
            lineas[a][1] = linea2[a];
            System.out.println(lineas[a][0] + " " + lineas[a][1]);
        }
        this.totales = llenarVector(
                "SELECT total,iva,totalneto FROM pedidos WHERE idpedidos='" + idpedido + "';");
        this.archivo = new File(directorio);
        Document documento = new Document(PageSize.A6);
        FileOutputStream ficheroPdf = new FileOutputStream(archivo);
        PdfWriter.getInstance(documento, ficheroPdf).setInitialLeading(20);
        documento.setMargins(0, 0, 1, 0);
        documento.open();
        documento.add(tablaHeader());
        documento.add(tablaCliente());
        documento.add(tablaLineas());
        documento.add(tablaFooter());
        documento.close();
        FileInputStream pdf = new FileInputStream(archivo);
        int len = (int) archivo.length();
        String query = ("UPDATE pedidos SET ticket=? WHERE idpedidos='" + idpedido + "';");
        BasededatosManager bd = new BasededatosManager();
        PreparedStatement pstmt = bd.getConexion("chulospizza").prepareStatement(query);
        //method to insert a stream of bytes
        pstmt.setBinaryStream(1, pdf);
        pstmt.executeUpdate();
        ejecutarPDF();
    } catch (SQLException ex) {
        Logger.getLogger(PedidoPDF.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:fxml.test.PDFService.java

public void generatePdf() {
    //   Document document = new Document(PageSize.A4.rotate());
    Document document = new Document(new Rectangle(1008, 612));

    try {/* w  ww. j  a v  a 2  s.  c o  m*/
        PdfWriter.getInstance(document, new FileOutputStream("table.pdf"));

        document.setMargins(90, 80, 35, 40);
        document.open();

        if (!list.isEmpty()) {

            list.add("Total Credit");
            list.add("Total GPA");
            list.add("Letter Grade");
            list.add("Cumulative");
            list.add("Remarks");
            list.add("GC");

            if (inputs.get(1).contains("8th")) {

                list.add("PC. No");
                list.add("OC. No");
                list.add("D/AF. No");
                list.add("Others");
            }

            int totalCoureseSize = list.size();
            int totalCourseLoop = totalCoureseSize / 12;
            int courseLoopVariable = 0;

            if (totalCoureseSize % 12 > 0) {
                totalCourseLoop += 1;
            }

            int totalStudentSize = studentList.size();
            int totalStudentLoop = (totalStudentSize / 15);
            int studentLoopVariable = 0;

            if (totalStudentSize % 15 > 0) {
                totalStudentLoop += 1;
            }

            if (totalStudentLoop > 0) {

                for (studentLoopVariable = 0; studentLoopVariable < totalStudentLoop; studentLoopVariable++) {

                    //start print the courses when it is multiple of 12
                    if (totalCourseLoop > 0) {

                        for (courseLoopVariable = 0; courseLoopVariable < totalCourseLoop; courseLoopVariable++) {

                            int courseStart = courseLoopVariable * 12;
                            int studentStart = studentLoopVariable * 15;

                            //start document header
                            document.add(createDocumentHeader());
                            //end document header

                            //start table header
                            PdfPTable table = createTableHeader(courseStart);
                            //end table header

                            //start table body
                            table = createTableBody(studentStart, courseStart, table);
                            //end table body

                            //adding table and footer
                            table.setSpacingAfter(27);
                            document.add(table);
                            document.add(createFooter1());
                            document.add(createFooter2());
                            //end adding table and footer
                            //go to new page..
                            document.newPage();
                        }
                    }
                }
            }
        }

        document.close();

    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        AlertMessage.showAlertMessage(Alert.AlertType.ERROR, "Error creating Pdf document.Please try again");
        e.printStackTrace();
    }
}

From source file:generators.InvoiceGenerator.java

/**
 * Generate Invoice pdf file/* w w  w . j  a v  a2 s.c  o  m*/
 *
 * @param order the order
 * @throws DocumentException the document exception
 * @throws IOException       the io exception
 */
public void generate(Order order) throws DocumentException, IOException {
    Date invoiceDate = order.getDate();
    SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM YYYY");
    //        User guest = order.getGuest();
    User guest = new UserDAO().get(order.getUserId());
    guest.setOrder(order);
    System.out.println("invoice generator orderID: " + order.getId());
    Document document = new Document();
    Font defaultFont = new Font(Font.FontFamily.TIMES_ROMAN, 12);
    System.out.println(System.getProperty("user.dir"));
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(System.getProperty("user.dir") + "/src/main/java/nl/ipsen3/invoice/"
                    + new SimpleDateFormat("dd-MM-yyyy").format(invoiceDate) + " - " + order.getId() + ".pdf"));
    document.setMargins(30, 30, 30, 65);
    writer.setPageEvent(new InvoiceEventListener());
    document.open();
    Paragraph header = new Paragraph("Lionsclub Oegstgeest/Warmond",
            new Font(Font.FontFamily.TIMES_ROMAN, 14, Font.BOLD));
    header.setAlignment(Element.ALIGN_CENTER);
    document.add(header);
    AddressDAO addressDAO = new AddressDAO();
    Address userAddress = addressDAO.get(guest.getAddressId());
    Paragraph address = new Paragraph(guest.getFirstName() + " " + guest.getPrefixLastName() + " "
            + guest.getLastName() + "\n" + userAddress.getStreet() + " " + userAddress.getHouseNumber() + "\n"
            + userAddress.getZipCode() + " " + userAddress.getCity(), defaultFont);
    address.setSpacingBefore(35);
    address.setSpacingAfter(25);
    address.setLeading(15);
    document.add(address);

    Paragraph invoiceDetails = new Paragraph("Factuurdatum: " + sdf.format(invoiceDate) + "\n"
            + "FactuurNummer: " + order.getId() + " \n" + "Debiteurennummer: " + guest.getId(), defaultFont);

    invoiceDetails.setSpacingAfter(15);
    invoiceDetails.setLeading(15);
    document.add(invoiceDetails);

    Paragraph subject = new Paragraph("Betreft: Onderwerp factuur", defaultFont);
    subject.setSpacingAfter(30);
    document.add(subject);

    PdfPTable orderTable = new PdfPTable(10);
    PdfPCell wineCell = new PdfPCell(new Paragraph("Wijn", defaultFont));
    wineCell.setColspan(5);
    wineCell.setBorder(Rectangle.BOTTOM);
    orderTable.getDefaultCell().setPaddingBottom(10);
    orderTable.getDefaultCell().setBorder(Rectangle.BOTTOM);
    ;

    orderTable.addCell(new Paragraph("Code", defaultFont));
    orderTable.addCell(new Paragraph("Aantal", defaultFont));
    orderTable.addCell(wineCell);
    orderTable.addCell(new Paragraph("Jaar", defaultFont));
    orderTable.addCell(new Paragraph("Per Fles", defaultFont));
    orderTable.addCell(new Paragraph("Bedrag", defaultFont));

    orderTable.getDefaultCell().setPaddingBottom(0);
    orderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    wineCell.setBorder(Rectangle.NO_BORDER);

    NumberFormat numberFormat = NumberFormat.getCurrencyInstance(Locale.GERMANY);

    for (WineOrder wineOrder : order.getWineOrders()) {
        orderTable.addCell(new Paragraph("" + wineOrder.getWine().getId(), defaultFont));
        orderTable.addCell(new Paragraph("" + wineOrder.getAmount(), defaultFont));
        wineCell.setPhrase(new Phrase(wineOrder.getWine().getName(), defaultFont));
        orderTable.addCell(wineCell);
        orderTable.addCell(new Paragraph("" + wineOrder.getWine().getYear(), defaultFont));
        orderTable.addCell(new Paragraph(
                " " + numberFormat.format(wineOrder.getWine().getPrice()).replace(" ", ""), defaultFont));
        orderTable.addCell(new Paragraph(" " + numberFormat
                .format(wineOrder.getAmount() * wineOrder.getWine().getPrice()).replace(" ", ""),
                defaultFont));

        orderTable.completeRow();
    }

    orderTable.addCell(" ");
    orderTable.completeRow();
    Font totalFont = new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD);
    PdfPCell totalAmount = new PdfPCell(
            new Paragraph(" " + numberFormat.format(order.getTotalAmount()).replace(" ", ""), totalFont));
    totalAmount.setBorder(Rectangle.TOP);
    totalAmount.setPaddingTop(10);
    PdfPCell totalCell = new PdfPCell(new Paragraph("Totaal", totalFont));
    totalCell.setPaddingTop(10);
    totalCell.setBorder(Rectangle.NO_BORDER);
    orderTable.addCell(totalCell);
    PdfPCell fillerCell = new PdfPCell(new Paragraph(""));
    fillerCell.setColspan(8);
    fillerCell.setBorder(Rectangle.NO_BORDER);
    orderTable.addCell(fillerCell);
    orderTable.addCell(totalAmount);

    orderTable.setSpacingBefore(15);
    orderTable.setSpacingAfter(30);
    orderTable.setWidthPercentage(95);
    orderTable.setHorizontalAlignment(Element.ALIGN_CENTER);
    document.add(orderTable);

    Paragraph retrievalDetails = new Paragraph(
            "Wij verzoeken u vriendelijk het totaalbedrag binnen 7 dagen na factuurdatum over te maken op bankrekening <bankAccountNr> t.n.v <bankAccountName> onder vermelding van het factuurnummer",
            defaultFont);
    retrievalDetails.setLeading(15);
    retrievalDetails.setSpacingAfter(20);
    document.add(retrievalDetails);

    //        document.add(new Paragraph("U kunt uw wijnen ophalen op " +  sdf.format(invoiceDate) , defaultFont));
    //        document.add(new Paragraph("Adres:", defaultFont));
    //
    //        PdfPTable addressTable = new PdfPTable(1);
    //        addressTable.setSpacingBefore(5);
    //        addressTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
    //        addressTable.getDefaultCell().setPaddingLeft(35);
    //        MerchantService merchantService = new MerchantService();
    //        Merchant merchant = merchantService.find(merchantService.all().get(0).getId());
    //        addressTable.addCell(new Paragraph(merchant.getName(), defaultFont));
    //        addressTable.addCell(new Paragraph(merchant.getAddress().getStreet()
    //                + " " + merchant.getAddress().getHouseNumber(), defaultFont));
    //        addressTable.addCell(new Paragraph(merchant.getAddress().getZipCode() + " " +
    //                merchant.getAddress().getCity(), defaultFont));
    //        addressTable.setHorizontalAlignment(Element.ALIGN_LEFT);
    //        document.add(addressTable);

    document.close();
    System.out.println(
            "Succesfully generated IPSEN2.invoice: " + order.getId() + " on Date: " + sdf.format(invoiceDate));
}