Example usage for com.lowagie.text Paragraph add

List of usage examples for com.lowagie.text Paragraph add

Introduction

In this page you can find the example usage for com.lowagie.text Paragraph add.

Prototype

public boolean add(Object o) 

Source Link

Document

Adds an Object to the Paragraph.

Usage

From source file:biblivre3.administration.reports.AssetHoldingFullReport.java

License:Open Source License

@Override
protected void generateReportBody(Document document, BaseReportDto reportData) throws Exception {
    AssetHoldingDto dto = (AssetHoldingDto) reportData;
    String title = "";
    if (this.topographic) {
        title = this.getText("REPORTS_TOPOGRAPHIC_TITLE");
    } else {//from w  w  w .ja v  a  2  s.  c o m
        title = this.getText("REPORTS_ASSET_HOLDING_TITLE");
    }
    Paragraph p1 = new Paragraph(title);
    p1.setAlignment(Paragraph.ALIGN_CENTER);
    document.add(p1);
    document.add(new Phrase("\n"));
    PdfPTable table = new PdfPTable(20);
    table.setWidthPercentage(100f);
    createHeader(table);
    PdfPCell cell;
    List<String[]> dataList = dto.getData();
    Collections.sort(dataList, this);
    for (String[] data : dataList) {
        PdfContentByte cb = getWriter().getDirectContent();

        String holdingSerial = StringUtils.leftPad(data[0], 10, "0");
        Barcode39 code39 = new Barcode39();
        code39.setExtended(true);
        code39.setCode(holdingSerial);
        code39.setStartStopText(false);

        Image image39 = code39.createImageWithBarcode(cb, null, null);
        image39.scalePercent(100f);
        cell = new PdfPCell(new Paragraph(new Phrase(new Chunk(image39, 0, 0))));
        cell.setColspan(6);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);
        cell = new PdfPCell(new Paragraph(this.getSmallFontChunk(data[1])));
        cell.setColspan(3);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
        cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
        table.addCell(cell);

        Paragraph para = new Paragraph();
        para.add(new Phrase(this.getSmallFontChunk(data[2] + "\n")));
        para.add(new Phrase(this.getSmallFontChunk(data[3] + "\n")));

        if (StringUtils.isNotBlank(data[4])) {
            para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_LOCATION") + ": ")));
            para.add(new Phrase(this.getSmallFontChunk(data[4] + " ")));
        }

        if (StringUtils.isNotBlank(data[5])) {
            para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_EDITION") + ": ")));
            para.add(new Phrase(this.getSmallFontChunk(data[5] + " ")));
        }

        if (StringUtils.isNotBlank(data[6])) {
            para.add(new Phrase(this.getBoldChunk(this.getText("REPORTS_DATE") + ": ")));
            para.add(new Phrase(this.getSmallFontChunk(data[6])));
        }

        cell = new PdfPCell(para);
        cell.setColspan(11);
        cell.setHorizontalAlignment(PdfPCell.ALIGN_LEFT);
        cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
        cell.setPaddingTop(5f);
        cell.setPaddingLeft(7f);
        cell.setPaddingBottom(4f);
        table.addCell(cell);
    }
    document.add(table);
}

From source file:biblivre3.cataloging.bibliographic.BiblioBO.java

License:Open Source License

