Example usage for com.itextpdf.text Phrase getFont

List of usage examples for com.itextpdf.text Phrase getFont

Introduction

In this page you can find the example usage for com.itextpdf.text Phrase getFont.

Prototype

public Font getFont() 

Source Link

Document

Gets the font of the first Chunk that appears in this Phrase.

Usage

From source file:EplanPrinter.PDFPrint.java

License:Open Source License

public String insertStamp(String loc, float x, float y, int width, int height, int set, String date,
        int pageNum, int masterHeight, int masterWidth, String projNo)
        throws BadElementException, MalformedURLException, IOException, DocumentException {
    Image image = Image.getInstance(loc);
    float[] scalar = scale(x, y, width, height, masterHeight, masterWidth, pageNum);
    float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight,
            masterWidth, pageNum);//  w  ww.  j ava2  s  .  co m
    float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum);

    float shift = 0;

    /* Addition. ftorres - 7/22/2015 - Added to account for rotated pages 
     *   with the origin (0,0) not set to the bottom-left of the page. [1400] */
    trans = translateRotation(trans[0], trans[1], pageNum);

    if (set == 1) {
        float m = image.getPlainHeight();
        float pageChunk = r[pageNum - 1].getHeight() / 10;
        shift = r[pageNum - 1].getHeight() / 100;
        scalar[1] = (int) (pageChunk);
        scalar[0] = (int) (image.getPlainWidth() * pageChunk) / image.getPlainHeight();
        trans[0] = (int) (0 + (pageChunk * widthScalar));
        trans[1] = (int) (r[pageNum - 1].getHeight() - (pageChunk * heightScalar)
                - (shift * (heightScalar + 2)));
        heightScalar = heightScalar + 1;
        if (heightScalar == 8) {
            heightScalar = 0;
            widthScalar = widthScalar + 2;
        }
    }

    if (set == 1) {
        image.setAbsolutePosition(trans[0] + shift, trans[1] - scalar[1]);
        image.scaleAbsoluteHeight(scalar[1]);
        image.scaleAbsoluteWidth(scalar[0]);
        image.setRotationDegrees(rot);
    } else {
        //swap stamp dimensions for rotated drawings
        if (rot > 0) {
            image.setAbsolutePosition(trans[0] - 2 * scalar[1], trans[1] - 2 * scalar[0]);
        } else {
            image.setAbsolutePosition(trans[0], trans[1] - 2 * scalar[1]);
        }
        image.scaleAbsoluteHeight(scalar[1] * 2);
        image.scaleAbsoluteWidth(scalar[0] * 2);
        image.setRotationDegrees(rot);
    }

    PdfContentByte fg = pds.getOverContent(pageNum);
    fg.addImage(image);

    //Added by tmittelstadt on 09/21/2012 for ticket #698
    //draws a box around the date
    fg.setColorFill(BaseColor.WHITE);
    fg.setLineWidth(0f);

    //dmoody removed box.  ticket 900
    /*fg.moveTo(trans[0], trans[1] - scalar[1] * 2);
       fg.lineTo(trans[0], trans[1] - scalar[1] * 2 - 10);
       fg.lineTo(trans[0] + scalar[0] * 2, trans[1] - scalar[1] * 2 - 10);
       fg.lineTo(trans[0] + scalar[0] * 2, trans[1] - scalar[1] * 2);
       fg.lineTo(trans[0], trans[1] - scalar[1] * 2);*/

    fg.closePathFillStroke();
    fg.fill();

    //adds the date the stamp was added to the document to the pdf
    Phrase p = new Phrase(date);
    p.getFont().setColor(BaseColor.BLACK);
    //Modification zreeve 10/11/2012.  set font size to 11.
    p.getFont().setSize(9f);
    //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id));
    ColumnText.showTextAligned(fg, Element.ALIGN_CENTER, p, (float) (trans[0]),
            (float) (trans[1] - scalar[1] * 2 - 12), 0);
    Phrase pn = new Phrase("#[" + projNo + "]");
    pn.getFont().setColor(BaseColor.BLACK);
    pn.getFont().setSize(10f);
    pn.getFont().setStyle("bold");
    ColumnText.showTextAligned(fg, Element.ALIGN_CENTER, pn, (float) (trans[0]),
            (float) (trans[1] - scalar[1] * 2 - 22), 0);

    return "";
}

