Example usage for com.lowagie.text PageSize A4

List of usage examples for com.lowagie.text PageSize A4

Introduction

In this page you can find the example usage for com.lowagie.text PageSize A4.

Prototype

Rectangle A4

To view the source code for com.lowagie.text PageSize A4.

Click Source Link

Document

This is the a4 format

Usage

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 {//from w w w.  j a  va 2s .c om
        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 ww  .  ja v  a 2s  .  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;
}

From source file:br.org.archimedes.io.pdf.PDFExporter.java

License:Open Source License

public void exportDrawing(Drawing drawing, OutputStream output) throws IOException {

    Rectangle rectangle = PageSize.A4.rotate();
    Document document = new Document(rectangle);

    PdfWriter writer = null;/* w ww.jav a  2 s.c  om*/
    try {
        writer = PdfWriter.getInstance(document, output);
    } catch (DocumentException e) {
        // Should never happen since I just created a new document.
        e.printStackTrace();
    }
    document.open();
    PdfContentByte cb = writer.getDirectContent();
    PDFWriter pdf = new PDFWriter(cb, rectangle);
    pdf.write(drawing);

    document.close();
}

From source file:br.rio.puc.inf.les.controller.ApartamentoBean.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();/*w w w  . j ava  2  s  .  c o m*/
    pdf.setPageSize(PageSize.A4);

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    //String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "demo" + File.separator + "images" + File.separator + "prime_logo.png";

    // pdf.add(Image.getInstance(logo));
}

From source file:bs.global.web.CustomizeDocument.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();// w  w  w .j a v a  2  s  .co  m
    pdf.setPageSize(PageSize.A4);

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "image"
            + File.separator + "logo.png";

    pdf.add(Image.getInstance(logo));
}

From source file:candelaria.presentacion.beans.ClienteControlador.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();//from  ww w . ja v  a 2 s .  co m
    pdf.setPageSize(PageSize.A4);

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
            + File.separator + "reportes" + File.separator + "clientes.png";

    pdf.add(Image.getInstance(logo));
}

From source file:candelaria.presentacion.beans.EmpleadoControlador.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();//from   ww  w  .j a  v  a 2 s . c o  m
    pdf.setPageSize(PageSize.A4);

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
            + File.separator + "reportes" + File.separator + "empleados.png";

    pdf.add(Image.getInstance(logo));
}

From source file:candelaria.presentacion.beans.MateriaPrimaControlador.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();//from w w  w.j  a  v a2 s.c o m
    pdf.setPageSize(PageSize.A4);

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
            + File.separator + "reportes" + File.separator + "materiaprima.png";

    pdf.add(Image.getInstance(logo));
}

From source file:candelaria.presentacion.beans.ProductoControlador.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();//from www .  j  a va 2 s .c om
    pdf.setPageSize(PageSize.A4);

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
            + File.separator + "reportes" + File.separator + "productos.png";

    pdf.add(Image.getInstance(logo));
}

From source file:candelaria.presentacion.beans.ProveedorControlador.java

public void preProcessPDF(Object document) throws IOException, BadElementException, DocumentException {
    Document pdf = (Document) document;
    pdf.open();//from w w  w.  ja va  2 s.c o  m
    pdf.setPageSize(PageSize.A4);

    ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
            .getContext();
    String logo = servletContext.getRealPath("") + File.separator + "resources" + File.separator + "images"
            + File.separator + "reportes" + File.separator + "proveedores.png";

    pdf.add(Image.getInstance(logo));
}