public MemoryFileDTO createFileLabelsPDF(ArrayList<LabelDTO> labels, LabelConfigDTO labelConfig) {
    Document document = new Document();
    final MemoryFileDTO file = new MemoryFileDTO();
    file.setFileName("biblivre_etiquetas_" + new Date().getTime() + ".pdf");
    try {/*from w ww.  jav a 2  s.  c  o  m*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.setPageSize(PageSize.A4);
        float verticalMargin = (297.0f - (labelConfig.getHeight() * labelConfig.getRows())) / 2;
        document.setMargins(7.15f * ApplicationConstants.MM_UNIT, 7.15f * ApplicationConstants.MM_UNIT,
                verticalMargin * ApplicationConstants.MM_UNIT, verticalMargin * ApplicationConstants.MM_UNIT);
        document.open();

        PdfPTable table = new PdfPTable(labelConfig.getColumns());
        table.setWidthPercentage(100f);
        PdfPCell cell;

        int i = 0;
        for (i = 0; i < labelConfig.getOffset(); i++) {
            cell = new PdfPCell();
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setFixedHeight(labelConfig.getHeight() * ApplicationConstants.MM_UNIT);
            table.addCell(cell);
        }

        for (LabelDTO ldto : labels) {
            PdfContentByte cb = writer.getDirectContent();

            String holdingSerial = String.valueOf(ldto.getHoldingSerial());
            while (holdingSerial.length() < 10) {
                holdingSerial = "0" + holdingSerial;
            }
            Barcode39 code39 = new Barcode39();
            code39.setExtended(true);
            code39.setCode(holdingSerial);
            code39.setStartStopText(false);

            Image image39 = code39.createImageWithBarcode(cb, null, null);
            if (labelConfig.getHeight() > 30.0f) {
                image39.scalePercent(110f);
            } else {
                image39.scalePercent(90f);
            }

            Paragraph para = new Paragraph();
            Phrase p1 = new Phrase(StringUtils.left(ldto.getAuthor(), 28) + "\n");
            Phrase p2 = new Phrase(StringUtils.left(ldto.getTitle(), 28) + "\n\n");
            Phrase p3 = new Phrase(new Chunk(image39, 0, 0));
            para.add(p1);
            para.add(p2);
            para.add(p3);

            cell = new PdfPCell(para);
            i++;
            cell.setNoWrap(true);
            cell.setFixedHeight(labelConfig.getHeight() * ApplicationConstants.MM_UNIT);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            cell.setBorder(Rectangle.NO_BORDER);
            table.addCell(cell);

            Paragraph para2 = new Paragraph();
            Phrase p5 = new Phrase(ldto.getLocationA() + "\n");
            Phrase p6 = new Phrase(ldto.getLocationB() + "\n");
            Phrase p7 = new Phrase(ldto.getLocationC() + "\n");
            Phrase p8 = new Phrase(ldto.getLocationD() + "\n");
            Phrase p4 = new Phrase(ldto.getAssetHolding() + "\n");
            para2.add(p5);
            para2.add(p6);
            para2.add(p7);
            para2.add(p8);
            para2.add(p4);

            cell = new PdfPCell(para2);
            i++;
            cell.setFixedHeight(labelConfig.getHeight() * ApplicationConstants.MM_UNIT);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            cell.setBorder(Rectangle.NO_BORDER);
            table.addCell(cell);
        }
        if ((i % labelConfig.getColumns()) != 0) {
            while ((i % labelConfig.getColumns()) != 0) {
                i++;
                cell = new PdfPCell();
                cell.setBorder(Rectangle.NO_BORDER);
                table.addCell(cell);
            }
        }
        document.add(table);
        writer.flush();
        document.close();
        file.setFileData(baos.toByteArray());
    } catch (Exception de) {
        System.out.println(de.getMessage());
    }
    return file;
}

From source file:biblivre3.circulation.CirculationBO.java

License:Open Source License

public MemoryFileDTO createFileUserCardsPDF(ArrayList<UserCardDTO> cards, int startOffset, Properties i18n) {
    Document document = new Document();
    MemoryFileDTO file = new MemoryFileDTO();
    file.setFileName("user_cards_" + new Date().getTime() + ".pdf");
    try {/*from   w w w .  j a  v a  2  s.  c om*/
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        document.setPageSize(PageSize.A4);
        document.setMargins(7.15f * ApplicationConstants.MM_UNIT, 7.15f * ApplicationConstants.MM_UNIT,
                9.09f * ApplicationConstants.MM_UNIT, 9.09f * ApplicationConstants.MM_UNIT);
        document.open();
        PdfPTable table = new PdfPTable(3);
        table.setWidthPercentage(100f);
        PdfPCell cell;
        int i = 0;
        for (i = 0; i < startOffset; i++) {
            cell = new PdfPCell();
            cell.setBorder(Rectangle.NO_BORDER);
            cell.setFixedHeight(46.47f * ApplicationConstants.MM_UNIT);
            table.addCell(cell);
        }
        for (UserCardDTO card : cards) {
            String userEnrollNumber = String.valueOf(card.getUserId());
            PdfContentByte cb = writer.getDirectContent();
            Barcode39 code39 = new Barcode39();
            code39.setExtended(true);
            while (userEnrollNumber.length() < 10) {
                userEnrollNumber = "0" + userEnrollNumber;
            }
            code39.setCode(userEnrollNumber);
            code39.setStartStopText(false);
            Image image39 = code39.createImageWithBarcode(cb, null, null);
            image39.scalePercent(110f);
            Paragraph para = new Paragraph();
            String name = card.getUserName();
            name = name.length() >= 30 ? name.substring(0, 30) : name;
            Phrase p1 = new Phrase(name + "\n");
            Phrase p2 = new Phrase(new Chunk(image39, 0, 0));
            Phrase p3 = new Phrase(
                    I18nUtils.getText(i18n, "LABEL_USER_SERIAL") + ": " + card.getUserId() + "\n");
            Phrase p4 = new Phrase(
                    I18nUtils.getText(i18n, "LABEL_USER_TYPE") + ": " + card.getUserType() + "\n\n");
            para.add(p1);
            para.add(p3);
            para.add(p4);
            para.add(p2);
            cell = new PdfPCell(para);
            i++;
            cell.setFixedHeight(46.47f * ApplicationConstants.MM_UNIT);
            cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
            cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
            cell.setBorder(Rectangle.NO_BORDER);
            table.addCell(cell);
        }
        if ((i % 3) != 0) {
            while ((i % 3) != 0) {
                i++;
                cell = new PdfPCell();
                cell.setBorder(Rectangle.NO_BORDER);
                table.addCell(cell);
            }
        }
        document.add(table);
        writer.flush();
        document.close();
        writer.close();
        file.setFileData(baos.toByteArray());
    } catch (DocumentException de) {
        System.out.println(de.getMessage());
    }
    return file;
}