From source file:EplanPrinter.PDFPrint.java

License:Open Source License

public String insertComment(String sx, String sy, String id, String deptValue, String userInit, String comment,
        int pageNum, int masterHeight, int masterWidth, int pinned, int customFontSize)
        throws DocumentException, IOException {
    float ratio = getRatio(masterHeight, masterWidth, pageNum);
    float x = Float.parseFloat(sx);
    float y = Float.parseFloat(sy);
    float[] f = commentTrans(x, y, masterHeight, masterWidth, pageNum);
    PdfGState gs1 = new PdfGState();
    gs1.setFillOpacity(1);//w ww.j  a  va 2 s .c om
    if (customFontSize > 0)
        fontSize = customFontSize;

    PdfContentByte fg = pds.getOverContent(pageNum);
    fg.setGState(gs1);
    BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
    float[] trans = translate(x, y, r[pageNum - 1].getHeight(), r[pageNum - 1].getWidth(), masterHeight,
            masterWidth, pageNum);
    // comment tag image (width=35pts, height=8pts)
    float[] scalar = scale(trans[0], trans[1], 35, 8, masterHeight, masterWidth, pageNum);

    /* Addition. ftorres - 7/21/2015 - Added to account for rotated pages 
     *   with the origin (0,0) not set to the bottom-left of the page. [1400] */
    float coords[] = translateRotation(trans[0], trans[1], pageNum);
    coords = checkBounds(coords[0], coords[1], pageNum);

    /* Addition. ftorres - 10/20/2015 - If the comment was pinned in EPC, then
     *   render the comment inside a comment box. */
    if (pinned == 1) {
        insertPinnedComment(coords[0], coords[1], id + " - " + deptValue + " (" + userInit + ")", comment,
                pageNum, masterHeight, masterWidth);

        // Add the pinned comment text to page annotation -Jon Changkachith 11/24/2015
        Rectangle rect = new Rectangle(0, 0, 0, 0);
        PdfAnnotation annotation = PdfAnnotation.createText(pds.getWriter(), rect,
                id + " - " + deptValue + " (" + userInit + ")", cleanupComment(comment), true, id);
        pds.addAnnotation(annotation, pds.getWriter().getCurrentPageNumber());
    } else {
        Image image = Image.getInstance(commentIMGPath);
        image.setAbsolutePosition(coords[0] + (scalar[0] * (id.length() / 5f)), coords[1]);

        /*
         * Commented out by Jon Changkachith 12/09/2015 because it was throwing
         * DocumentException with the message "The image must have absolute positioning."
        image.scaleAbsoluteHeight(1);
        image.scaleAbsoluteWidth(1);
        */
        image.scalePercent(ratio); //Added to fix DocumentException "The image must have absolute positioning." Jon Changkachith 12/09/2015
        image.setAnnotation(new Annotation(id + " - " + deptValue + " (" + userInit + ")",
                cleanupComment(comment), 0, 0, 0, 0));
        fg.addImage(image);
    }

    fg.setLineWidth(.5f * ratio);
    fg.setColorStroke(new BaseColor(Color.decode("0x6E2405").getRGB()));
    fg.setColorFill(new BaseColor(Color.decode("0x6E2405").getRGB()));

    float tHeight = scalar[1];
    float tWidth = 0;
    if (id.length() > 3) {
        tWidth = (scalar[0] * (id.length() / 5f));
    } else {
        tWidth = (scalar[0]);
    }

    fg.moveTo(coords[0], coords[1]);
    fg.lineTo(coords[0] + (10f * ratio), coords[1] - (tHeight / 2));
    fg.lineTo(coords[0] + tWidth, coords[1] - (tHeight / 2));
    fg.lineTo(coords[0] + tWidth, coords[1] + (tHeight / 2));
    fg.lineTo(coords[0] + (10f * ratio), coords[1] + (tHeight / 2));

    fg.lineTo(coords[0], coords[1]);
    fg.closePathFillStroke();
    fg.fill();

    // Comment number that goes on the comment tag image
    Phrase p = new Phrase(id);
    p.getFont().setColor(BaseColor.WHITE);
    p.getFont().setSize(8f * ratio); //comment number font size = 8f
    //p.getChunks().get(0).setAnnotation(PdfAnnotation.createText(pds.getWriter(), new Rectangle(trans[0],trans[1], trans[0]+5f, trans[1]+5f), id, comment, true, id));

    float fs[] = translateRotation(f[0], f[1], pageNum);
    fs = checkBounds(fs[0], fs[1], pageNum);
    ColumnText.showTextAligned(fg, Element.ALIGN_LEFT, p, (float) (fs[0] + (9 * ratio)),
            (float) (fs[1] - (3 * ratio)), 0);

    return "";
}

