Example usage for com.itextpdf.text Element ALIGN_BOTTOM

List of usage examples for com.itextpdf.text Element ALIGN_BOTTOM

Introduction

In this page you can find the example usage for com.itextpdf.text Element ALIGN_BOTTOM.

Prototype

int ALIGN_BOTTOM

To view the source code for com.itextpdf.text Element ALIGN_BOTTOM.

Click Source Link

Document

A possible value for vertical alignment.

Usage

From source file:com.asae.controllers.BeanGestionRutinas.java

public void generarPdf() {
    Document document = new Document();
    try {/*from   w w w  .j  a v  a2s .c  o m*/
        File file = File.createTempFile("rutina-", ".pdf", new File("/var/webapp/pdf"));
        pdfFileName = file.getName();

        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        document.open();
        Font bold = new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD);
        URL url = FacesContext.getCurrentInstance().getExternalContext()
                .getResource("/resources/img/logo-unicauca-negro.png");
        Image imgLogoUnicauca = Image.getInstance(url);
        imgLogoUnicauca.scaleAbsolute(118f, 131f);

        PdfPTable tableEncabezado = new PdfPTable(2);
        tableEncabezado.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableEncabezado.setWidthPercentage(100);
        tableEncabezado.setSpacingAfter(5);
        PdfPCell cell1 = new PdfPCell(imgLogoUnicauca);
        cell1.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell2 = new PdfPCell(new Paragraph("Vicerrectoria Administrativa"));
        cell2.setBorder(Rectangle.NO_BORDER);
        cell2.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cell2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        PdfPCell cell3 = new PdfPCell(new Paragraph("Universidad del Cauca", bold));
        cell3.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell4 = new PdfPCell(new Paragraph("Gimnasio y Actividad Fsica", bold));
        cell4.setBorder(Rectangle.NO_BORDER);
        cell4.setHorizontalAlignment(Element.ALIGN_RIGHT);
        tableEncabezado.addCell(cell1);
        tableEncabezado.addCell(cell2);
        tableEncabezado.addCell(cell3);
        tableEncabezado.addCell(cell4);

        PdfPTable tableDatosUsuario = new PdfPTable(3);
        tableDatosUsuario.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableDatosUsuario.setWidthPercentage(100);
        tableDatosUsuario.setSpacingBefore(20);
        PdfPCell cell5 = new PdfPCell(new Paragraph("Nombre: " + rutinaVisualizar.getIdusuario().getFisrtname()
                + " " + rutinaVisualizar.getIdusuario().getSecondname() + " "
                + rutinaVisualizar.getIdusuario().getFirstlastname() + " "
                + rutinaVisualizar.getIdusuario().getSecondlastname()));
        cell5.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell6 = new PdfPCell();
        cell6.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell7 = new PdfPCell();
        cell7.setBorder(Rectangle.NO_BORDER);

        tableDatosUsuario.addCell(cell5);
        tableDatosUsuario.addCell(cell6);
        tableDatosUsuario.addCell(cell7);

        PdfPTable tableFechas = new PdfPTable(3);
        tableFechas.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableFechas.setWidthPercentage(100);
        tableFechas.setSpacingBefore(10);
        PdfPCell cell8 = new PdfPCell(
                new Paragraph("Fecha de inicio: " + getMyFormattedDate(rutinaVisualizar.getFechaInicio())));
        cell8.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell9 = new PdfPCell(
                new Paragraph("Fecha de fin: " + getMyFormattedDate(rutinaVisualizar.getFechaFin())));
        cell9.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell10 = new PdfPCell();
        cell10.setBorder(Rectangle.NO_BORDER);

        tableFechas.addCell(cell8);
        tableFechas.addCell(cell9);
        tableFechas.addCell(cell10);

        PdfPTable tableMedidas = new PdfPTable(4);
        tableMedidas.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableMedidas.setWidthPercentage(100);
        tableMedidas.setSpacingBefore(10);

        Usuario usuAux = rutinaVisualizar.getIdusuario();
        List<Evaluacion> lstEvalAux = usuAux.getEvaluacionList();
        Evaluacion evalAux;
        double peso = 0;
        if (lstEvalAux.size() > 0) {
            evalAux = lstEvalAux.get(lstEvalAux.size() - 1);
            peso = evalAux.getPeso().doubleValue();
        }

        double estatura = 0;
        MedidasGenerales medGenAux = usuAux.getMedidasGenerales();
        if (medGenAux != null) {
            estatura = medGenAux.getEstatura().doubleValue();
        }

        PdfPCell cell11 = new PdfPCell(new Paragraph("Peso: " + peso));
        cell11.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell12 = new PdfPCell(new Paragraph("Talla: " + estatura));
        cell12.setBorder(Rectangle.NO_BORDER);

        double imc = 0;
        if (peso != 0 && estatura != 0) {
            imc = peso / Math.pow(estatura, 2);
        }

        PdfPCell cell13 = new PdfPCell(new Paragraph("I.M.C: " + imc));
        cell13.setBorder(Rectangle.NO_BORDER);
        PdfPCell cell14 = new PdfPCell(new Paragraph("Rutina: " + rutinaVisualizar.getCodigoRutina()));
        cell14.setBorder(Rectangle.NO_BORDER);

        tableMedidas.addCell(cell11);
        tableMedidas.addCell(cell12);
        tableMedidas.addCell(cell13);
        tableMedidas.addCell(cell14);

        PdfPTable tableDias = new PdfPTable(2);
        tableDias.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        tableDias.setWidthPercentage(100);
        tableDias.setSpacingBefore(20);
        tableDias.setHorizontalAlignment(Element.ALIGN_LEFT);
        tableDias.setWidths(new int[] { 1, 9 });

        List<Dia> lstDiasPDF = rutinaVisualizar.getDiaList();

        PdfPCell cellCabezeraDia = new PdfPCell(new Paragraph("Da", bold));
        PdfPCell cellCabezeraDia2 = new PdfPCell();
        cellCabezeraDia2.setBorder(Rectangle.NO_BORDER);

        tableDias.addCell(cellCabezeraDia);
        tableDias.addCell(cellCabezeraDia2);

        for (Dia dia : lstDiasPDF) {
            PdfPCell cellDia = new PdfPCell(new Paragraph(dia.getNumDia().toString()));
            PdfPCell cellDia2 = new PdfPCell();
            cellDia2.setBorder(Rectangle.NO_BORDER);

            List<GrupoMuscular> lstGMuscularPDF = dia.getGrupoMuscularList();

            if (lstGMuscularPDF.size() > 0) {
                PdfPTable tableGMuscular = new PdfPTable(2);
                tableGMuscular.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                tableGMuscular.setWidthPercentage(100);
                tableGMuscular.setHorizontalAlignment(Element.ALIGN_LEFT);
                tableGMuscular.setWidths(new int[] { 1, 6 });

                PdfPCell cellCabezeraGMuscular = new PdfPCell(new Paragraph("Grupo Muscular", bold));
                cellCabezeraGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                PdfPCell cellCabezeraGMuscular2 = new PdfPCell();
                cellCabezeraGMuscular2.setBorder(Rectangle.NO_BORDER);
                tableGMuscular.addCell(cellCabezeraGMuscular);
                tableGMuscular.addCell(cellCabezeraGMuscular2);

                int aux = 1;
                for (GrupoMuscular gMuscularFor : lstGMuscularPDF) {
                    PdfPCell cellGMuscular = new PdfPCell(
                            new Paragraph(gMuscularFor.getIdgrupoMuscularGeneral().getNombre()));
                    cellGMuscular.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                    PdfPCell cellGMuscular2 = new PdfPCell();
                    cellGMuscular2.setBorder(Rectangle.NO_BORDER);

                    List<EjercicioGm> lstEjerciciosGMuscularPDF = gMuscularFor.getEjercicioGmList();
                    BaseColor myColor = WebColors.getRGBColor("#CCEEFF");
                    if (lstEjerciciosGMuscularPDF.size() > 0) {
                        PdfPTable tableEjercicioGMsucular = new PdfPTable(5);
                        tableEjercicioGMsucular.getDefaultCell().setBorder(Rectangle.NO_BORDER);
                        tableEjercicioGMsucular.setWidthPercentage(100);
                        tableEjercicioGMsucular.setHorizontalAlignment(Element.ALIGN_LEFT);

                        PdfPCell cellCabezeraEjercicioGM = new PdfPCell(new Paragraph("Ejercicio", bold));
                        cellCabezeraEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM);

                        PdfPCell cellCabezeraEjercicioGM2 = new PdfPCell(new Paragraph("Series", bold));
                        cellCabezeraEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM2.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM2.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM2);

                        PdfPCell cellCabezeraEjercicioGM3 = new PdfPCell(new Paragraph("Repeticiones", bold));
                        cellCabezeraEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM3.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM3.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM3);

                        PdfPCell cellCabezeraEjercicioGM4 = new PdfPCell(new Paragraph("Receso", bold));
                        cellCabezeraEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM4.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM4.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM4);

                        PdfPCell cellCabezeraEjercicioGM5 = new PdfPCell(new Paragraph("Peso", bold));
                        cellCabezeraEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT | Rectangle.TOP);
                        cellCabezeraEjercicioGM5.setLeading(20f, 0f);
                        cellCabezeraEjercicioGM5.setBackgroundColor(myColor);
                        tableEjercicioGMsucular.addCell(cellCabezeraEjercicioGM5);

                        int aux2 = 1;
                        for (EjercicioGm ejercicioGm : lstEjerciciosGMuscularPDF) {
                            PdfPCell cellEjercicioGM = new PdfPCell(
                                    new Paragraph(ejercicioGm.getEjercicio().getNombre()));
                            cellEjercicioGM.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM2 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getNumeroSeries().toString()));
                            cellEjercicioGM2.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM2.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM3 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getRepeticiones().toString()));
                            cellEjercicioGM3.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM3.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM4 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getReceso().toString()));
                            cellEjercicioGM4.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM4.setLeading(20f, 0f);

                            PdfPCell cellEjercicioGM5 = new PdfPCell(
                                    new Paragraph(ejercicioGm.getPeso().toString()));
                            cellEjercicioGM5.setBorder(Rectangle.BOTTOM | Rectangle.RIGHT);
                            cellEjercicioGM5.setLeading(20f, 0f);

                            if (aux2 % 2 == 0) {
                                cellEjercicioGM.setBackgroundColor(myColor);
                                cellEjercicioGM2.setBackgroundColor(myColor);
                                cellEjercicioGM3.setBackgroundColor(myColor);
                                cellEjercicioGM4.setBackgroundColor(myColor);
                                cellEjercicioGM5.setBackgroundColor(myColor);
                            }

                            tableEjercicioGMsucular.addCell(cellEjercicioGM);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM2);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM3);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM4);
                            tableEjercicioGMsucular.addCell(cellEjercicioGM5);
                            aux2++;
                        }
                        cellGMuscular2.addElement(tableEjercicioGMsucular);
                    }
                    tableGMuscular.addCell(cellGMuscular);
                    tableGMuscular.addCell(cellGMuscular2);
                    aux++;
                }
                cellDia2.addElement(tableGMuscular);
            }
            tableDias.addCell(cellDia);
            tableDias.addCell(cellDia2);
        }

        LineSeparator ls = new LineSeparator();
        document.add(tableEncabezado);
        document.add(ls);
        document.add(tableDatosUsuario);
        document.add(tableFechas);
        document.add(tableMedidas);
        document.add(tableDias);
        document.close();
    } catch (DocumentException | FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException ex) {
        Logger.getLogger(BeanGestionRutinas.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.chaschev.itext.CellBuilder.java

License:Apache License

public CellBuilder alignBottom() {
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    return this;
}

From source file:com.masscustsoft.service.ToPdf.java

License:Open Source License

private int getVAlign(Map it, String fld) {
    String alignment = MapUtil.getStr(it, fld);
    int align = Element.ALIGN_UNDEFINED;
    if ("bottom".equalsIgnoreCase(alignment))
        align = Element.ALIGN_BOTTOM;
    if ("top".equalsIgnoreCase(alignment))
        align = Element.ALIGN_TOP;
    if ("middle".equalsIgnoreCase(alignment))
        align = Element.ALIGN_MIDDLE;
    return align;
}

From source file:com.softwaremagico.tm.pdf.complete.skills.CompleteSkillsTable.java

License:Open Source License

private static PdfPCell getThirdColumnTable(CharacterPlayer characterPlayer, String language,
        Stack<PdfPCell> learnedSkillsRows) throws InvalidXmlElementException {
    float[] widths = { 4f, 1f };
    PdfPTable table = new PdfPTable(widths);
    setTablePropierties(table);/*from   www.j a v a  2s  .  c o  m*/
    PdfPCell cell = new PdfPCell();
    setCellProperties(cell);

    for (int i = 0; i < ROWS - OCCULTISM_ROWS; i++) {
        // Two columns: skill and value.
        table.addCell(learnedSkillsRows.pop());
        table.addCell(learnedSkillsRows.pop());
    }

    // Add Occultism table
    PdfPTable occultismTable = new OccultismTable(characterPlayer, language);
    PdfPCell occulstimCell = new PdfPCell();
    // setCellProperties(occulstimCell);
    // occulstimCell.setRowspan(widths.length);
    occulstimCell.setRowspan(OCCULTISM_ROWS);
    occulstimCell.setColspan(2);
    occulstimCell.addElement(occultismTable);
    occulstimCell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    occulstimCell.setPadding(0);
    table.addCell(occulstimCell);

    cell.addElement(table);
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    return cell;
}

From source file:de.aidger.utils.pdf.ActivityReportConverter.java

License:Open Source License

/**
 * Writes the logos and the address of the institute.
 *//*from  w  ww .  j a  v a  2  s.  c  om*/
private void writeLogo() {
    try {
        Font generatedByFont = new Font(
                BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 8);
        Image aidger = Image.getInstance(getClass().getResource("/de/aidger/res/pdf/AidgerLogo.png"));
        aidger.scaleAbsolute(80.0f, 20.0f);
        PdfPTable table = new PdfPTable(2);
        table.setTotalWidth(reader.getPageSize(1).getRight());
        PdfPCell cell = new PdfPCell(new Phrase(_("Generated by: "), generatedByFont));
        cell.setBorder(0);
        cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cell.setPaddingBottom(5);
        cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
        table.addCell(cell);
        cell = new PdfPCell(Image.getInstance(aidger));
        cell.setHorizontalAlignment(Element.ALIGN_LEFT);
        cell.setBorder(0);
        table.addCell(cell);
        table.writeSelectedRows(0, -1, 0, 25, contentByte);
    } catch (BadElementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:direccion.GeneradorFormato.java

@Override
public void onEndPage(PdfWriter writer, Document document) {

    Rectangle rect = writer.getBoxSize("art");
    Image imghead = null;/*from w w w  .  ja  v a 2 s. co  m*/
    PdfContentByte cbhead = null;

    //        try {
    //            imghead = Image.getInstance("LogoSapito5.png");
    //            imghead.setAbsolutePosition(0, 0);
    //            imghead.setAlignment(Image.ALIGN_CENTER);
    //            imghead.scalePercent(10f);
    //            cbhead = writer.getDirectContent();
    //            PdfTemplate tp = cbhead.createTemplate(100, 150);
    //            tp.addImage(imghead);
    //            cbhead.addTemplate(tp, 100, 715);
    //        } catch (BadElementException e) {
    //            e.printStackTrace();
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        } catch (DocumentException e) {
    //            e.printStackTrace();
    //        }

    Phrase headPhraseImg = new Phrase(cbhead + "",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 7, Font.NORMAL));

    Calendar c1 = Calendar.getInstance();
    Calendar c2 = new GregorianCalendar();
    String dia, mes, annio;
    dia = Integer.toString(c1.get(Calendar.DATE));
    mes = Integer.toString(c1.get(Calendar.MONTH));
    annio = Integer.toString(c1.get(Calendar.YEAR));
    Date fecha = new Date();
    String fechis = dia + "/" + mes + "/" + annio;

    Paragraph parrafo5 = new Paragraph(fechis,
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo5),
            rect.getRight(450), rect.getTop(-80), 0);

    Paragraph parrafo7 = new Paragraph("Empresa Sapito S.A. de C.V.",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo7),
            rect.getBottom(250), rect.getTop(-60), 0);

    Paragraph parrafo8 = new Paragraph("Reporte algoooooo",
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo8),
            rect.getBottom(250), rect.getTop(-40), 0);

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase(
            "      _____________________________________________________________________________________    "),
            rect.getBorder(), rect.getTop(650), 0);

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase(
            "      _____________________________________________________________________________________    "),
            rect.getBorder(), rect.getTop(-24), 0);

    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_BOTTOM, new Phrase(
            "      _____________________________________________________________________________________    "),
            rect.getBorder(), rect.getTop(-20), 0);

    Paragraph parrafo6 = new Paragraph(String.format("Pg %d", writer.getPageNumber()),
            FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.NORMAL, BaseColor.BLACK));
    ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(parrafo6),
            rect.getRight(-35), rect.getTop(-80), 0);
}

