Example usage for com.itextpdf.text Image setAlignment

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

Introduction

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

Prototype


public void setAlignment(final int alignment) 

Source Link

Document

Sets the alignment for the image.

Usage

From source file:essencialles.modelos.relatorio.tipos.MaisVendidos.java

@Override
public void run() {
    try {// www .ja  v a2s.  c  om
        //criao do PDF
        Document doc = new Document(PageSize.A4, 72, 72, 72, 72);

        OutputStream saida = new FileOutputStream(this.caminho);
        PdfWriter.getInstance(doc, saida);
        doc.open();
        try {
            //logomarca
            Image img = Image.getInstance("src/views/img/logomarca.png");
            img.setAlignment(Element.ALIGN_CENTER);
            doc.add(img);
        } catch (BadElementException | IOException ex) {
            throw new RuntimeException(ex);
        }
        //paragrafo
        Paragraph paragrafo = new Paragraph("Relatrio de Produtos Mais Vendidos");
        paragrafo.setSpacingAfter(50);
        paragrafo.setSpacingBefore(15);
        paragrafo.setFont(new Font(Font.FontFamily.COURIER, Font.BOLD));
        paragrafo.setAlignment(Element.ALIGN_CENTER);
        doc.add(paragrafo);

        /*tabela
         PdfPTable tabela = new PdfPTable(9);
         tabela.setHorizontalAlignment(Element.ALIGN_CENTER);
         PdfPCell header = new PdfPCell(new Paragraph("Todos os Produtos"));
         header.setColspan(9);
         tabela.addCell(header);
         tabela.addCell("Codigo");
         tabela.addCell("Nome");
         tabela.addCell("Marca");
         tabela.addCell("Preo");
         tabela.addCell("Custo");
         tabela.addCell("Cor");
         tabela.addCell("Descrio");
         tabela.addCell("Peso");
         tabela.addCell("Disponibilidade");
         tabela.addCell("Validade");
         adicionar linhas da tabela.
         for (Produto p : produtos) {
         String cod = p.getCod_produto() + "";
         String nome = p.getNome();
         String marca = p.getMarca();
         String preco = p.getPreco() + "";
         String custo = p.getCusto() + "";
         String cor = p.getCor();
         String descricao = p.getDescricao();
         String peso = p.getPeso();
         String disponibilidade = p.getDisponibilidade();
         String validade = p.getValidade() + "";
                
         }*/
        try {
            saida.flush();

        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        doc.close();

        try {
            saida.close();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }

    } catch (FileNotFoundException | DocumentException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:essencialles.modelos.relatorio.tipos.ProdutosTodos.java

@Override
public void run() {

    try {//from w  w w  .j  a v  a  2s. c o  m
        //criao do PDF

        Document doc = new Document(PageSize.A4, 72, 72, 72, 72);

        OutputStream saida = new FileOutputStream(this.caminho);
        PdfWriter.getInstance(doc, saida);
        doc.open();
        try {
            //logomarca

            Image img = Image.getInstance("src/views/img/logomarca.png");
            img.setAlignment(Element.ALIGN_CENTER);
            doc.add(img);
        } catch (BadElementException | IOException ex) {
            throw new RuntimeException(ex);
        }
        //paragrafo
        Paragraph paragrafo = new Paragraph("Relatrio de Produtos");
        paragrafo.setSpacingAfter(50);
        paragrafo.setSpacingBefore(15);
        paragrafo.setFont(new Font(Font.FontFamily.COURIER, Font.BOLD));
        paragrafo.setAlignment(Element.ALIGN_CENTER);
        doc.add(paragrafo);

        /*tabela
         PdfPTable tabela = new PdfPTable(9);
         tabela.setHorizontalAlignment(Element.ALIGN_CENTER);
         PdfPCell header = new PdfPCell(new Paragraph("Todos os Produtos"));
         header.setColspan(9);
         tabela.addCell(header);
         tabela.addCell("Codigo");
         tabela.addCell("Nome");
         tabela.addCell("Marca");
         tabela.addCell("Preo");
         tabela.addCell("Custo");
         tabela.addCell("Cor");
         tabela.addCell("Descrio");
         tabela.addCell("Peso");
         tabela.addCell("Disponibilidade");
         tabela.addCell("Validade");
         adicionar linhas da tabela.
         for (ProdutoModelo p : produtos) {
         String cod = p.getCod_produto() + "";
         String nome = p.getNome();
         String marca = p.getMarca();
         String preco = p.getPreco() + "";
         String custo = p.getCusto() + "";
         String cor = p.getCor();
         String descricao = p.getDescricao();
         String peso = p.getPeso();
         String disponibilidade = p.getDisponibilidade();
         String validade = p.getValidade() + "";
                
         }*/
        try {
            saida.flush();

        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        doc.close();

        try {
            saida.close();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }

    } catch (FileNotFoundException | DocumentException ex) {
        throw new RuntimeException(ex);
    }

}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.AbstractContentFactory.java

License:Open Source License

protected Paragraph decorateImage(Image i, String caption) {

    Paragraph p = new Paragraph("", IMAGE_CAPTION);
    p.setAlignment(Element.ALIGN_CENTER);
    i.setAlignment(Element.ALIGN_CENTER);
    i.setBorder(Image.BOX);/*from w  ww .j a va2s  .  com*/
    i.setBorderWidth(3f);
    i.setBorderColor(new BaseColor(52, 90, 138));
    p.add(i);

    Paragraph captionP = new Paragraph(caption, IMAGE_CAPTION);
    captionP.setAlignment(Element.ALIGN_CENTER);
    //p.add(Chunk.NEWLINE);
    p.add(captionP);

    //p.setKeepTogether(true);
    return p;
}

From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java

License:Open Source License

/******************************************************************************************/

private void buildAppendixAChapter(Chapter c, Document d) {

    c.setTitle(getChapterTitleParagraph("Appendix A"));
    c.setNumberDepth(0);/*from w  w w . java2  s.  c  o m*/
    c.setTriggerNewPage(true);

    float width = d.getPageSize().getWidth() - d.leftMargin() - d.rightMargin();
    float height = d.getPageSize().getHeight() - d.topMargin() - d.bottomMargin() - 70;

    if (needSocialDiagramInAppendixA()) {
        Image socialImage = rsp.generateScrenshot(ViewsManager.SOCIAL_VIEW);
        socialImage.setAlignment(Element.ALIGN_CENTER);
        if (socialImage.getPlainWidth() > socialImage.getPlainHeight()) {
            fitImageInArea(socialImage, height, width, true);
            socialImage.setRotationDegrees(90);
        } else {
            fitImageInArea(socialImage, width, height, true);
        }

        c.add(decorateImage(socialImage, ftc.getFigure(FigureConstant.SOCIAL_DIAGRAM)
                + " - Social View for the " + getProjectName() + " project"));
    }
    if (needInformationDiagramInAppendixA()) {
        Image informationImage = rsp.generateScrenshot(ViewsManager.RESOURCE_VIEW);
        informationImage.setAlignment(Element.ALIGN_CENTER);
        if (informationImage.getPlainWidth() > informationImage.getPlainHeight()) {
            fitImageInArea(informationImage, height, width, true);
            informationImage.setRotationDegrees(90);
        } else {
            fitImageInArea(informationImage, width, height, true);
        }
        // c.add(informationImage);
        c.add(decorateImage(informationImage, ftc.getFigure(FigureConstant.INFORMATION_DIAGRAM)
                + " - Information View for the " + getProjectName() + " project"));

    }
    if (needInformationDiagramInAppendixA()) {
        Image authorisationImage = rsp.generateScrenshot(ViewsManager.AUTHORIZATION_VIEW);
        authorisationImage.setAlignment(Element.ALIGN_CENTER);
        if (authorisationImage.getPlainWidth() > authorisationImage.getPlainHeight()) {
            fitImageInArea(authorisationImage, height, width, true);
            authorisationImage.setRotationDegrees(90);
        } else {
            fitImageInArea(authorisationImage, width, height, true);
        }
        // c.add(authorisationImage);
        c.add(decorateImage(authorisationImage, ftc.getFigure(FigureConstant.AUTH_DIAGRAM)
                + " - Authorisation View for the " + getProjectName() + " project"));

    }

    c.setComplete(true);
}

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 {//from w  w  w .  ja va 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:eyeofthetiger.utils.PDFDossardGenerator.java

private Element createCleanBarcode(PdfContentByte cb, String numero, float width, float height) {
    Barcode128 code128 = new Barcode128();
    code128.setCode(numero);// w  w w  .j a va 2s  .  c om
    Image barcodeImage = code128.createImageWithBarcode(cb, null, null);
    barcodeImage.setAlignment(Image.ALIGN_CENTER);
    //barcodeImage.setWidthPercentage(75f);
    barcodeImage.scaleToFit(width, height);
    return barcodeImage;
}

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

License:Apache License

private void createFirstPage() throws DocumentException, IOException {
    Rectangle savePagesize = document.getPageSize();
    document.setPageSize(PageSize.A4);/*from  w  ww . ja va 2s.c  o m*/
    document.newPage();
    Image imageLogo = Image.getInstance(PdfRenderer.class.getResource("/logo.png"));
    imageLogo.scaleToFit(document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin(),
            imageLogo.getHeight());
    document.add(imageLogo);

    Paragraph paragraph = new Paragraph("21, 22 et 23 mai");
    paragraph.setSpacingAfter(80);
    paragraph.getFont().setSize(20);
    paragraph.setAlignment(Element.ALIGN_CENTER);
    document.add(paragraph);

    Paragraph title = new Paragraph("Programme 2014");
    title.setSpacingAfter(100);
    title.getFont().setSize(56);
    title.setAlignment(Element.ALIGN_CENTER);
    document.add(title);

    PdfPTable sponsors = new PdfPTable(4);
    sponsors.setWidthPercentage(90f);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/LogoZenika-H-(Quadri).jpg", 2);
    addSponsor(sponsors,
            "http://blogs.technet.com/resized-image.ashx/__size/450x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-80-54/6864.Microsoft-Logo.png",
            2);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/Google_Logo_3564x1189.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/cbpaas.jpeg", 1);
    addSponsor(sponsors, "https://github.global.ssl.fastly.net/images/modules/logos_page/GitHub-Logo.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/sonarsource-300x94.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/serli.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/Logo_sqli_group.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/SofteamCadextanLogo_w200.png", 1);
    addSponsor(sponsors, "http://www.breizhcamp.org/img/logoSII_w200.png", 1);
    document.add(sponsors);

    Image istic = Image.getInstance("http://www.breizhcamp.org/img/Logo_ISTIC_BLACK_FRA.jpg");
    istic.scaleToFit(150, 150);
    istic.setAlignment(Element.ALIGN_CENTER);
    document.add(istic);

    document.setPageSize(savePagesize);
}

From source file:fxml.test.PDFService.java

private PdfPTable createDocumentHeader() throws IOException, BadElementException {

    //start creating header for the document......
    PdfPTable headerTable = new PdfPTable(3);
    headerTable.setHorizontalAlignment(Element.ALIGN_LEFT);
    try {/*from   ww w.  jav  a2  s . co m*/
        headerTable.setTotalWidth(new float[] { 57.5f, 531.5f, 183f });
        headerTable.setLockedWidth(true);

    } catch (DocumentException ex) {
        Logger.getLogger(PDFService.class.getName()).log(Level.SEVERE, null, ex);
    }

    Image image = Image.getInstance(getClass().getClassLoader().getResource("img/sust.jpg"));
    image.scalePercent(42f);
    image.setAlignment(Element.ALIGN_LEFT);
    PdfPCell imageCell = new PdfPCell(image, false);
    imageCell.setPaddingTop(6);
    imageCell.setBorder(Rectangle.NO_BORDER);
    headerTable.addCell(imageCell);

    //start info table.....
    PdfPTable infoTable = new PdfPTable(1);
    infoTable.getDefaultCell().setBorder(Rectangle.NO_BORDER);

    String universityText = "SHAHJALAL UNIVERSITY OF SCIENCE & TECHNOLOGY SYLHET, BANGLADESH";
    String tabulationText = "TABULATION SHEET";
    String deptText = inputs.get(0).trim();

    String s1 = inputs.get(1).trim();
    String s2 = inputs.get(2).trim();
    String semesterText = ("B.Sc (Engg.) " + s1 + " SEMESTER EXAMINATION " + s2);

    String session = inputs.get(3).trim();
    String date = inputs.get(4).trim();

    String sessionDateText = ("SESSION:" + session + " EXAMINATION HELD IN: " + date);

    infoTable.addCell(getCellForHeaderString(universityText, 0, false, 0, Element.ALIGN_CENTER, font10, true));
    infoTable.addCell(getCellForHeaderString(tabulationText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    infoTable.addCell(getCellForHeaderString(deptText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    infoTable.addCell(getCellForHeaderString(semesterText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    infoTable
            .addCell(getCellForHeaderString(sessionDateText, 0, false, 0, Element.ALIGN_CENTER, font10, false));
    //end info table.....

    PdfPCell infoCell = new PdfPCell(infoTable);
    infoCell.setBorder(Rectangle.NO_BORDER);
    headerTable.addCell(infoCell);

    PdfPCell resultPublishDateCell = new PdfPCell(
            new Paragraph("Result Published On............................",
                    new Font(Font.FontFamily.TIMES_ROMAN, 10, Font.BOLD)));
    resultPublishDateCell.setBorder(Rectangle.NO_BORDER);
    resultPublishDateCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
    resultPublishDateCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    headerTable.addCell(resultPublishDateCell);
    headerTable.setSpacingAfter(17.5f);
    // System.err.println("completed header table");
    return headerTable;
    //end creating header for the document......
}

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

License:Open Source License

private void addLogo() throws IOException, DocumentException {
    Image image = Image.getInstance(AbstractPdfWriterGenerator.class.getResource(LOGO_IMAGE_PATH));
    image.setAlignment(Image.RIGHT);
    image.scalePercent(FIFTY_PERCENT);//from w  w w  .  j a  v  a 2  s.com
    document.add(image);
}

From source file:grafico.GenerarMapa.java

public void imprimir() {
    Document document = new Document(PageSize.A2);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    try {/*from   www  .j a  v  a  2 s.com*/
        PdfWriter.getInstance(document, baos);
        //METADATA

        document.open();
        String nombretabla = "ESTUDIANTES INSCRITOS\n";
        document.add(new Paragraph(nombretabla));
        DateFormat formatter = new SimpleDateFormat("dd/MM/yy '-' hh:mm:ss:");

        Date currentDate = new Date();
        String date = formatter.format(currentDate);
        document.add(new Paragraph("Fecha Generado: " + date));
        document.add(new Paragraph("\n"));

        Image imageen;
        Image foto = Image.getInstance("grafo.jpg");
        foto.scaleToFit(1000, 1000);
        foto.setAlignment(Chunk.ALIGN_MIDDLE);

        document.add(foto);

        document.close();

        FacesContext context = FacesContext.getCurrentInstance();
        Object response = context.getExternalContext().getResponse();
        if (response instanceof HttpServletResponse) {
            HttpServletResponse hsr = (HttpServletResponse) response;
            hsr.setContentType("application/pdf");

            hsr.setHeader("Content-disposition", "filename=" + nombretabla + ".pdf");

            try {
                ServletOutputStream out = hsr.getOutputStream();
                baos.writeTo(out);
                out.flush();
                out.close();
            } catch (IOException ex) {
                System.out.println("Error:  " + ex.getMessage());
            }
            context.responseComplete();
        }

    } catch (Exception ex) {
        System.out.println("Error " + ex.getMessage());
    }
}