From source file:br.edu.ifrs.restinga.sgru.bean.RelatorioBean.java

/**
 * Cria um cabealho para o documento PDF
 * @param document//from  w ww  .  j a v  a  2 s  . com
 */
public void preProcessPDF(Object document) {
    try {
        Document pdf = (Document) document;
        pdf.setPageSize(PageSize.A4);
        pdf.open();

        Paragraph preface = new Paragraph();

        // Titulo
        String titulo;
        if (this.relatorioCompras) {
            titulo = "Compras realizadas no perodo de " + this.getDataInicialFormatada() + " a "
                    + this.getDataFinalFormatada();
        } else {
            titulo = "Recargas realizadas no perodo de " + this.getDataInicialFormatada() + " a "
                    + this.getDataFinalFormatada();
        }
        // Titulo centralizado
        preface.setAlignment(Element.ALIGN_CENTER);
        // We add one empty line
        addEmptyLine(preface, 1);
        // Lets write a big header
        preface.add(new Paragraph(titulo, CAT_FONT));
        addEmptyLine(preface, 1);

        // O restante serah alinhado a a esquerda
        preface.setAlignment(Element.ALIGN_LEFT);
        // Nome de quem requisitou o relatorio
        SimpleDateFormat fmt = new SimpleDateFormat("dd/MM/yyyy 's' HH'h'mm");
        String dataSolicitacao = fmt.format(Calendar.getInstance().getTime());
        preface.add(new Paragraph("Relatrio gerado por " + this.controlador.getUsuarioLogado().getNome()
                + " em " + dataSolicitacao, SMALL_BOLD));

        // Forma de pagamento, Tipo de Cliente e Nome do Cliente            
        if (this.controlador.isUsuarioLogadoGerente()) {
            // Opcao para relatorio de compras apenas
            if (this.relatorioCompras) {
                String formaPgto;
                if (this.controlador.getFormaPgto() == FORMA_PGTO_CARTAO) {
                    formaPgto = "Carto";
                } else {
                    formaPgto = "Ticket";
                }
                preface.add(new Paragraph("Forma de Pagamento: " + formaPgto, SMALL_BOLD));
            }

            // Tipo de cliente
            //String tipoUsuario = this.controlador.getDescricaoCodigoCliente();
            String tipoCliente = "Todos";
            if (this.controlador.getTipoCliente() != null) {
                tipoCliente = this.controlador.getTipoCliente().getDescricao();
            }

            // Tipo de usuario e cliente nao serah impresso para ticket
            if ((this.controlador.getFormaPgto() != FORMA_PGTO_TICKET)) {
                // Tipo de usuario
                preface.add(new Paragraph("Tipo de Usurio: " + tipoCliente, SMALL_BOLD));

                // Cliente           
                String nomeCliente = "Todos";
                if (this.controlador.getCliente() != null) {
                    nomeCliente = this.controlador.getCliente().getNome();
                }
                preface.add(new Paragraph("Nome do Cliente: " + nomeCliente, SMALL_BOLD));

            }
        }

        addEmptyLine(preface, 1);
        pdf.add(preface);
    } catch (DocumentException e) {
        enviarMensagem(FacesMessage.SEVERITY_ERROR, e.getMessage());
    }
}