From source file:es.sm2.openppm.front.utils.DocumentUtils.java

License:Open Source License

/**
 * /*  w w  w.  ja  v a2s. c o  m*/
 * @param pagActual
 * @param pagTotal
 * @param headerImg
 * @param footerImg
 * @param reader
 * @param stamper
 * @param idioma
 * @throws DocumentException
 * @throws IOException
 */
private static void setHeaderFooter(int pagActual, int pagTotal, Image headerImg, Image footerImg,
        PdfReader reader, PdfStamper stamper, ResourceBundle idioma) throws DocumentException, IOException {

    PdfContentByte content = stamper.getUnderContent(pagActual);
    content.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, false), 8);
    headerImg.setAbsolutePosition(74f, 745f);
    content.addImage(headerImg);
    footerImg.setAbsolutePosition(75f, 20f);
    content.addImage(footerImg);
    content.beginText();
    content.showTextAligned(Element.ALIGN_BOTTOM,
            "_____________________________________________________________________________________________________",
            75f, 55f, 0f);
    content.showTextAligned(Element.ALIGN_BOTTOM, "2010 OPEN PPM - Projet Portfolio Management. (Open PPM)",
            75f, 45f, 0f);
    content.showTextAligned(Element.ALIGN_BOTTOM, "www.sourceforce.net/openppm", 75f, 35f, 0f);
    content.showTextAligned(Element.ALIGN_BOTTOM,
            new ParamResourceBundle("pdf.pagination", pagActual, pagTotal).toString(idioma), 475f, 45f, 0f);
    content.endText();
    content.stroke();
}