From source file:Export.SeguroMaritimo.java

public String criarDoc(String numApolice, String numCliente, MaritimoBean mb, Contrato c, String user,
        String moeda, String arquivo) {
    try {//from   w w  w  . ja v  a  2s .  com
        SimpleDateFormat sdf = new SimpleDateFormat("dd 'de' MMMM 'de' yyyy", new Locale("pt", "BR"));
        SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MM-yyyy hh'.'mm'.'ss");

        Font fontCabecalhoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 9.5f);
        Font fontCorpo = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f);
        Font fontCorpoP = FontFactory.getFont(Fontes.FONT, BaseFont.WINANSI, BaseFont.EMBEDDED, 7f);
        Font fontCorpoN = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8f);
        Font fontCorpoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 8.5f);
        Font fontCabecalhoNG = FontFactory.getFont(Fontes.FONTB, BaseFont.WINANSI, BaseFont.EMBEDDED, 16f,
                Font.UNDERLINE);

        PdfPTable pTableEmpresaPricipal = new PdfPTable(new float[] { 25f, 75f });
        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);
        pCellPolice.setBorder(0);

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

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

        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);
        PdfPTable pTableCliente = new PdfPTable(1);

        PdfPTable pTableTitulo = new PdfPTable(1);
        Phrase pTitulo = new Phrase("Formulario de SEguro Maritimo".toUpperCase());
        pTitulo.getFont().setStyle(Font.BOLD);
        pTitulo.getFont().setFamily(Font.FontFamily.COURIER.name());
        PdfPCell cellTitulo = new PdfPCell(pTitulo);
        cellTitulo.setBorder(0);
        cellTitulo.setHorizontalAlignment(Element.ALIGN_CENTER);
        pTableTitulo.addCell(cellTitulo);

        ClienteI ci = new ClienteI(numCliente);
        PdfPCell cellTituloTsbleSegurado = new PdfPCell(
                new Phrase("1 - Informaes Cliente".toUpperCase(), fontCorpoNG));
        cellTituloTsbleSegurado.setBorder(0);

        Paragraph pCl = new Paragraph();
        pCl.add(new Phrase("   " + ci.getNOMEL_(), fontCorpo));
        pCl.add(new Phrase(ci.getNOME_(), fontCorpoN));
        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));
        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));
        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));
        PdfPCell cellLocalTrabalho = new PdfPCell(pCl);
        cellLocalTrabalho.setBorder(0);

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

        PdfPCell cellTiltuloSegro = new PdfPCell(
                new Phrase("3 - Montante Segurado/Limete de Responsabilidade".toUpperCase(), fontCorpoNG));
        cellTiltuloSegro.setBorder(0);
        PdfPCell cellApolice = new PdfPCell(
                new Phrase("   N Aplice: ".toUpperCase() + numApolice, fontCorpo));
        cellApolice.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.setBorder(0);
        PdfPCell cellDataNota = new PdfPCell(new Phrase(
                "   Ambas as datas incluidas, para os periodos adicionados que possam ser mutuamente acordadas"
                        .toUpperCase(),
                fontCorpo));
        cellDataNota.setBorder(0);
        PdfPCell cellCorpoMotor = new PdfPCell(new Phrase(
                "   Para Corpo e o motor (Excluindo risco de guerra): ".toUpperCase() + c.getPrimeiroPremio(),
                fontCorpo));
        cellCorpoMotor.setBorder(0);
        PdfPCell cellParaTerceiro = new PdfPCell(
                new Phrase("   Para terceiros/responsabilidade civil: ", fontCorpo));
        cellParaTerceiro.setBorder(0);
        PdfPCell cellAcidentePessoal = new PdfPCell(
                new Phrase("   Para acidente pessoal ao condutor: ", fontCorpo));
        cellAcidentePessoal.setBorder(0);
        PdfPCell cellTotalPremioAnual = new PdfPCell(
                new Phrase("   Valor Premio Anual: ".toUpperCase() + c.getPremioAnual(), fontCorpo));
        cellTotalPremioAnual.setBorder(0);

        pTableSeguro.addCell(cellTiltuloSegro);
        pTableSeguro.addCell(cellApolice);
        pTableSeguro.addCell(cellPeriodo);
        pTableSeguro.addCell(cellDataNota);
        pTableSeguro.addCell(cellCorpoMotor);
        pTableSeguro.addCell(cellParaTerceiro);
        pTableSeguro.addCell(cellAcidentePessoal);
        pTableSeguro.addCell(cellTotalPremioAnual);

        PdfPTable pTableDadosTitulo = new PdfPTable(1);
        PdfPCell cellDadosTitulo = new PdfPCell(new Phrase());
        cellDadosTitulo.setBorder(0);
        Paragraph pInfoTitulo = new Paragraph("2 - Informaes do(s) Navio(s)".toUpperCase(), fontCorpoN);
        Paragraph pInfoShip = new Paragraph(
                "   1. Navio/Embarcao: ".toUpperCase() + mb.getMaritimo().getNomeNavio(), fontCorpo);
        Paragraph pInfo1 = new Paragraph("      A)MARCA/MODELO (CASSI: ) " + mb.getMaritimo().getMarcaModelo()
                + "/" + mb.getMaritimo().getMarcaMotor(), fontCorpo);
        Paragraph pInfo2 = new Paragraph("   2. TIPO DE CONSTRUO DO NAVIO (i.e Material usado) "
                + mb.getMaritimo().getTipoConstrucao(), fontCorpo);
        Paragraph pInfo3 = new Paragraph("   3. TIPO DE NAVIO: " + mb.getMaritimo().getTipoNavio(), fontCorpo);
        Paragraph pInfo4 = new Paragraph(
                "   4. IDADE DO NAVIO (ano de construo): " + mb.getMaritimo().getIdadeNavio(), fontCorpo);
        Paragraph pInfo5 = new Paragraph(
                "   5. CONDIO ACTUAL DO NAVIO: " + mb.getMaritimo().getCondicaoAtual(), fontCorpo);
        Paragraph pInfo6 = new Paragraph("   6. RELATRIO DE MANUTEMO DOS PROPRIET?RIOS DO NAVIO: ",
                fontCorpo);
        Paragraph pInfo7 = new Paragraph(
                "   7. CLASSE DE ESTATUTO DE RENOVAO: " + mb.getMaritimo().getClasseRenovacao(), fontCorpo);
        Paragraph pInfo8 = new Paragraph("   8. BANDEIRA DO NAVIO: " + mb.getMaritimo().getBandeiraNavio(),
                fontCorpo);
        Paragraph pInfo9 = new Paragraph(
                "   9. USO A QUE SE DISTINA O NAVIO OU COMRCIO: " + mb.getMaritimo().getUsoNavio(),
                fontCorpo);
        Paragraph pInfo10 = new Paragraph("   10. QUANTIDADE/PESO DO " + mb.getMaritimo().getNomeNavio() + " : "
                + mb.getMaritimo().getPeso() + " (LIQUIDO E BRUTO):VER NO RELATRIO", fontCorpo);
        Paragraph pInfo11 = new Paragraph("   11. POTNCIA DO MOTOR", fontCorpo);
        Paragraph pInfo12 = new Paragraph(
                "   12. TIPO DE COMBUST?VEL DO MOTOR DE PROPULSAO: " + mb.getMaritimo().getTipoCombustivel(),
                fontCorpo);
        Paragraph pInfo13 = new Paragraph("   13. NMERO DO MOTOR: " + mb.getMaritimo().getNumMotor(),
                fontCorpo);
        Paragraph pInfo14 = new Paragraph("   14. MARCA DO MOTOR: " + mb.getMaritimo().getMarcaMotor(),
                fontCorpo);
        Paragraph pInfo15 = new Paragraph(
                "   15. NMERO M?XIMO DE TRIPULANTES: " + mb.getMaritimo().getNumMaximoTripulante(),
                fontCorpo);
        Paragraph pInfo16 = new Paragraph("   16. DISPOSITIVOS DE SALVAMENTO SUFICIENTE PARA UM M?XIMO: ",
                fontCorpo);
        Paragraph pInfo17 = new Paragraph("   17. APOIOS PARA NAVEGAO INSTALADOS: "
                + mb.getMaritimo().getEspecificacaoApoioNavegacao(), fontCorpo);
        Paragraph pInfo18 = new Paragraph(
                "   18. EXPERINCIA ANTERIOR DE RECLAMAO: " + mb.getMaritimo().getExperienciaRecalmacao(),
                fontCorpo);
        Paragraph pInfo19 = new Paragraph("   19. MBITO DA COBERTURA: ", fontCorpo);
        Paragraph pInfo20 = new Paragraph(
                "   20. LIMITAO TERRITORIAL/?REA DE OERAO: " + mb.getMaritimo().getAreaOperacao(),
                fontCorpo);
        Paragraph pInfo21 = new Paragraph("          DATA: " + sdf.format(new Date()), fontCorpo);
        cellDadosTitulo.addElement(pInfoTitulo);
        cellDadosTitulo.addElement(pInfoShip);
        cellDadosTitulo.addElement(pInfo1);
        cellDadosTitulo.addElement(pInfo2);
        cellDadosTitulo.addElement(pInfo3);
        cellDadosTitulo.addElement(pInfo4);
        cellDadosTitulo.addElement(pInfo5);
        cellDadosTitulo.addElement(pInfo6);
        cellDadosTitulo.addElement(pInfo7);
        cellDadosTitulo.addElement(pInfo8);
        cellDadosTitulo.addElement(pInfo9);
        cellDadosTitulo.addElement(pInfo10);
        cellDadosTitulo.addElement(pInfo11);
        cellDadosTitulo.addElement(pInfo12);
        cellDadosTitulo.addElement(pInfo13);
        cellDadosTitulo.addElement(pInfo14);
        cellDadosTitulo.addElement(pInfo15);
        cellDadosTitulo.addElement(pInfo16);
        cellDadosTitulo.addElement(pInfo17);
        cellDadosTitulo.addElement(pInfo18);
        cellDadosTitulo.addElement(pInfo19);
        cellDadosTitulo.addElement(pInfo20);
        cellDadosTitulo.addElement(pInfo21);
        pTableDadosTitulo.addCell(cellDadosTitulo);

        PdfPTable pTableAssinaturaTitulo = new PdfPTable(1);
        PdfPTable pTableAssinatura = new PdfPTable(new float[] { 50f, 50f });
        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 Maritimo\\");
        //            ff.mkdirs();
        //            ff =new File(ff.getAbsoluteFile()+"\\"+"Formulario Seguro Maritimo "+sdf1.format(new Date())+".pdf");
        File ff = new File(arquivo + "/" + user + "/Seguro Maritimo/");

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

        reString = "../Documentos/" + user + "/Seguro Maritimo/" + "Formulario Seguro Maritimo " + 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);
        }

        documento.open();
        documento.add(pTableEmpresaPricipal);
        documento.add(pTableNull);
        documento.add(pTableTitulo);
        documento.add(pTableNull);
        documento.add(pTableCliente);
        documento.add(pTableNull);
        documento.add(pTableDadosTitulo);
        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