From source file:br.edu.ifrs.restinga.sgru.bean.RelatorioBean.java

/**
 * Adiciona uma linha no arquivo PDF//from  ww  w.  j av  a  2s .c o m
 * @param paragraph
 * @param number 
 */
private void addEmptyLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph(" "));
    }
}

From source file:br.edu.ifrs.restinga.sgru.modelo.ControladorVenda.java

/**
 * Realiza a venda de um ticket para um cliente
 *
 * @param documento//from www  .  j a  v  a  2  s. co  m
 * @throws br.edu.ifrs.restinga.sgru.excessao.TicketInvalidoException
 */
//public void realizarVendaTicket(Object documento) throws TicketInvalidoException {
public void realizarVendaTicket() throws TicketInvalidoException {
    if (this.quantidade <= 0) {
        throw new TicketInvalidoException("Venda de Quantidade invalida!");
    }

    Document pdfTicket = new Document();
    File temp;

    try {
        temp = File.createTempFile("imp_ticket", ".pdf");
        PdfWriter.getInstance(pdfTicket, new FileOutputStream(temp));
        pdfTicket.open();
        pdfTicket.setPageSize(PageSize.A4);

        Table tabela = new Table(1);
        tabela.setWidth(100);

        for (int i = 0; i < this.quantidade; i++) {
            VendaTicketsRecargas vendaTicketsRecarga = new VendaTicketsRecargas();
            vendaTicketsRecarga.setCaixaRU(this.caixaRU);
            vendaTicketsRecarga.realizarVendaTicket();

            Cell celula = new Cell();
            celula.setHorizontalAlignment(Element.ALIGN_CENTER);
            celula.add(new Paragraph("SISTEMA DE GERENCIAMENTO DE RESTAURANTE UNIVERSIT?RIO"));

            Paragraph parag = new Paragraph();
            parag.getFont().setSize(18);
            parag.add("TICKET");
            celula.add(parag);

            // Gerando o codigo convetido do ticket
            String conversor = "";
            for (char con : String.format("%07d", vendaTicketsRecarga.getTicket().getId()).toCharArray()) {
                conversor = con + conversor;
            }

            parag = new Paragraph();
            parag.getFont().setSize(20);
            parag.add(String.valueOf(Integer.valueOf(conversor, 16)));
            celula.add(parag);

            NumberFormat format = NumberFormat.getCurrencyInstance(new Locale("pt", "BR"));
            format.setMaximumFractionDigits(2);
            celula.add(new Paragraph("VALOR " + format.format(vendaTicketsRecarga.getTicket().getValor())));
            celula.add(new Paragraph(vendaTicketsRecarga.getTicket().getDataCriado().getTime().toString()));
            celula.add(new Paragraph(" _ "));
            tabela.addCell(celula);

            this.caixaRU.atualizarLstVendaTicketsRecargas(vendaTicketsRecarga);
        }

        pdfTicket.add(tabela);
    } catch (DocumentException | IOException de) {
        throw new TicketInvalidoException(de.getMessage());
    } finally {
        pdfTicket.close();
    }

    // Abrindo o pdf no pc
    try {
        Desktop.getDesktop().open(temp);
        temp.deleteOnExit();
    } catch (IOException ex) {
        throw new TicketInvalidoException(ex.getMessage());
    }
}

From source file:br.gov.jfrj.siga.ex.util.GeradorRTF.java

License:Open Source License