From source file:Export.DocNotaDebito.java

@SuppressWarnings({ "CallToPrintStackTrace", "null", "UnusedAssignment" })
public String docSeguros(String nomeSeguro, String numApolice, String interCodVendedor, String idCliente,
        String fundoContrato, ArrayList<String[]> listaValores, Contrato contrato, String user, String moeda,
        String arquivo, String numeroRegistro) {
    String reString;/*from ww  w .jav a 2  s . com*/
    try {

        Font fontCabecalhoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.2f);
        Font fontLinha = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 0.000000358f);
        Font fontCabecalhoS = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.2f);
        Font fontCorpo = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f);
        Font fontCorpoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f);
        Font fontNull = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 4f);
        Font fontMenor = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 3f);

        PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 80, 20 });
        pTableEmpresaPricipal.setWidthPercentage(95);
        PdfPTable pTableEmpresaInforImpres1 = new PdfPTable(1);
        PdfPTable pTableEmpresaInforImpres2 = new PdfPTable(1);
        PdfPTable pTableEmpresaInforImpres3 = new PdfPTable(2);
        PdfPTable pTableEmpresaInforImpres4 = new PdfPTable(2);
        PdfPTable pTableEmpresaInforImpres5 = new PdfPTable(1);

        PdfPTable pTableFatura = new PdfPTable(new float[] { 80, 20 });
        pTableFatura.setWidthPercentage(95);

        PdfPCell pCellNomeEmpresa = new PdfPCell(new Phrase(Empresa.NOME, fontCabecalhoN));
        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 pCellCapital = new PdfPCell(new Phrase(Empresa.CAPITALSOCIAL, fontCabecalhoN));
        pCellCapital.setBorder(0);

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

        PdfPCell pCellDebNF = new PdfPCell(new Phrase("Deb. N", fontCabecalhoS));
        pCellDebNF.setHorizontalAlignment(Element.ALIGN_RIGHT);
        pCellDebNF.setBorder(0);

        PdfPCell pCellDebN = new PdfPCell(new Phrase(numeroRegistro, fontCabecalhoS));
        pCellDebN.setHorizontalAlignment(Element.ALIGN_CENTER);
        pCellDebN.setBorder(0);

        PdfPCell pCellInterCoF = new PdfPCell(new Phrase("Inter COD:", fontCabecalhoS));
        pCellInterCoF.setHorizontalAlignment(Element.ALIGN_RIGHT);
        pCellInterCoF.setBorder(0);

        PdfPCell pCellInterCo = new PdfPCell(new Phrase(interCodVendedor, fontCabecalhoS));
        pCellInterCo.setHorizontalAlignment(Element.ALIGN_CENTER);
        pCellInterCo.setBorder(0);

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

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

        pTableEmpresaInforImpres2.addCell(pCellCapital);
        pTableEmpresaInforImpres2.addCell(pCellPolice);

        pTableEmpresaInforImpres3.addCell(pCellDebNF);
        pTableEmpresaInforImpres3.addCell(pCellDebN);
        pTableEmpresaInforImpres3.addCell(pCellInterCoF);
        pTableEmpresaInforImpres3.addCell(pCellInterCo);

        PdfPCell cellTabela1 = new PdfPCell(pTableEmpresaInforImpres2);
        cellTabela1.setBorder(0);

        pTableEmpresaInforImpres4.addCell(cellTabela1);

        PdfPCell cellTabela2 = new PdfPCell(pTableEmpresaInforImpres3);
        cellTabela2.setBorder(0);

        pTableEmpresaInforImpres4.addCell(cellTabela2);

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

        pTableEmpresaInforImpres5.addCell(cellTabela3);

        PdfPCell cellTabela4 = new PdfPCell(pTableEmpresaInforImpres4);
        cellTabela4.setBorder(0);

        pTableEmpresaInforImpres5.addCell(cellTabela4);

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

        pTableEmpresaPricipal.addCell(cellTabela5);

        PdfPCell cellTabela6 = new PdfPCell(imageEmpresa);
        cellTabela6.setBorder(0);
        cellTabela6.setHorizontalAlignment(Element.ALIGN_RIGHT);

        pTableEmpresaPricipal.addCell(cellTabela6);

        PdfPCell cellFaturaTitulo = new PdfPCell(new Phrase("FACTURA", fontCabecalhoN));
        cellFaturaTitulo.setBorder(0);
        cellFaturaTitulo.setHorizontalAlignment(Element.ALIGN_RIGHT);

        PdfPCell cellFaturaTipo = new PdfPCell(new Phrase(nomeSeguro, fontCabecalhoN));
        cellFaturaTipo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellFaturaTipo.setBorder(0);

        PdfPTable pTableLinha = new PdfPTable(1);
        pTableLinha.setWidthPercentage(95);
        PdfPCell linha = new PdfPCell(new Phrase(" ", fontLinha));
        linha.setBorderWidthTop(0.5f);
        linha.setBorderWidthBottom(0);
        linha.setBorderWidthLeft(0);
        linha.setBorderWidthRight(0);
        pTableLinha.addCell(linha);

        pTableFatura.addCell(cellFaturaTitulo);
        pTableFatura.addCell(cellFaturaTipo);

        PdfPTable pTableClientePrincipal = new PdfPTable(new float[] { 60, 10, 30 });
        pTableClientePrincipal.setWidthPercentage(95);
        PdfPTable pTableClienteDescisao = new PdfPTable(1);
        PdfPTable pTableDataEVenda = new PdfPTable(1);
        PdfPTable pTableTitulo = new PdfPTable(1);
        pTableTitulo.setWidthPercentage(95);

        ClienteI ci = null;
        ArrayList<DataReseguro.DataEmpresa> listaDataEmpresas = new ArrayList<>();
        if (!isReseguro) {
            ci = new ClienteI(idCliente);
        } else {
            listaDataEmpresas = DataReseguro.getDadosEmpresa(Integer.valueOf(idCliente));
        }

        Paragraph pCl = new Paragraph();
        pCl.add(new Phrase((isReseguro) ? "NOME: " : ci.getNOMEL_(), fontCorpo));
        pCl.add(new Phrase(
                (isReseguro) ? listaDataEmpresas.get(0).getEMPRESA().toUpperCase() + " (" + segurado + ")"
                        : ci.getNOME_(),
                fontCorpoN));
        PdfPCell cellNomeCliente = new PdfPCell(pCl);
        cellNomeCliente.setBorder(0);

        pCl = new Paragraph();
        pCl.add(new Phrase((isReseguro) ? "ENDEREO: " : ci.getENDERECOL_(), fontCorpo));
        pCl.add(new Phrase((isReseguro) ? listaDataEmpresas.get(0).getENDERECO() : ci.getENDERECO_(),
                fontCorpoN));
        if (!isReseguro) {
            pCl.add(new Phrase("       ", fontCorpoN));
            pCl.add(new Phrase((isReseguro) ? "" : ci.getCODPOSTALL_(), fontCorpo));
            pCl.add(new Phrase((isReseguro) ? "" : ci.getCODPOSTAL_(), fontCorpoN));
        }
        PdfPCell cellClienteMorada = new PdfPCell(pCl);
        cellClienteMorada.setBorder(0);

        PdfPCell cellNomeLocalidade = null;
        PdfPCell cellNomeTelefone = null;
        if (!isReseguro) {
            pCl = new Paragraph();
            pCl.add(new Phrase(ci.getLOCALTRABALHOL_(), fontCorpo));
            pCl.add(new Phrase(ci.getLOCALTRABALHO_(), fontCorpoN));
            cellNomeLocalidade = new PdfPCell(pCl);
            cellNomeLocalidade.setBorder(0);

            pCl = new Paragraph();
            pCl.add(new Phrase(ci.getTELEFONEL_(), fontCorpo));
            pCl.add(new Phrase(ci.getTELEFONE_(), fontCorpoN));
            cellNomeTelefone = new PdfPCell(pCl);
            cellNomeTelefone.setBorder(0);
        }

        SimpleDateFormat sdf = new SimpleDateFormat("dd 'de' MMMM 'de' yyyy", new Locale("pt", "BR"));
        SimpleDateFormat sdfContr = new SimpleDateFormat("dd-MM-yyyy");
        SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss");
        PdfPCell cellDataContrato = new PdfPCell(new Phrase(
                "Data: " + (contrato.getDataInicio() != null ? sdfContr.format(contrato.getDataInicio()) : "")
                        + " - " + (contrato.getDataFim() != null ? sdfContr.format(contrato.getDataFim()) : ""),
                fontCorpo));
        cellDataContrato.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellDataContrato.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cellDataContrato.setBorderWidthTop(1f);
        cellDataContrato.setBorderWidthBottom(0f);
        cellDataContrato.setBorderWidthLeft(1f);
        cellDataContrato.setBorderWidthRight(1f);

        PdfPCell cellVendetor = new PdfPCell(new Phrase("Vendedor: "
                + ((!isReseguro) ? "NICON SEGUROS" : listaDataEmpresas.get(0).getEMPRESA().toUpperCase()),
                fontCorpo));
        cellVendetor.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellVendetor.setVerticalAlignment(Element.ALIGN_TOP);
        cellVendetor.setBorderWidthTop(0f);
        cellVendetor.setBorderWidthBottom(1f);
        cellVendetor.setBorderWidthLeft(1f);
        cellVendetor.setBorderWidthRight(1f);

        pTableClienteDescisao.addCell(cellNomeCliente);
        pTableClienteDescisao.addCell(cellClienteMorada);
        if (!isReseguro) {
            pTableClienteDescisao.addCell(cellNomeLocalidade);
            pTableClienteDescisao.addCell(cellNomeTelefone);
        }

        PdfPCell cellZerro = new PdfPCell(new Phrase(" ", fontNull));
        cellZerro.setBorder(0);
        PdfPCell cellZerro2 = new PdfPCell(new Phrase(" "));
        cellZerro2.setBorderWidthTop(0f);
        cellZerro2.setBorderWidthBottom(0f);
        cellZerro2.setBorderWidthLeft(1f);
        cellZerro2.setBorderWidthRight(1f);

        PdfPTable pTableNull = new PdfPTable(1);
        pTableNull.setWidthPercentage(95);
        pTableNull.addCell(cellZerro);

        pTableDataEVenda.addCell(cellDataContrato);
        pTableDataEVenda.addCell(cellZerro2);
        pTableDataEVenda.addCell(cellVendetor);

        PdfPCell cellTitulo = new PdfPCell(new Phrase("Cliente", fontCabecalhoN));
        cellTitulo.setBorder(0);

        pTableTitulo.addCell(cellZerro);
        pTableTitulo.addCell(cellTitulo);

        PdfPCell cellCliente = new PdfPCell(pTableClienteDescisao);
        cellCliente.setBorder(0);

        PdfPCell cellCliente1 = new PdfPCell(pTableDataEVenda);
        cellCliente1.setBorder(0);

        pTableClientePrincipal.addCell(cellCliente);
        pTableClientePrincipal.addCell(cellZerro);
        pTableClientePrincipal.addCell(cellCliente1);

        PdfPCell cellQuan = new PdfPCell(new Phrase("QTD", fontCorpo));
        PdfPCell cellDescricao = new PdfPCell(new Phrase("Descrio", fontCorpo));
        PdfPCell cellValorUnitatio = new PdfPCell(new Phrase("Valor Unitrio", fontCorpo));
        PdfPCell cellTotal = new PdfPCell(new Phrase("Total", fontCorpo));
        PdfPTable TableRegistro = new PdfPTable(new float[] { 10, 45, 28, 17 });
        TableRegistro.setWidthPercentage(95);

        cellQuan.setBorderWidthBottom(1f);
        cellQuan.setBorderWidthTop(1f);
        cellQuan.setBorderWidthLeft(1f);
        cellQuan.setBorderWidthRight(1f);
        cellQuan.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellQuan.setVerticalAlignment(Element.ALIGN_CENTER);

        cellDescricao.setBorderWidthBottom(1f);
        cellDescricao.setBorderWidthTop(1f);
        cellDescricao.setBorderWidthLeft(0.5f);
        cellDescricao.setBorderWidthRight(1f);
        cellDescricao.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellDescricao.setVerticalAlignment(Element.ALIGN_CENTER);

        cellValorUnitatio.setBorderWidthBottom(1f);
        cellValorUnitatio.setBorderWidthTop(1f);
        cellValorUnitatio.setBorderWidthLeft(0.5f);
        cellValorUnitatio.setBorderWidthRight(1f);
        cellValorUnitatio.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellValorUnitatio.setVerticalAlignment(Element.ALIGN_CENTER);

        cellTotal.setBorderWidthBottom(1f);
        cellTotal.setBorderWidthTop(1f);
        cellTotal.setBorderWidthLeft(0.5f);
        cellTotal.setBorderWidthRight(1f);
        cellTotal.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTotal.setVerticalAlignment(Element.ALIGN_CENTER);

        TableRegistro.addCell(cellQuan);
        TableRegistro.addCell(cellDescricao);
        TableRegistro.addCell(cellValorUnitatio);
        TableRegistro.addCell(cellTotal);

        int total = (listaValores.size() > 21) ? listaValores.size() : 18;

        boolean rulpas = false;
        for (int i = 0; i < total + 1; i++) {
            /**
             * Serve para add linha a Table <TableRegistro> e testa caso o ArrayList tenha
             * Menos linha que o <total> a Table <TableRegistro> continua recebendo dados Com String Vazios
             */
            if (listaValores.size() - 1 >= i || (listaValores.size() - 1 == i)) {
                //                    System.err.println(i);
                cellQuan = new PdfPCell(new Phrase(listaValores.get(i)[0], fontCorpo));
                cellDescricao = new PdfPCell(new Phrase(listaValores.get(i)[1], fontCorpo));
                cellValorUnitatio = new PdfPCell(new Phrase(listaValores.get(i)[2] + " "
                        + ((!nomeSeguro.equals("Viagem")) ? contrato.getSigla() : ""), fontCorpo));
                cellTotal = new PdfPCell(new Phrase(listaValores.get(i)[3] + " "
                        + ((!nomeSeguro.equals("Viagem") || listaValores.size() - 1 == i) ? contrato.getSigla()
                                : ""),
                        fontCorpo));

                cellQuan.setPaddingTop(2.5f);
                cellDescricao.setPaddingTop(2.5f);
                cellValorUnitatio.setPaddingTop(2.5f);
                cellTotal.setPaddingTop(2.5f);

                cellQuan.setPaddingBottom(2.5f);
                cellDescricao.setPaddingBottom(2.5f);
                cellValorUnitatio.setPaddingBottom(2.5f);
                cellTotal.setPaddingBottom(2.5f);

                cellQuan.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                cellDescricao.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                cellValorUnitatio.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
                cellTotal.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);

            } else {
                cellQuan = new PdfPCell(new Phrase(" ", fontCorpo));
                cellDescricao = new PdfPCell(new Phrase(" ", fontCorpo));
                cellValorUnitatio = new PdfPCell(new Phrase(" ", fontCorpo));
                cellTotal = new PdfPCell(new Phrase(" ", fontCorpo));
            }

            if (listaValores.size() - 1 == i && !rulpas) {
                cellDescricao.setRowspan(total - i);
                rulpas = true;
            }

            cellQuan.setBorderWidthBottom(0f);
            cellQuan.setBorderWidthTop((listaValores.size() - 1 == i) ? 1f : 0f);
            cellQuan.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellDescricao.setBorderWidthBottom((listaValores.size() - 1 == i) ? 1f : 0f);
            cellDescricao.setBorderWidthTop((listaValores.size() - 1 == i) ? 1f : 0f);
            cellDescricao.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellValorUnitatio.setBorderWidthBottom(0f);
            cellValorUnitatio.setBorderWidthTop((listaValores.size() - 1 == i) ? 1f : 0f);
            cellValorUnitatio.setHorizontalAlignment(Element.ALIGN_CENTER);

            cellTotal.setBorderWidthBottom(0f);
            cellTotal.setBorderWidthTop((listaValores.size() - 1 == i) ? 1f : 0f);
            cellTotal.setHorizontalAlignment(Element.ALIGN_CENTER);

            if (i + 1 == total) {
                cellQuan.setBorderWidthBottom(1f);
                cellDescricao.setBorderWidthBottom(1f);
                cellValorUnitatio.setBorderWidthBottom(1f);
                cellTotal.setBorderWidthBottom(1f);
            }

            TableRegistro.addCell(cellQuan);
            if (listaValores.size() - 1 >= i || listaValores.size() - 1 == i) {
                TableRegistro.addCell(cellDescricao);
            }

            TableRegistro.addCell(cellValorUnitatio);
            TableRegistro.addCell(cellTotal);
        }
        PdfPTable pTablePrincipalPagamento = new PdfPTable(new float[] { 55, 45 });
        pTablePrincipalPagamento.setWidthPercentage(95);
        PdfPTable pTableFomaPagamentoPricipal = new PdfPTable(1);
        PdfPTable pTableFomaPagamento = new PdfPTable(new float[] { 15, 50, 10 });
        PdfPTable pTableFomaValoresPricipal = new PdfPTable(1);
        PdfPTable pTableFomaValores = new PdfPTable(new float[] { 15, 47, 38 });

        PdfPCell cellvazio = new PdfPCell(new Phrase(" ", fontCorpo));
        PdfPCell cellTituloFormaPagamento = new PdfPCell(new Phrase("Forma de Pagamento", fontCorpoN));
        cellTituloFormaPagamento.setBorderWidthBottom(0f);
        cellTituloFormaPagamento.setBorderWidthTop(1f);
        cellTituloFormaPagamento.setBorderWidthRight(0f);
        cellTituloFormaPagamento.setBorderWidthLeft(0f);

        PdfPCell cellTituloForma1 = new PdfPCell(new Phrase(" Cheque", fontCorpo));
        cellTituloForma1.setBorderWidthBottom(0f);
        cellTituloForma1.setBorderWidthTop(0f);
        cellTituloForma1.setBorderWidthRight(0f);
        cellTituloForma1.setBorderWidthLeft(0f);

        PdfPCell cellTituloForma2 = new PdfPCell(new Phrase(" Dinheiro", fontCorpo));
        cellTituloForma2.setBorderWidthBottom(0f);
        cellTituloForma2.setBorderWidthTop(0f);
        cellTituloForma2.setBorderWidthRight(0f);
        cellTituloForma2.setBorderWidthLeft(0f);

        PdfPCell cellTituloForma3 = new PdfPCell(new Phrase(" Outros", fontCorpo));
        cellTituloForma3.setBorderWidthBottom(1f);
        cellTituloForma3.setBorderWidthTop(0f);
        cellTituloForma3.setBorderWidthRight(0f);
        cellTituloForma3.setBorderWidthLeft(0f);

        cellvazio.setBorderWidthBottom(0f);
        cellvazio.setBorderWidthTop(1f);
        cellvazio.setBorderWidthRight(0f);
        cellvazio.setBorderWidthLeft(1f);
        pTableFomaPagamento.addCell(cellvazio);
        pTableFomaPagamento.addCell(cellTituloFormaPagamento);
        cellvazio.setBorderWidthBottom(0f);
        cellvazio.setBorderWidthTop(1f);
        cellvazio.setBorderWidthRight(1f);
        cellvazio.setBorderWidthLeft(0f);
        pTableFomaPagamento.addCell(cellvazio);

        cellvazio.setBorderWidthBottom(0f);
        cellvazio.setBorderWidthTop(0f);
        cellvazio.setBorderWidthRight(0f);
        cellvazio.setBorderWidthLeft(1f);
        pTableFomaPagamento.addCell(cellvazio);
        pTableFomaPagamento.addCell(cellTituloForma1);
        cellvazio.setBorderWidthBottom(0f);
        cellvazio.setBorderWidthTop(0f);
        cellvazio.setBorderWidthRight(1f);
        cellvazio.setBorderWidthLeft(0f);
        pTableFomaPagamento.addCell(cellvazio);

        cellvazio.setBorderWidthBottom(0f);
        cellvazio.setBorderWidthTop(0f);
        cellvazio.setBorderWidthRight(0f);
        cellvazio.setBorderWidthLeft(1f);
        pTableFomaPagamento.addCell(cellvazio);
        pTableFomaPagamento.addCell(cellTituloForma2);
        cellvazio.setBorderWidthBottom(0f);
        cellvazio.setBorderWidthTop(0f);
        cellvazio.setBorderWidthRight(1f);
        cellvazio.setBorderWidthLeft(0f);
        pTableFomaPagamento.addCell(cellvazio);

        cellvazio.setBorderWidthBottom(1f);
        cellvazio.setBorderWidthTop(0f);
        cellvazio.setBorderWidthRight(0f);
        cellvazio.setBorderWidthLeft(1f);
        pTableFomaPagamento.addCell(cellvazio);
        pTableFomaPagamento.addCell(cellTituloForma3);
        cellvazio.setBorderWidthBottom(1f);
        cellvazio.setBorderWidthTop(0f);
        cellvazio.setBorderWidthRight(1f);
        cellvazio.setBorderWidthLeft(0f);
        pTableFomaPagamento.addCell(cellvazio);

        PdfPCell cellNull = new PdfPCell(new Phrase(" ", fontMenor));
        cellNull.setBorderWidthBottom(0f);
        cellNull.setBorderWidthTop(0f);
        cellNull.setBorderWidthRight(0f);
        cellNull.setBorderWidthLeft(0f);

        pTableFomaPagamentoPricipal.addCell(cellNull);
        PdfPCell cellPagamento = new PdfPCell(pTableFomaPagamento);
        cellPagamento.setBorder(0);
        pTableFomaPagamentoPricipal.addCell(cellPagamento);

        PdfPCell cellPecentage1 = new PdfPCell(new Phrase(((nomeSeguro.equals("Viagem") || isReseguro) ? " "
                : ((nomeSeguro.equals("Acidente Para Grupo")) ? " " : "2.50%")), fontCorpo));
        cellPecentage1.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellPecentage1.setBorderWidthBottom(0f);
        cellPecentage1.setBorderWidthTop(1f);
        cellPecentage1.setBorderWidthRight(0f);
        cellPecentage1.setBorderWidthLeft(1f);

        PdfPCell cellPecentage2 = new PdfPCell(new Phrase((isReseguro) ? " " : "5%", fontCorpo));
        cellPecentage2.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellPecentage2.setBorderWidthBottom(0f);
        cellPecentage2.setBorderWidthTop(0f);
        cellPecentage2.setBorderWidthRight(0f);
        cellPecentage2.setBorderWidthLeft(1f);

        PdfPCell cellPecentage3 = new PdfPCell(new Phrase(" ", fontCorpo));
        cellPecentage3.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellPecentage3.setBorderWidthBottom(0f);
        cellPecentage3.setBorderWidthTop(0f);
        cellPecentage3.setBorderWidthRight(0f);
        cellPecentage3.setBorderWidthLeft(1f);

        PdfPCell cellFundo = new PdfPCell(new Phrase(fundoContrato, fontCorpo));
        cellFundo.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellFundo.setBorderWidthBottom(0f);
        cellFundo.setBorderWidthTop(1f);
        cellFundo.setBorderWidthRight(0f);
        cellFundo.setBorderWidthLeft(0f);

        PdfPCell cellImposto = new PdfPCell(new Phrase((isReseguro) ? " " : "IMPOSTO", fontCorpo));
        cellImposto.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellImposto.setBorderWidthBottom(0f);
        cellImposto.setBorderWidthTop(0f);
        cellImposto.setBorderWidthRight(0f);
        cellImposto.setBorderWidthLeft(0f);

        PdfPCell cellSelo = new PdfPCell(new Phrase((isReseguro) ? " " : "ACESSORIOS", fontCorpo));
        cellSelo.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellSelo.setBorderWidthBottom(0f);
        cellSelo.setBorderWidthTop(0f);
        cellSelo.setBorderWidthRight(0f);
        cellSelo.setBorderWidthLeft(0f);

        PdfPCell cellvazio1;
        if (!isReseguro) {
            cellvazio1 = new PdfPCell(
                    new Phrase(
                            ((nomeSeguro.equals("Viagem"))
                                    ? ((contrato.getValorNC() == null || contrato.getValorNC().isEmpty())
                                            ? " "
                                            : Moeda.format(
                                                    Double.valueOf(contrato.getValorNC().replace(',', '.')))
                                                    + " EUR")
                                    : ((nomeSeguro.equals("Acidente Para Grupo")) ? " "
                                            : ((nomeSeguro.equals("Automovel")) ? Moeda.format(
                                                    (Double.valueOf(contrato.getPremioLiquido()) * 0.025)) + " "
                                                    + contrato.getSigla() : "2.50%"))),
                            fontCorpo));
        } else {
            cellvazio1 = new PdfPCell(new Phrase(" ", fontCorpo));
        }
        pTableFomaValores.addCell(cellPecentage1);
        pTableFomaValores.addCell(cellFundo);
        cellvazio1.setBorderWidthTop(1);
        cellvazio1.setBorderWidthRight(1);
        cellvazio1.setHorizontalAlignment(Element.ALIGN_RIGHT);
        pTableFomaValores.addCell(cellvazio1);

        double i05 = 0;//imposto 0.05%
        double i25 = 0;//imposto 2.5%
        try {
            if (nomeSeguro.equals("Viagem")) {
                i05 = 0.05 * Moeda.arrendodamento(contrato.getValorNC().replace(',', '.'));
                i25 = 0.006 * Moeda.arrendodamento(contrato.getValorNC().replace(',', '.'));
            } else if (!isReseguro) {
                i05 = 0.05 * Moeda.arrendodamento(contrato.getPremioLiquido());
                i25 = 0.006 * Moeda.arrendodamento(contrato.getPremioLiquido());
            }
        } catch (Exception e) {
        }
        PdfPCell cellvazio2 = new PdfPCell(
                new Phrase((isReseguro) ? " " : (Moeda.format(i05) + " " + contrato.getSigla()), fontCorpo));
        pTableFomaValores.addCell(cellPecentage2);
        pTableFomaValores.addCell(cellImposto);
        cellvazio2.setBorderWidthRight(1);
        cellvazio2.setBottom(10000);
        cellvazio2.setHorizontalAlignment(Element.ALIGN_RIGHT);
        pTableFomaValores.addCell(cellvazio2);

        PdfPCell cellvazio3 = new PdfPCell(
                new Phrase((isReseguro) ? " " : (Moeda.format(i25) + " " + contrato.getSigla()), fontCorpo));
        pTableFomaValores.addCell(cellPecentage3);
        pTableFomaValores.addCell(cellSelo);
        cellvazio3.setBorderWidthRight(1);
        cellvazio3.setHorizontalAlignment(Element.ALIGN_RIGHT);
        pTableFomaValores.addCell(cellvazio3);

        PdfPTable pTableTotalPagar = new PdfPTable(2);
        PdfPCell cellTituloTotalPagar = new PdfPCell(
                new Phrase("TOTAL A PAGAR " + contrato.getSigla(), fontCorpoN));
        cellTituloTotalPagar.setBorderWidthBottom(1f);
        cellTituloTotalPagar.setBorderWidthTop(0f);
        cellTituloTotalPagar.setBorderWidthRight(0f);
        cellTituloTotalPagar.setBorderWidthLeft(1f);

        PdfPCell cellValorPagar = new PdfPCell(
                new Phrase(contrato.getPremioLiquidoMoeda() + " " + contrato.getSigla(), fontCorpo));
        cellValorPagar.setBorderWidthBottom(1f);
        cellValorPagar.setBorderWidthTop(0f);
        cellValorPagar.setBorderWidthRight(1f);
        cellValorPagar.setBorderWidthLeft(0f);
        cellValorPagar.setHorizontalAlignment(Element.ALIGN_RIGHT);

        pTableTotalPagar.addCell(cellTituloTotalPagar);
        pTableTotalPagar.addCell(cellValorPagar);

        PdfPTable pTableSubTotal = new PdfPTable(new float[] { 62, 38 });
        PdfPCell cellTituloSubTotal = new PdfPCell(new Phrase("SubTotal", fontCorpoN));
        cellTituloSubTotal.setBorder(0);
        cellTituloSubTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);
        PdfPCell cellValorSubTotal = new PdfPCell(
                new Phrase(contrato.getPremioBrutoMoeda() + " " + contrato.getSigla(), fontCorpo));
        cellValorSubTotal.setBorderWidthBottom(0.5f);
        cellValorSubTotal.setBorderWidthTop(1f);
        cellValorSubTotal.setBorderWidthRight(0.5f);
        cellValorSubTotal.setBorderWidthLeft(0.5f);
        cellValorSubTotal.setHorizontalAlignment(Element.ALIGN_RIGHT);

        pTableSubTotal.addCell(cellTituloSubTotal);
        pTableSubTotal.addCell(cellValorSubTotal);

        PdfPCell cellPagament1 = new PdfPCell(pTableSubTotal);
        cellPagament1.setBorder(0);
        PdfPCell cellPagament2 = new PdfPCell(pTableFomaValores);
        cellPagament2.setBorder(0);
        PdfPCell cellPagament3 = new PdfPCell(pTableTotalPagar);
        cellPagament3.setBorder(0);

        pTableFomaValoresPricipal.addCell(cellPagament1);
        pTableFomaValoresPricipal.addCell(cellPagament2);
        pTableFomaValoresPricipal.addCell(cellPagament3);

        PdfPCell cellPagamentPricipal1 = new PdfPCell(pTableFomaPagamentoPricipal);
        cellPagamentPricipal1.setBorder(0);
        PdfPCell cellPagamentPricipal2 = new PdfPCell(pTableFomaValoresPricipal);
        cellPagamentPricipal2.setBorder(0);

        pTablePrincipalPagamento.addCell(cellPagamentPricipal1);
        pTablePrincipalPagamento.addCell(cellPagamentPricipal2);

        PdfPTable pTableCambio = new PdfPTable(2);
        pTableCambio.setWidthPercentage(95);
        PdfPCell cellTituloCambio1 = new PdfPCell(new Phrase("Cambio", fontCorpoN));
        cellTituloCambio1.setBorder(0);
        cellTituloCambio1.setHorizontalAlignment(Element.ALIGN_CENTER);

        PdfPCell cellTituloCambio2 = new PdfPCell(new Phrase("Total Em Dobras", fontCorpoN));
        cellTituloCambio2.setBorder(0);
        cellTituloCambio2.setHorizontalAlignment(Element.ALIGN_CENTER);

        PdfPCell cellValorCambio = new PdfPCell(new Phrase(
                "1 " + contrato.getSigla() + "= "
                        + Moeda.format(valorCompra(contrato.getDataRegistro(), contrato)) + " " + "STD",
                fontCorpo));
        cellValorCambio.setBorder(0);
        cellValorCambio.setHorizontalAlignment(Element.ALIGN_CENTER);

        DecimalFormat formato = new DecimalFormat("#.##");
        String numero = formato.format(Double.valueOf(contrato.getPremioLiquido()));
        double premioLiquido = Double.valueOf((numero).replace(',', '.'));

        //            System.err.println(taxa + "Taxa * Premio Liquido" + Double.valueOf(contrato.getPremioLiquido()));
        //            System.err.println(taxa + "Taxa * Premio Liquido" + Double.toString(premioLiquido));

        PdfPCell cellValorDobras = new PdfPCell(
                new Phrase(Moeda.format((taxa * premioLiquido)) + " STD", fontCorpo));
        cellValorDobras.setBorder(0);
        cellValorDobras.setHorizontalAlignment(Element.ALIGN_CENTER);

        pTableCambio.addCell(cellTituloCambio1);
        pTableCambio.addCell(cellTituloCambio2);
        pTableCambio.addCell(cellValorCambio);
        pTableCambio.addCell(cellValorDobras);

        PdfPTable pTableData = new PdfPTable(1);
        pTableData.setWidthPercentage(95);
        Paragraph pData = new Paragraph();
        pData.add(new Phrase("Elaborado por ", fontCorpo));
        pData.add(new Phrase(interCodVendedor, fontCorpoN));
        pData.add(new Phrase(" Data ".toUpperCase() + sdf.format(new Date()), fontCorpo));
        PdfPCell cellData = new PdfPCell(pData);
        cellData.setBorder(0);
        cellData.setBorderWidthBottom(0.1f);
        cellData.setHorizontalAlignment(Element.ALIGN_CENTER);

        pTableData.addCell(cellData);

        Document documento = new Document();
        documento.setPageSize(PageSize.A4);
        documento.setMargins(20f, 20f, 70f, 5f);

        String f1 = (arquivo + "/" + user + "/Seguro " + nomeSeguro + "/");
        File f = new File(f1);
        String Ddata = sdf1.format(new Date());
        f.mkdirs();
        f = new File(f.getAbsoluteFile() + "/" + "Nota de Debito " + Ddata + ".pdf");

        reString = "../Documentos/" + user + "/Seguro " + nomeSeguro + "/" + "Nota de Debito " + Ddata + ".pdf";
        OutputStream outputStraem = new FileOutputStream(f);
        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();
        documento.add(pTableEmpresaPricipal);
        documento.add(pTableFatura);
        documento.add(pTableLinha);
        documento.add(pTableLinha);
        documento.add(pTableTitulo);
        documento.add(pTableClientePrincipal);
        documento.add(pTableNull);
        documento.add(TableRegistro);
        documento.add(pTablePrincipalPagamento);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableCambio);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableData);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableNull);
        documento.add(pTableLinha);
        documento.add(pTableLinha);
        documento.close();

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

    return "";
}