private Phrase createCleanPhrase(String txt1, float fontSize1, boolean bold1) {
    Phrase phrase = new Phrase(txt1);
    phrase.getFont().setSize(fontSize1);
    if (bold1) {/*from   w  w  w  . j  a  va 2 s  .c o  m*/
        phrase.getFont().setStyle(Font.BOLD);
        phrase.setLeading(fontSize1);
    }

    return phrase;
}

From source file:org.spinsuite.print.ReportPrintData.java

License:Open Source License

/**
 * Create a PDF File//w w w .ja v a2s  .co m
 * @author Yamel Senih, ysenih@erpcya.com, ERPCyA http://www.erpcya.com 02/04/2014, 22:52:09
 * @param outFile
 * @throws FileNotFoundException
 * @throws DocumentException
 * @return void
 */
private void createPDF(File outFile) throws FileNotFoundException, DocumentException {
    Document document = new Document(PageSize.LETTER);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outFile));
    PDFHeaderAndFooter event = new PDFHeaderAndFooter();
    writer.setPageEvent(event);
    document.open();
    //   
    document.addAuthor(ctx.getResources().getString(R.string.app_name));
    document.addCreationDate();
    //   
    Paragraph title = new Paragraph(m_reportQuery.getInfoReport().getName());
    //   Set Font
    title.getFont().setStyle(Font.BOLD);
    //   Set Alignment
    title.setAlignment(Paragraph.ALIGN_CENTER);
    //   Add Title
    document.add(title);
    //   Add New Line
    document.add(Chunk.NEWLINE);
    //   Parameters
    ProcessInfoParameter[] param = m_pi.getParameter();
    //   Get Parameter
    if (param != null) {
        //   
        boolean isFirst = true;
        //   Iterate
        for (ProcessInfoParameter para : param) {
            //   Get SQL Name
            String name = para.getInfo();
            StringBuffer textParameter = new StringBuffer();
            if (para.getParameter() == null && para.getParameter_To() == null)
                continue;
            else {
                //   Add Parameters Title
                if (isFirst) {
                    Paragraph titleParam = new Paragraph(
                            ctx.getResources().getString(R.string.msg_ReportParameters));
                    //   Set Font
                    titleParam.getFont().setStyle(Font.BOLDITALIC);
                    //   Add to Document
                    document.add(titleParam);
                    isFirst = false;
                }
                //   Add Parameters Name
                if (para.getParameter() != null && para.getParameter_To() != null) { //   From and To is filled
                    //   
                    textParameter.append(name).append(" => ").append(para.getDisplayValue()).append(" <= ")
                            .append(para.getDisplayValue_To());
                } else if (para.getParameter() != null) { //   Only From
                    //   
                    textParameter.append(name).append(" = ").append(para.getDisplayValue());
                } else if (para.getParameter_To() != null) { //   Only To
                    //   
                    textParameter.append(name).append(" <= ").append(para.getDisplayValue_To());
                }
            }
            //   Add to Document
            Paragraph viewParam = new Paragraph(textParameter.toString());
            document.add(viewParam);
        }
    }
    document.add(Chunk.NEWLINE);
    //   
    InfoReportField[] columns = m_reportQuery.getColumns();
    //   Add Table
    PdfPTable table = new PdfPTable(columns.length);
    table.setSpacingBefore(4);
    //   Add Header
    PdfPCell headerCell = new PdfPCell(new Phrase(m_reportQuery.getInfoReport().getName()));
    headerCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    headerCell.setColspan(columns.length);
    //   Add to Table
    table.addCell(headerCell);
    //   Add Header
    //   Decimal and Date Format
    DecimalFormat[] cDecimalFormat = new DecimalFormat[columns.length];
    SimpleDateFormat[] cDateFormat = new SimpleDateFormat[columns.length];
    for (int i = 0; i < columns.length; i++) {
        InfoReportField column = columns[i];
        //   Only Numeric
        if (DisplayType.isNumeric(column.DisplayType))
            cDecimalFormat[i] = DisplayType.getNumberFormat(ctx, column.DisplayType, column.FormatPattern);
        //   Only Date
        else if (DisplayType.isDate(column.DisplayType))
            cDateFormat[i] = DisplayType.getDateFormat(ctx, column.DisplayType, column.FormatPattern);
        //   
        Phrase phrase = new Phrase(column.PrintName);
        PdfPCell cell = new PdfPCell(phrase);
        if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        else
            cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
        //   
        table.addCell(cell);
    }
    //   Add Detail
    for (int row = 0; row < m_data.size(); row++) {
        //   Get Row
        RowPrintData rPrintData = m_data.get(row);
        //   Iterate
        for (int col = 0; col < columns.length; col++) {
            InfoReportField column = columns[col];
            ColumnPrintData cPrintData = rPrintData.get(col);
            Phrase phrase = null;
            PdfPCell cell = new PdfPCell();
            //   
            String value = cPrintData.getValue();
            //   Only Values
            if (value != null) {
                if (DisplayType.isNumeric(column.DisplayType)) { //   Number
                    //   Format
                    DecimalFormat decimalFormat = cDecimalFormat[col];
                    //   Format
                    if (decimalFormat != null)
                        value = decimalFormat.format(DisplayType.getNumber(value));
                    //   Set Value
                    cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
                } else if (DisplayType.isDate(column.DisplayType)) { //   Is Date
                    SimpleDateFormat dateFormat = cDateFormat[col];
                    if (dateFormat != null && value.trim().length() > 0) {
                        long date = Long.parseLong(value);
                        value = dateFormat.format(new Date(date));
                    }
                }
            }
            //   Set Value
            phrase = new Phrase(value);
            //   
            if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            else
                cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
            //   Set Font
            if (rPrintData.isFunctionRow()) {
                //   Set Function Value
                if (cPrintData.getFunctionValue() != null && cPrintData.getFunctionValue().length() > 0)
                    phrase = new Phrase(cPrintData.getFunctionValue());
                //   Set Font
                phrase.getFont().setStyle(Font.BOLDITALIC);
            }
            //   Add to Table
            cell.setPhrase(phrase);
            table.addCell(cell);
        }
    }
    //   Add Table to Document
    document.add(table);
    //   New Line
    document.add(Chunk.NEWLINE);
    //   Add Footer
    StringBuffer footerText = new StringBuffer(Env.getContext("#SUser"));
    footerText.append("(");
    footerText.append(Env.getContext("#AD_Role_Name"));
    footerText.append("@");
    footerText.append(Env.getContext("#AD_Client_Name"));
    footerText.append(".");
    footerText.append(Env.getContext("#AD_Org_Name"));
    footerText.append("{").append(Build.MANUFACTURER).append(".").append(Build.MODEL).append("}) ");
    //   Date
    SimpleDateFormat pattern = DisplayType.getDateFormat(ctx, DisplayType.DATE_TIME);
    footerText.append(" ").append(ctx.getResources().getString(R.string.Date)).append(" = ");
    footerText.append(pattern.format(new Date()));
    //   
    Paragraph footer = new Paragraph(footerText.toString());
    footer.setAlignment(Paragraph.ALIGN_CENTER);
    //   Set Font
    footer.getFont().setSize(8);
    //   Add Footer
    document.add(footer);
    //   Close Document
    document.close();
}