private TextElementArray percorreProximoBloco(TextElementArray element, int level, boolean considerarPTags)
        throws Exception {
    String tagName = parser.getName();
    while (!(parser.getEventType() == XmlPullParser.END_TAG && parser.getName() != null
            && parser.getName().equals(tagName))) {

        parser.nextToken();/*from  w  w w.  j  a  v  a2  s. c om*/

        // insere um texto comum
        if (parser.getEventType() == XmlPullParser.TEXT)
            element.add(parser.getText().toUpperCase());

        // Insere um pargrafo
        if (parser.getEventType() == XmlPullParser.START_TAG)
            if (parser.getName().toUpperCase().equals("P") && considerarPTags
            /*
             * || parser.getName().toUpperCase().equals("UL") ||
             * parser.getName().toUpperCase().equals("OL") ||
             * parser.getName().toUpperCase().equals("DL")
             */) {
                Paragraph paragrafo = new Paragraph();
                paragrafo.add("\t");
                // paragrafo.setFirstLineIndent(((Paragraph)element).indentationLeft()
                // + 29);
                // paragrafo.setSpacingAfter(200);
                // paragrafo.setSpacingBefore(200);
                paragrafo = (Paragraph) percorreProximoBloco(paragrafo, level + 1, true);
                paragrafo.add("\n");
                element.add(paragrafo);
            }

        if (parser.getEventType() == XmlPullParser.START_TAG)
            if (parser.getName().toUpperCase().equals("TABLE")
            /*
             * || parser.getName().toUpperCase().equals("UL") ||
             * parser.getName().toUpperCase().equals("OL") ||
             * parser.getName().toUpperCase().equals("DL")
             */) {
                Paragraph paragrafo = new Paragraph();
                paragrafo.add("\t");
                // paragrafo.setFirstLineIndent(((Paragraph)element).indentationLeft()
                // + 29);
                // paragrafo.setSpacingAfter(200);
                // paragrafo.setSpacingBefore(200);
                paragrafo = (Paragraph) percorreProximoBloco(paragrafo, level + 1, false);
                paragrafo.add("\n");
                element.add(paragrafo);
            }

        // Insere um item de lista
        if (parser.getEventType() == XmlPullParser.START_TAG)
            if (parser.getName().toUpperCase().equals("LI")) {
                Paragraph paragrafo = new Paragraph();
                for (int k = 0; k <= level + 1; k++)
                    paragrafo.add("\t");
                paragrafo = (Paragraph) percorreProximoBloco(paragrafo, level + 1, false);
                element.add(paragrafo);

            }

        // Pula linha ao fim da lista
        if (parser.getEventType() == XmlPullParser.END_TAG)
            if (parser.getName().toUpperCase().equals("UL") || parser.getName().toUpperCase().equals("OL")
                    || parser.getName().toUpperCase().equals("DL")) {
                element.add("\n");
            }

        if (parser.getEventType() == XmlPullParser.START_TAG)
            if (parser.getName().toUpperCase().equals("TD")) {
                element.add("\t");
                percorreProximoBloco(element, level + 1, false);
            }

        if (parser.getEventType() == XmlPullParser.START_TAG)
            if (parser.getName().toUpperCase().equals("TR")) {
                element.add("\n\n");
            }

        if (parser.getEventType() == XmlPullParser.START_TAG)
            if (parser.getName().toUpperCase().equals("BR")) {
                element.add("\n\n\t");
            }
    }
    return element;
}

From source file:br.gov.jfrj.siga.ex.util.GeradorRTF.java

License:Open Source License

public byte[] geraRTF(ExDocumento doc) throws Exception {

    html = doc.getConteudoBlobHtmlString();
    html = (new ProcessadorHtml()).canonicalizarHtml(html, true, false, true, true, false);
    html = html.replace("<!-- INICIO MIOLO -->", "<MIOLO>");
    html = html.replace("<!-- FIM MIOLO -->", "</MIOLO>");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    RtfWriter2.getInstance(document, baos);
    document.open();// w ww  . j a  v a  2  s  . c om
    document.setMargins(29, 340, 29, 29);
    parser.setInput(new StringReader(html));

    BaseFont arial = BaseFont.createFont("C:\\WINDOWS\\FONTS\\ARIAL.TTF", BaseFont.CP1252, true);
    Font fonte = new Font(arial);
    fonte.setSize(7);
    Paragraph paragrafoBase = new Paragraph("", fonte);

    paragrafoBase.add("\t" + doc.getOrgaoUsuario().getDescricaoMaiusculas());
    paragrafoBase.add("\n\n");
    paragrafoBase
            .add("\t" + doc.getExFormaDocumento().getDescricao().toUpperCase() + " " + doc.getCodigoString());
    if (doc.getDtDocDDMMYY() != null && doc.getDtDocDDMMYY().length() > 0)
        paragrafoBase.add(" DE " + doc.getDtDocDDMMYY());
    paragrafoBase.add("\n\n");

    try {

        seekTag("MIOLO");
        paragrafoBase = (Paragraph) percorreProximoBloco(paragrafoBase, 0, true);

        document.add(paragrafoBase);
    } catch (XmlPullParserException xppe) {
        int a = 2;
    } catch (IOException ioe) {
        int a = 2;
    } finally {
        document.close();
    }

    /*
     * Pattern p1 = Pattern .compile("^.<!-- INICIO MIOLO -->.<!--
     * FIM MIOLO -->."); final Matcher m = p1.matcher(html);
     */

    byte[] retorno = baos.toByteArray();

    baos.close();

    return retorno;

}