From source file:Export.ReciboPagamento.java

public PdfPTable detaDoc(HashMap<String, Object> map, Font fontTitile, Font fontRecibo, Font fontTitileShort,
        Font fontReciboTxt, Font fontConteudo, Font fontConteudoTxt, Font fontConteudoTxtUl)
        throws DocumentException {
    PdfPTable pTablePrincipal = new PdfPTable(new float[] { 100 });
    try {// w  w w  . java  2  s  .  c  o m
        pTablePrincipal.setWidthPercentage(100f);

        PdfPTable pTableTitulo = new PdfPTable(new float[] { 60, 40 });
        pTableTitulo.setWidthPercentage(100);

        PdfPTable pTableTituloImage = new PdfPTable(new float[] { 20, 80 });
        pTableTituloImage.setWidthPercentage(100);

        PdfPCell cellTitulo = new PdfPCell(new Phrase(ConfigDoc.Empresa.NOME, fontTitile));
        cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTitulo.setBorder(0);
        cellTitulo.setPaddingTop(20f);
        cellTitulo.setPaddingLeft(70f);
        pTableTitulo.addCell(cellTitulo);
        cellTitulo = new PdfPCell(new Phrase("Recibo N ".toUpperCase() + map.get(IDAMORTIZACAO), fontRecibo));
        cellTitulo.setVerticalAlignment(Element.ALIGN_BOTTOM);
        cellTitulo.setHorizontalAlignment(Element.ALIGN_RIGHT);
        cellTitulo.setBorder(0);
        pTableTitulo.addCell(cellTitulo);

        cellTitulo = new PdfPCell(new Phrase(ConfigDoc.Empresa.ENDERECO + ", " + ConfigDoc.Empresa.CAIXAPOSTAL
                + ", " + ConfigDoc.Empresa.TELEFAX, fontTitileShort));
        cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTitulo.setPaddingLeft(70f);
        cellTitulo.setBorder(0);
        pTableTitulo.addCell(cellTitulo);
        cellTitulo = new PdfPCell(new Phrase(" ", fontTitileShort));
        cellTitulo.setPaddingBottom(0f);
        cellTitulo.setPaddingTop(0f);
        cellTitulo.setBorder(0);
        pTableTitulo.addCell(cellTitulo);

        cellTitulo = new PdfPCell(new Phrase(ConfigDoc.Empresa.REPUBLICA, fontTitileShort));
        cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTitulo.setBorder(0);
        cellTitulo.setPaddingLeft(70f);
        pTableTitulo.addCell(cellTitulo);
        cellTitulo = new PdfPCell(new Phrase(" ", fontTitileShort));
        cellTitulo.setPaddingBottom(0f);
        cellTitulo.setPaddingTop(0f);
        cellTitulo.setBorder(0);
        pTableTitulo.addCell(cellTitulo);

        cellTitulo = new PdfPCell(new Phrase(ConfigDoc.Empresa.EMAIL, fontTitileShort));
        cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTitulo.setBorder(0);
        cellTitulo.setPaddingLeft(70f);
        pTableTitulo.addCell(cellTitulo);
        cellTitulo = new PdfPCell(new Phrase(" ", fontTitileShort));
        cellTitulo.setPaddingBottom(0f);
        cellTitulo.setPaddingTop(0f);
        cellTitulo.setBorder(0);
        pTableTitulo.addCell(cellTitulo);

        cellTitulo = new PdfPCell(new Phrase("Ordem de receita / recibo".toUpperCase(), fontRecibo));
        cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
        cellTitulo.setBorder(0);
        cellTitulo.setPaddingLeft(70f);
        pTableTitulo.addCell(cellTitulo);
        cellTitulo = new PdfPCell(new Phrase(" ", fontTitileShort));
        cellTitulo.setVerticalAlignment(Element.ALIGN_TOP);
        cellTitulo.setPaddingBottom(30f);
        cellTitulo.setPaddingTop(0f);
        cellTitulo.setBorder(0);
        pTableTitulo.addCell(cellTitulo);

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

        PdfPCell cellImagem = new PdfPCell(imageEmpresa);
        cellImagem.setBorder(PdfPCell.NO_BORDER);
        cellImagem.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        cellImagem.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);

        PdfPCell cellpTableTitulo = new PdfPCell(pTableTitulo);
        cellpTableTitulo.setBorder(PdfPCell.NO_BORDER);
        cellpTableTitulo.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);

        pTableTituloImage.addCell(cellImagem);
        pTableTituloImage.addCell(cellpTableTitulo);

        PdfPCell cellpTableTituloPrincipal = new PdfPCell(pTableTituloImage);
        cellpTableTituloPrincipal.setBorder(PdfPCell.NO_BORDER);

        pTablePrincipal.addCell(cellpTableTituloPrincipal);

        PdfPTable pTableDataCaixaMontante = new PdfPTable(new float[] { 35f, 5f, 60f });
        pTableDataCaixaMontante.setWidthPercentage(100f);

        PdfPCell cellDataCaixaMontante = new PdfPCell(new Phrase(" ", fontRecibo));
        cellDataCaixaMontante.setBorder(0);
        pTableDataCaixaMontante.addCell(cellDataCaixaMontante);
        pTableDataCaixaMontante.addCell(cellDataCaixaMontante);
        cellDataCaixaMontante = new PdfPCell();
        cellDataCaixaMontante.setBorder(0);
        Paragraph p = new Paragraph();
        p.add(new Phrase("Data: ".toUpperCase(), fontRecibo));

        p.add(new Phrase(converterData(map.get(REGISTROAMORTIZACAO), 1), fontReciboTxt));
        p.setAlignment(Element.ALIGN_RIGHT);
        cellDataCaixaMontante.addElement(p);
        cellDataCaixaMontante.setPaddingBottom(5f);
        pTableDataCaixaMontante.addCell(cellDataCaixaMontante);

        cellDataCaixaMontante = new PdfPCell();
        p = new Paragraph();
        p.add(new Phrase("Caixa de: ".toUpperCase(), fontRecibo));
        p.add(new Phrase("So Tom", fontReciboTxt));
        p.setAlignment(Element.ALIGN_LEFT);
        cellDataCaixaMontante.addElement(p);
        cellDataCaixaMontante.setPaddingTop(-2f);
        cellDataCaixaMontante.setPaddingBottom(5f);
        cellDataCaixaMontante.setBorderColor(BaseColor.BLUE.darker().darker().darker());
        pTableDataCaixaMontante.addCell(cellDataCaixaMontante);

        cellDataCaixaMontante = new PdfPCell(new Phrase(" ", fontRecibo));
        cellDataCaixaMontante.setBorder(0);
        pTableDataCaixaMontante.addCell(cellDataCaixaMontante);

        cellDataCaixaMontante = new PdfPCell();
        p = new Paragraph();
        p.add(new Phrase("Montante: ".toUpperCase(), fontRecibo));

        Double montade = Moeda.arrendodamento(toString(map.get(VALORAMORTIZADO)));

        //            SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:");
        Object dRegistro = map.get(DATAREGAPOLICE);
        montade *= valorCompra(map.get(SIGLAMOEDA) + "", dRegistro);

        p.add(new Phrase(converterMoeda(montade, "STD") + "", fontReciboTxt));
        p.setAlignment(Element.ALIGN_LEFT);
        cellDataCaixaMontante.addElement(p);
        cellDataCaixaMontante.setPaddingTop(-2f);
        cellDataCaixaMontante.setPaddingBottom(5f);
        cellDataCaixaMontante.setBorderColor(BaseColor.BLUE.darker().darker().darker());
        pTableDataCaixaMontante.addCell(cellDataCaixaMontante);

        PdfPCell cellDataCaixaMontantePrincipal = new PdfPCell(pTableDataCaixaMontante);
        cellDataCaixaMontantePrincipal.setBorder(PdfPCell.NO_BORDER);

        pTablePrincipal.addCell(cellDataCaixaMontantePrincipal);

        PdfPTable pTableConteudo = new PdfPTable(new float[] { 40, 60 });
        pTableConteudo.setWidthPercentage(100f);
        PdfPCell cellConteudo = new PdfPCell();
        cellConteudo.setBorder(0);

        Paragraph pConteudo = new Paragraph();
        pConteudo.add(new Phrase("N Assegurado: ".toUpperCase(), fontConteudo));
        pConteudo.add(new Phrase(map.get(NUMREGISTRO) + "\n", fontConteudoTxt));

        /**
         * For alter
         */
        pConteudo.add(new Phrase("Prmio Liquido: ".toUpperCase(), fontConteudo));
        pConteudo.add(new Phrase(converterMoeda(map.get(TOTALBRUTO), map.get(SIGLAMOEDA) + "") + "\n",
                fontConteudoTxt));

        pConteudo.add(new Phrase("Impostos: ".toUpperCase(), fontConteudo));
        pConteudo.add(new Phrase(converterMoeda(impostosCalculo(map.get(TOTAl), map.get(IMPOSTOCONSUMO)),
                map.get(SIGLAMOEDA) + "") + "\n", fontConteudoTxt));

        pConteudo.add(new Phrase("Impostos Selo: ".toUpperCase(), fontConteudo));
        pConteudo.add(new Phrase(
                converterMoeda(impostosCalculo(map.get(TOTAl), map.get(IMPOSTOSELO)), map.get(SIGLAMOEDA) + "")
                        + "\n",
                fontConteudoTxt));

        pConteudo.add(new Phrase("FGA: ", fontConteudo));
        pConteudo.add(new Phrase(
                converterMoeda(impostosCalculo(map.get(TOTAl), map.get(MOTORFOUND)), map.get(SIGLAMOEDA) + "")
                        + "\n",
                fontConteudoTxt));

        pConteudo.add(new Phrase("Total: ".toUpperCase(), fontConteudo));
        pConteudo.add(
                new Phrase(converterMoeda(map.get(TOTAl), map.get(SIGLAMOEDA) + "") + "\n", fontConteudoTxt));

        pConteudo.add(new Phrase("Efeito: ".toUpperCase(), fontConteudo));
        pConteudo.add(new Phrase(converterData(map.get(EFEITO), 1) + "\n", fontConteudoTxt));

        pConteudo.add(new Phrase("Vencimento: ".toUpperCase(), fontConteudo));
        pConteudo.add(new Phrase(converterData(map.get(VENCIMENTO), 1) + "\n", fontConteudoTxt));

        cellConteudo.addElement(pConteudo);
        pTableConteudo.addCell(cellConteudo);

        cellConteudo = new PdfPCell();
        cellConteudo.setBorder(0);

        pConteudo = new Paragraph();
        pConteudo.add(new Phrase("Recebido do Sr: ".toUpperCase(), fontConteudo));
        pConteudo.add(new Phrase(map.get(CLIENTE) + "\n", fontConteudoTxt));

        PdfPTable pTableNomeCod = new PdfPTable(new float[] { 70, 30 });
        pTableNomeCod.setWidthPercentage(100);

        Paragraph pNomeCod = new Paragraph();
        pNomeCod.add(new Phrase("Nome do Assegurado/Pagador: ".toUpperCase(), fontConteudo));
        pNomeCod.add(new Phrase(map.get(CLIENTE) + "", fontConteudoTxt));
        PdfPCell cellNomeCod = new PdfPCell();
        cellNomeCod.addElement(pNomeCod);
        cellNomeCod.setBorder(0);
        cellNomeCod.setPaddingTop(-2f);
        cellNomeCod.setPaddingBottom(2f);
        pTableNomeCod.addCell(cellNomeCod);

        cellNomeCod = new PdfPCell();
        pNomeCod = new Paragraph();
        pNomeCod.add(new Phrase("Codigo: ".toUpperCase(), fontConteudo));
        pNomeCod.add(new Phrase(" ", fontConteudoTxt));
        cellNomeCod.addElement(pNomeCod);
        cellNomeCod.setBorder(0);
        cellNomeCod.setPaddingTop(-2f);
        cellNomeCod.setPaddingBottom(2f);
        pTableNomeCod.addCell(cellNomeCod);

        pNomeCod = new Paragraph();
        pNomeCod.add(new Phrase("Nome do Intermedirio: ".toUpperCase(), fontConteudo));
        pNomeCod.add(new Phrase(" ", fontConteudoTxt));
        cellNomeCod = new PdfPCell();
        cellNomeCod.addElement(pNomeCod);
        cellNomeCod.setBorder(0);
        cellNomeCod.setPaddingTop(-2f);
        cellNomeCod.setPaddingBottom(2f);
        pTableNomeCod.addCell(cellNomeCod);

        cellNomeCod = new PdfPCell();
        pNomeCod = new Paragraph();
        pNomeCod.add(new Phrase("Codigo: ".toUpperCase(), fontConteudo));
        pNomeCod.add(new Phrase(" ", fontConteudoTxt));
        cellNomeCod.addElement(pNomeCod);
        cellNomeCod.setBorder(0);
        cellNomeCod.setPaddingTop(-2f);
        cellNomeCod.setPaddingBottom(2f);
        pTableNomeCod.addCell(cellNomeCod);

        pConteudo.add(pTableNomeCod);

        JTextPane jtp = new JTextPane();
        Double valor = Moeda.arrendodamento((map.get(VALORPRESTACAO) + ""));
        valor *= valorCompra(map.get(SIGLAMOEDA) + "", dRegistro);
        Moeda.EscreverEstenso(valor, jtp, "Dobras");

        pConteudo.add(new Phrase("A soma (por extenso) ".toUpperCase(), fontConteudo));
        pConteudo.add(new Phrase(jtp.getText().trim() + "\n", fontConteudoTxt));

        PdfPTable pTableApoliceDatasP = new PdfPTable(new float[] { 20, 80 });
        pTableApoliceDatasP.setWidthPercentage(100);
        PdfPTable pTableApoliceDatas = new PdfPTable(new float[] { 60, 40 });
        pTableApoliceDatas.setWidthPercentage(100);

        for (int i = 0; i < 1; i++) {
            PdfPCell cellApolice = new PdfPCell();
            Paragraph pApolice = new Paragraph();
            pApolice.add(new Phrase("N ", fontConteudo));
            pApolice.add(new Phrase(map.get(APOLICA) + "", fontConteudoTxt));
            cellApolice.addElement(pApolice);
            cellApolice.setPaddingTop(-2f);
            cellApolice.setPaddingBottom(2f);
            cellApolice.setBorder(0);
            pTableApoliceDatas.addCell(cellApolice);

            PdfPCell cellDatas = new PdfPCell();
            Paragraph pDatas = new Paragraph();
            pDatas.add(new Phrase("Data: ".toUpperCase(), fontConteudo));
            pDatas.add(new Phrase(converterData(map.get(DATAREGAPOLICE), 2) + "", fontConteudoTxt));
            cellDatas.addElement(pDatas);
            cellDatas.setBorder(0);
            cellDatas.setPaddingTop(-2f);
            cellDatas.setPaddingBottom(2f);
            pTableApoliceDatas.addCell(cellDatas);
        }
        PdfPCell cellApoliceP = new PdfPCell(new Phrase("Apolices".toUpperCase(), fontConteudo));
        cellApoliceP.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cellApoliceP.setBorder(0);
        pTableApoliceDatasP.addCell(cellApoliceP);
        cellApoliceP = new PdfPCell(pTableApoliceDatas);
        cellApoliceP.setBorder(0);
        pTableApoliceDatasP.addCell(cellApoliceP);

        pConteudo.add(pTableApoliceDatasP);
        //            
        PdfPTable pTableTipoPagemento = new PdfPTable(new float[] { 70f, 30f });
        pTableTipoPagemento.setWidthPercentage(100f);

        PdfPCell cellTipoPageme = new PdfPCell();
        Paragraph pDatas = new Paragraph();
        pDatas.add(new Phrase("Pagamento: ".toUpperCase(), fontConteudo));
        pDatas.add(new Phrase(map.get(TIPOPAGAMENTO) + " ", fontConteudoTxt));
        cellTipoPageme.addElement(pDatas);
        cellTipoPageme.setBorder(0);
        cellTipoPageme.setPaddingTop(-2f);
        cellTipoPageme.setPaddingBottom(2f);
        //           cellTipoPageme.setBorderColor(BaseColor.BLUE.darker().darker().darker());
        //           cellTipoPageme.setBorderWidthTop((i==0)?0.5f:0f);
        //           cellTipoPageme.setBorderWidthBottom(0.5f);
        pTableTipoPagemento.addCell(cellTipoPageme);

        cellTipoPageme = new PdfPCell();
        pDatas = new Paragraph();
        pDatas.add(new Phrase("N ".toUpperCase(), fontConteudo));
        pDatas.add(new Phrase(toString(map.get(DOCUMENTOAMORTIZACAO)) + " ", fontConteudoTxt));
        cellTipoPageme.addElement(pDatas);
        cellTipoPageme.setBorder(0);
        cellTipoPageme.setPaddingTop(-2f);
        cellTipoPageme.setPaddingBottom(2f);
        //                cellTipoPageme.setBorderColor(BaseColor.BLUE.darker().darker().darker());
        //                cellTipoPageme.setBorderWidthTop((i==0)?0.5f:0f);
        //                cellTipoPageme.setBorderWidthBottom(0.5f);
        pTableTipoPagemento.addCell(cellTipoPageme);

        pConteudo.add(pTableTipoPagemento);

        cellConteudo.addElement(pConteudo);
        pTableConteudo.addCell(cellConteudo);

        PdfPCell cellConteudoPrincipal = new PdfPCell(new PdfPTable(pTableConteudo));
        cellConteudoPrincipal.setBorder(PdfPCell.NO_BORDER);
        pTablePrincipal.addCell(cellConteudoPrincipal);

        PdfPTable pTableAssinatura = new PdfPTable(new float[] { 50f, 50f });
        pTableAssinatura.setWidthPercentage(100f);

        Font fontConteudoTxt_acess = FontFactory.getFont(ConfigDoc.Fontes.FONT, BaseFont.WINANSI,
                BaseFont.EMBEDDED, 5f, Font.ITALIC, BaseColor.BLACK.darker().darker().darker());
        Font fontConteudo_acess = FontFactory.getFont(ConfigDoc.Fontes.FONTB, BaseFont.WINANSI,
                BaseFont.EMBEDDED, 5f, Font.NORMAL, BaseColor.BLUE.darker().darker());

        PdfPCell cellAcessorio = new PdfPCell();
        Paragraph pAcessorio = new Paragraph();
        pAcessorio.add(new Phrase("Acessrios: ".toUpperCase(), fontConteudo_acess));
        pAcessorio.add(new Phrase(
                (map.get(ACCESSORIO) == null) ? " " : (map.get(ACCESSORIO) + "").replaceAll("\n", " "),
                fontConteudoTxt_acess));
        cellAcessorio.addElement(pAcessorio);
        cellAcessorio.setColspan(2);
        cellAcessorio.setBorder(0);
        cellAcessorio.setPaddingBottom(4f);
        cellAcessorio.setPaddingTop(-2f);
        pTableAssinatura.addCell(cellAcessorio);

        PdfPCell cellLinhaAssina = new PdfPCell();
        Paragraph pAssinatura = new Paragraph();
        pAssinatura.add(new Paragraph("_________________________________", fontConteudo));
        pAssinatura.add(new Paragraph("                Carimbo e Assinatura", fontConteudo));
        pAssinatura.setAlignment(Element.ALIGN_CENTER);
        cellLinhaAssina.addElement(pAssinatura);
        cellLinhaAssina.setPaddingBottom(2f);
        cellLinhaAssina.setBorder(0);
        cellLinhaAssina.setPaddingTop(25f);
        pTableAssinatura.addCell(cellLinhaAssina);

        PdfPCell cellCambio = new PdfPCell();
        Paragraph pCombio = new Paragraph();
        pCombio.add(new Phrase("Cambio (USD): ".toUpperCase(), fontConteudo));
        pCombio.add(new Phrase(converterMoeda(valorCompra("USD", dRegistro), "") + "\n", fontConteudoTxt));
        pCombio.add(new Phrase("Cambio (EUR): ".toUpperCase(), fontConteudo));
        pCombio.add(new Phrase(converterMoeda(valorCompra("EUR", dRegistro), "") + "\n", fontConteudoTxt));
        cellCambio.addElement(pCombio);
        cellCambio.setBorder(0);
        cellCambio.setPaddingTop(-2f);
        cellCambio.setPaddingBottom(2f);
        pTableAssinatura.addCell(cellCambio);

        PdfPCell cellpTableAssinaturaPrincipal = new PdfPCell(pTableAssinatura);
        cellpTableAssinaturaPrincipal.setBorder(PdfPCell.NO_BORDER);
        pTablePrincipal.addCell(new PdfPCell(cellpTableAssinaturaPrincipal));

        //            pTableAssinatura.writeSelectedRows(-1, 2, 10, 70, writer.getDirectContent());
        //            pTableImagem.writeSelectedRows(-1, 2, 52.5f, 402.5f, writer.getDirectContent());
    } catch (BadElementException | IOException ex) {
        Logger.getLogger(ReciboPagamento.class.getName()).log(Level.SEVERE, null, ex);
    }
    return pTablePrincipal;
}

From source file:femr.ui.controllers.PDFController.java

License:Open Source License

/**
 * Builds the page header - Title and Empty cell (for border)
 *
 * @return PdfPTable the itext table to add to the document
 *///from   www  .  j  a v  a 2 s .c  o m
public PdfPTable createHeaderTable() {

    PdfPTable table = new PdfPTable(2);
    table.setSpacingAfter(10);
    table.setWidthPercentage(100);

    Paragraph title = new Paragraph("Medical Record", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD));
    PdfPCell cell = new PdfPCell(title);
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderWidthBottom(1);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    //Paragraph encounterId = new Paragraph("Encounter ID: " + patientEncounter.getId(), new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.NORMAL));
    cell = new PdfPCell(table.getDefaultCell());
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    cell.setBorder(PdfPCell.NO_BORDER);
    cell.setBorderColorBottom(BaseColor.BLACK);
    cell.setBorderWidthBottom(1);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setPaddingBottom(5);
    table.addCell(cell);

    return table;
}