From source file:org.spinsuite.view.report.ReportPrintData.java

License:Open Source License

/**
 * Create a PDF File//  w ww  .j av a 2 s .c o m
 * @author <a href="mailto:yamelsenih@gmail.com">Yamel Senih</a> 02/04/2014, 22:52:09
 * @param outFile
 * @throws FileNotFoundException
 * @throws DocumentException
 * @return void
 */
private void createPDF(File outFile) throws FileNotFoundException, DocumentException {
    Document document = new Document(PageSize.LETTER);

    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outFile));
    PDFHeaderAndFooter event = new PDFHeaderAndFooter();
    writer.setPageEvent(event);
    document.open();
    //   
    document.addAuthor(ctx.getResources().getString(R.string.app_name));
    document.addCreationDate();
    //   
    Paragraph title = new Paragraph(m_reportQuery.getInfoReport().getName());
    //   Set Font
    title.getFont().setStyle(Font.BOLD);
    //   Set Alignment
    title.setAlignment(Paragraph.ALIGN_CENTER);
    //   Add Title
    document.add(title);
    //   Add New Line
    document.add(Chunk.NEWLINE);
    //   Parameters
    ProcessInfoParameter[] param = m_pi.getParameter();
    //   Get Parameter
    if (param != null) {
        //   
        boolean isFirst = true;
        //   Iterate
        for (ProcessInfoParameter para : param) {
            //   Get SQL Name
            String name = para.getInfo();
            StringBuffer textParameter = new StringBuffer();
            if (para.getParameter() == null && para.getParameter_To() == null)
                continue;
            else {
                //   Add Parameters Title
                if (isFirst) {
                    Paragraph titleParam = new Paragraph(
                            ctx.getResources().getString(R.string.msg_ReportParameters));
                    //   Set Font
                    titleParam.getFont().setStyle(Font.BOLDITALIC);
                    //   Add to Document
                    document.add(titleParam);
                    isFirst = false;
                }
                //   Add Parameters Name
                if (para.getParameter() != null && para.getParameter_To() != null) { //   From and To is filled
                    //   
                    textParameter.append(name).append(" => ").append(para.getDisplayValue()).append(" <= ")
                            .append(para.getDisplayValue_To());
                } else if (para.getParameter() != null) { //   Only From
                    //   
                    textParameter.append(name).append(" = ").append(para.getDisplayValue());
                } else if (para.getParameter_To() != null) { //   Only To
                    //   
                    textParameter.append(name).append(" <= ").append(para.getDisplayValue_To());
                }
            }
            //   Add to Document
            Paragraph viewParam = new Paragraph(textParameter.toString());
            document.add(viewParam);
        }
    }
    document.add(Chunk.NEWLINE);
    //   
    InfoReportField[] columns = m_reportQuery.getColumns();
    //   Add Table
    PdfPTable table = new PdfPTable(columns.length);
    table.setSpacingBefore(4);
    //   Add Header
    PdfPCell headerCell = new PdfPCell(new Phrase(m_reportQuery.getInfoReport().getName()));
    headerCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    headerCell.setColspan(columns.length);
    //   Add to Table
    table.addCell(headerCell);
    //   Add Header
    //   Decimal and Date Format
    DecimalFormat[] cDecimalFormat = new DecimalFormat[columns.length];
    SimpleDateFormat[] cDateFormat = new SimpleDateFormat[columns.length];
    for (int i = 0; i < columns.length; i++) {
        InfoReportField column = columns[i];
        //   Only Numeric
        if (DisplayType.isNumeric(column.DisplayType))
            cDecimalFormat[i] = DisplayType.getNumberFormat(ctx, column.DisplayType, column.FormatPattern);
        //   Only Date
        else if (DisplayType.isDate(column.DisplayType))
            cDateFormat[i] = DisplayType.getDateFormat(ctx, column.DisplayType, column.FormatPattern);
        //   
        Phrase phrase = new Phrase(column.PrintName);
        PdfPCell cell = new PdfPCell(phrase);
        if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
        else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        else
            cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
        //   
        table.addCell(cell);
    }
    //   Add Detail
    for (int row = 0; row < m_data.size(); row++) {
        //   Get Row
        RowPrintData rPrintData = m_data.get(row);
        //   Iterate
        for (int col = 0; col < columns.length; col++) {
            InfoReportField column = columns[col];
            ColumnPrintData cPrintData = rPrintData.get(col);
            Phrase phrase = null;
            PdfPCell cell = new PdfPCell();
            //   
            String value = cPrintData.getValue();
            if (DisplayType.isNumeric(column.DisplayType)) { //   Number
                //   Format
                DecimalFormat decimalFormat = cDecimalFormat[col];
                //   Format
                if (decimalFormat != null)
                    value = decimalFormat.format(DisplayType.getNumber(value));
                //   Set Value
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            } else if (DisplayType.isDate(column.DisplayType)) { //   Is Date
                SimpleDateFormat dateFormat = cDateFormat[col];
                if (dateFormat != null) {
                    long date = Long.getLong(value, 0);
                    value = dateFormat.format(new Date(date));
                }
            }
            //   Set Value
            phrase = new Phrase(value);
            //   
            if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_TRAILING_RIGHT))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT);
            else if (column.FieldAlignmentType.equals(InfoReportField.FIELD_ALIGNMENT_TYPE_CENTER))
                cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            else
                cell.setHorizontalAlignment(PdfPCell.ALIGN_UNDEFINED);
            //   Set Font
            if (rPrintData.isFunctionRow()) {
                //   Set Function Value
                if (cPrintData.getFunctionValue() != null && cPrintData.getFunctionValue().length() > 0)
                    phrase = new Phrase(cPrintData.getFunctionValue());
                //   Set Font
                phrase.getFont().setStyle(Font.BOLDITALIC);
            }
            //   Add to Table
            cell.setPhrase(phrase);
            table.addCell(cell);
        }
    }
    //   Add Table to Document
    document.add(table);
    //   New Line
    document.add(Chunk.NEWLINE);
    //   Add Footer
    StringBuffer footerText = new StringBuffer(Env.getContext(ctx, "#SUser"));
    footerText.append("(");
    footerText.append(Env.getContext(ctx, "#AD_Role_Name"));
    footerText.append("@");
    footerText.append(Env.getContext(ctx, "#AD_Client_Name"));
    footerText.append(".");
    footerText.append(Env.getContext(ctx, "#AD_Org_Name"));
    footerText.append("{").append(Build.MANUFACTURER).append(".").append(Build.MODEL).append("}) ");
    //   Date
    SimpleDateFormat pattern = DisplayType.getDateFormat(ctx, DisplayType.DATE_TIME);
    footerText.append(" ").append(ctx.getResources().getString(R.string.Date)).append(" = ");
    footerText.append(pattern.format(new Date()));
    //   
    Paragraph footer = new Paragraph(footerText.toString());
    footer.setAlignment(Paragraph.ALIGN_CENTER);
    //   Set Font
    footer.getFont().setSize(8);
    //   Add Footer
    document.add(footer);
    //   Close Document
    document.close();
}