From source file:br.org.acessobrasil.silvinha.util.GeraRelatorioPDF.java

License:Open Source License

public static boolean geraRelatorio(File file) {
    TradGeraRelatorioPDF.carregaTexto(TokenLang.LANG);
    Document document = new Document(PageSize.A4);
    try {/*  w ww  .jav  a2  s .c  o m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        writer.setPageEvent(new HeaderAndFooter());
        document.open();
        int linha = 0, j, tot_pg = ResumoDoRelatorio.getTotPage();
        //calcula o total de htmls
        float tot_link = 0.0f;
        for (j = 1; j <= tot_pg; j++) {
            String conteudo = ResumoDoRelatorio.getPage(j);
            String arr[] = conteudo.split("\n");
            tot_link += arr.length;
        }
        PainelStatusBar.showProgTarReq();
        //loop por todas as pginas da paginacao
        for (j = 1; j <= tot_pg; j++) {
            String conteudo = ResumoDoRelatorio.getPage(j);
            String arr[] = conteudo.split("\n");
            int tot = arr.length;
            int i;
            //loop por todos os links
            for (i = 0; i < tot; i++) {
                progresso = (linha++ / tot_link) * 100.0f;
                PainelStatusBar.setValueProgress((int) progresso);
                String arr2[] = arr[i].split("\t");

                if (arr2.length == 8) {

                    String strUrl = arr2[7];// URL
                    /*
                    int ap1 = Integer.parseInt(arr2[4]);// Aviso1
                    int ep1 = Integer.parseInt(arr2[1]);// Erro1
                    int ap2 = Integer.parseInt(arr2[5]);// Aviso2
                    int ep2 = Integer.parseInt(arr2[2]);// Erro2
                    int ap3 = Integer.parseInt(arr2[6]);// Aviso3
                    int ep3 = Integer.parseInt(arr2[3]);// Erro3
                    */
                    String myHash = arr2[0];

                    RelatorioDaUrl relatorio = new RelatorioDaUrl();
                    relatorio.recarregaArquivoRelatorioEmXml2(myHash);

                    document.add(new Phrase("\n"));
                    Font font = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.BOLD);

                    Chunk url = new Chunk(strUrl, font);
                    Paragraph p1 = new Paragraph(TradGeraRelatorioPDF.RELATORIO_URL);
                    p1.add(url);
                    p1.setAlignment(Paragraph.ALIGN_LEFT);
                    document.add(p1);
                    document.add(new Phrase("\n\n"));

                    if (relatorio.getErrosPrioridade1() <= 0 && relatorio.getErrosPrioridade2() <= 0
                            && relatorio.getErrosPrioridade3() <= 0) {
                        Paragraph p2 = new Paragraph(TradGeraRelatorioPDF.PAGINAS_SEM_ERROS);
                        p2.setAlignment(Paragraph.ALIGN_CENTER);
                        document.add(p2);

                    } else {

                        if (relatorio.getErrosPrioridade1() > 0) {
                            Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P1, font);
                            p1.setAlignment(Paragraph.ALIGN_LEFT);
                            document.add(p);
                            document.add(new Chunk("\n"));
                            PdfPTable table = geraLista(relatorio.getListaErrosP1());
                            if (table != null) {
                                document.add(table);
                            }
                            document.add(new Phrase("\n\n"));
                        }

                        if (relatorio.getErrosPrioridade2() > 0) {
                            Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P2, font);
                            p1.setAlignment(Paragraph.ALIGN_LEFT);
                            document.add(p);
                            document.add(new Chunk("\n"));
                            PdfPTable table = geraLista(relatorio.getListaErrosP2());
                            if (table != null) {
                                document.add(table);
                            }
                            document.add(new Phrase("\n\n"));
                        }

                        if (relatorio.getErrosPrioridade3() > 0) {
                            Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P3, font);
                            p1.setAlignment(Paragraph.ALIGN_LEFT);
                            document.add(p);
                            document.add(new Chunk("\n"));
                            PdfPTable table = geraLista(relatorio.getListaErrosP3());
                            if (table != null) {
                                document.add(table);
                            }
                            document.add(new Phrase("\n\n"));
                        }
                        document.newPage();
                    }
                }
            }
        }
        writer.flush();
        document.close();
    } catch (DocumentException de) {
        log.error(de.getMessage(), de);
        PainelStatusBar.hideProgTarReq();
        return false;
    } catch (IOException ioe) {
        log.error(ioe.getMessage(), ioe);
        PainelStatusBar.hideProgTarReq();
        return false;
    }
    PainelStatusBar.hideProgTarReq();
    return true;
}

From source file:br.org.acessobrasil.silvinha.util.GeraRelatorioPDF.java

License:Open Source License

public static boolean geraRelatorio_bkp(File file, ResumoDoRelatorio resumo) {

    Document document = new Document(PageSize.A4);
    try {//from  w  w  w. ja va 2  s  .  c  o  m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
        writer.setPageEvent(new HeaderAndFooter());
        document.open();

        ArrayList<RelatorioDaUrl> relatorios = resumo.getRelatorios();
        loop: for (RelatorioDaUrl relatorio : relatorios) {
            document.add(new Phrase("\n"));
            Font font = FontFactory.getFont(FontFactory.HELVETICA, Font.DEFAULTSIZE, Font.BOLD);

            Chunk url = new Chunk(relatorio.getUrl(), font);
            Paragraph p1 = new Paragraph(TradGeraRelatorioPDF.RELATORIO_URL);
            p1.add(url);
            p1.setAlignment(Paragraph.ALIGN_LEFT);
            document.add(p1);
            document.add(new Phrase("\n\n"));

            if (relatorio.getErrosPrioridade1() <= 0 && relatorio.getErrosPrioridade2() <= 0
                    && relatorio.getErrosPrioridade3() <= 0) {
                Paragraph p2 = new Paragraph(TradGeraRelatorioPDF.PAGINAS_SEM_ERROS);
                p2.setAlignment(Paragraph.ALIGN_CENTER);
                document.add(p2);
                continue loop;
            }

            if (relatorio.getErrosPrioridade1() > 0) {
                Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P1_SEM_TAB, font);
                p1.setAlignment(Paragraph.ALIGN_LEFT);
                document.add(p);
                document.add(new Chunk("\n"));
                PdfPTable table = geraLista(relatorio.getListaErrosP1());
                if (table != null) {
                    document.add(table);
                }
                document.add(new Phrase("\n\n"));
            }

            if (relatorio.getErrosPrioridade2() > 0) {
                Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P2_SEM_TAB, font);
                p1.setAlignment(Paragraph.ALIGN_LEFT);
                document.add(p);
                document.add(new Chunk("\n"));
                PdfPTable table = geraLista(relatorio.getListaErrosP2());
                if (table != null) {
                    document.add(table);
                }
                document.add(new Phrase("\n\n"));
            }

            if (relatorio.getErrosPrioridade3() > 0) {
                Paragraph p = new Paragraph(TradGeraRelatorioPDF.ERROS_P3_SEM_TAB, font);
                p1.setAlignment(Paragraph.ALIGN_LEFT);
                document.add(p);
                document.add(new Chunk("\n"));
                PdfPTable table = geraLista(relatorio.getListaErrosP3());
                if (table != null) {
                    document.add(table);
                }
                document.add(new Phrase("\n\n"));
            }
            document.newPage();
        }

        writer.flush();
        document.close();
    } catch (DocumentException de) {
        log.error(de.getMessage(), de);
        return false;
    } catch (IOException ioe) {
        log.error(ioe.getMessage(), ioe);
        return false;
    }
    return true;
}