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:pruebareportes.rptEmpleadosSinMarcar.java

public void crearPdf(String nombreFile, List<String> dnis, Date fechaInicio, Date fechaFin, String oficina,
        String tipo, String usuario, Date horaInicio, Date horaFin) throws IOException, DocumentException {
    Document documento = new Document(PageSize.A4);
    PdfWriter.getInstance(documento, new FileOutputStream(nombreFile));
    documento.open();//  w w w  .j  a va2s  . c om
    String nombreGrupoOficina = "";
    if (tipo == "O") {
        nombreGrupoOficina = "OFICINA: ";
    } else {
        nombreGrupoOficina = "GRUPO HORARIO: ";
    }
    Font font = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
    Chunk nombreReporte = new Chunk("REPORTE DE CONSOLIDADO DE TARDANZA", font);
    Chunk labelOficina = new Chunk(nombreGrupoOficina, font);
    Chunk labelMes = new Chunk("MES: ", font);
    Chunk labelHoraInicio = new Chunk("HORA INICIO:", font);
    Chunk labelHoraFin = new Chunk("HORA FIN:", font);
    Chunk labelUsuario = new Chunk("USUARIO: ", font);

    Chunk nombreOficina = new Chunk(oficina, new Font(Font.TIMES_ROMAN, 10));
    Chunk nombreMes = new Chunk(ReporteUtil.obtenerNombreMes(fechaInicio).toUpperCase(),
            new Font(Font.TIMES_ROMAN, 10));
    Chunk nombreUsuario = new Chunk(usuario.toUpperCase(), new Font(Font.TIMES_ROMAN, 10));
    Chunk sHoraInicio = new Chunk(horaInicio.toString(), new Font(Font.TIMES_ROMAN, 10));
    Chunk sHoraFin = new Chunk(horaFin.toString(), new Font(Font.TIMES_ROMAN, 10));

    documento.add(new Paragraph(nombreReporte));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelOficina, nombreOficina)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelMes, nombreMes)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelUsuario, nombreUsuario)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelHoraInicio, sHoraInicio)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelHoraFin, sHoraFin)));
    documento.add(ReporteUtil.darEspaciado(20));

    PdfPTable tabla = new rptEmpleadosSinMarcar().crearTabla(dnis, fechaInicio, fechaFin);
    documento.add(tabla);
    documento.close();
    try {
        File path = new File(nombreFile);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:pruebareportes.rptTardC.java

public void crearPdf(String nombreFile, List<String> dnis, Date fechaInicio, Date fechaFin, String oficina,
        String tipo, String usuario) throws IOException, DocumentException {
    Document documento = new Document(PageSize.A4.rotate());
    PdfWriter.getInstance(documento, new FileOutputStream(nombreFile));
    documento.open();/*  w w w . j a  va  2s .c o  m*/
    String nombreGrupoOficina = "";
    if (tipo == "O") {
        nombreGrupoOficina = "OFICINA: ";
    } else {
        nombreGrupoOficina = "GRUPO HORARIO: ";
    }
    Font font = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
    Chunk nombreReporte = new Chunk("REPORTE DE CONSOLIDADO DE TARDANZA", font);
    Chunk labelOficina = new Chunk(nombreGrupoOficina, font);
    Chunk labelMes = new Chunk("MES: ", font);
    Chunk labelUsuario = new Chunk("USUARIO: ", font);

    Chunk nombreOficina = new Chunk(oficina, new Font(Font.TIMES_ROMAN, 10));
    Chunk nombreMes = new Chunk(ReporteUtil.obtenerNombreMes(fechaInicio).toUpperCase(),
            new Font(Font.TIMES_ROMAN, 10));
    Chunk nombreUsuario = new Chunk(usuario.toUpperCase(), new Font(Font.TIMES_ROMAN, 10));

    documento.add(new Paragraph(nombreReporte));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelOficina, nombreOficina)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelMes, nombreMes)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelUsuario, nombreUsuario)));
    documento.add(ReporteUtil.darEspaciado(20));
    PdfPTable tabla = new rptTardC().crearTabla(dnis, fechaInicio, fechaFin);
    documento.add(tabla);
    documento.close();
    try {
        File path = new File(nombreFile);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:pruebareportes.rptTardCx.java

public void crearPdf(String nombreFile, List<String> dnis, Date fechaInicio, Date fechaFin, String oficina,
        String tipo, String usuario) throws IOException, DocumentException {
    Document documento = new Document(PageSize.A4.rotate());
    PdfWriter.getInstance(documento, new FileOutputStream(nombreFile));
    documento.open();/*from  ww w .ja v  a2s .  c o  m*/
    String nombreGrupoOficina = "";
    if (tipo == "O") {
        nombreGrupoOficina = "OFICINA: ";
    } else {
        nombreGrupoOficina = "GRUPO HORARIO: ";
    }
    Font font = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
    Chunk nombreReporte = new Chunk("REPORTE DE CONSOLIDADO DE TARDANZA", font);
    Chunk labelOficina = new Chunk(nombreGrupoOficina, font);
    Chunk labelMes = new Chunk("MES: ", font);
    Chunk labelUsuario = new Chunk("USUARIO: ", font);

    Chunk nombreOficina = new Chunk(oficina, new Font(Font.TIMES_ROMAN, 10));
    Chunk nombreMes = new Chunk(ReporteUtil.obtenerNombreMes(fechaInicio).toUpperCase(),
            new Font(Font.TIMES_ROMAN, 10));
    Chunk nombreUsuario = new Chunk(usuario.toUpperCase(), new Font(Font.TIMES_ROMAN, 10));

    documento.add(new Paragraph(nombreReporte));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelOficina, nombreOficina)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelMes, nombreMes)));
    documento.add(ReporteUtil.darEspaciado(15));
    documento.add(new Paragraph(ReporteUtil.unirChunks(labelUsuario, nombreUsuario)));
    documento.add(ReporteUtil.darEspaciado(20));
    PdfPTable tabla = new rptTardCx().crearTabla(dnis, fechaInicio, fechaFin);
    documento.add(tabla);
    documento.close();
    try {
        File path = new File(nombreFile);
        Desktop.getDesktop().open(path);
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:questions.graphics2D.ArabicText.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4);
    try {/*from  w  w  w . j  a  v  a2s  . c o  m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        String text1 = "\u0634\u0627\u062f\u062c\u0645\u0647\u0648\u0631";
        String text2 = "\u0634";
        java.awt.Font font = new java.awt.Font("arial", 0, 12);
        PdfContentByte cb = writer.getDirectContent();

        java.awt.Graphics2D g2Shapes = cb.createGraphicsShapes(PageSize.A4.getWidth(), PageSize.A4.getHeight());
        g2Shapes.setFont(font);
        g2Shapes.drawString("text1, expected to render RTL", 50, 100);
        g2Shapes.drawString(text1, 50, 120);
        g2Shapes.drawString("text2, expected to match right-most glyph above", 50, 140);
        g2Shapes.drawString(text2, 50, 160);
        g2Shapes.dispose();

        ColumnText text = new ColumnText(cb);
        Font f = new Font(
                BaseFont.createFont("c://windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED),
                12);
        text.setSimpleColumn(50, 620, 545, 50);
        text.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
        text.setText(new Phrase(text1, f));
        text.go();
        text.setText(new Phrase(text2, f));
        text.go();

        FontMapper arialuni = new FontMapper() {
            public BaseFont awtToPdf(java.awt.Font font) {
                try {
                    return BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H,
                            BaseFont.EMBEDDED);
                } catch (DocumentException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return null;
            }

            public java.awt.Font pdfToAwt(BaseFont font, int size) {
                return null;
            }

        };
        java.awt.Graphics2D g = cb.createGraphics(PageSize.A4.getWidth(), PageSize.A4.getHeight(), arialuni);
        g.setFont(null);
        g.drawString("text1, not expected to render RTL", 50, 180);
        g.drawString(text1, 50, 200);
        g.drawString("text2, not expected to match right-most glyph above", 50, 220);
        g.drawString(text2, 50, 240);
        g.drawString("to your right you see what it SHOULD look like:", 50, 260);
        g.drawString("If it doesn't, the problem is in the JDK, it's not an iText problem.", 50, 280);
        g.dispose();
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:questions.importpages.HelloWorldImportedPages.java

public static void main(String[] args) {
    // we create a PDF file
    createPdf(SOURCE);/*from   w w  w  .  ja v  a2 s.c o m*/
    // step 1
    Document document = new Document(PageSize.A4);
    try {
        // we create a PdfReader object
        PdfReader reader = new PdfReader(SOURCE);
        // step 2
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        // step 3
        document.open();
        // step 4
        PdfImportedPage page;
        for (int i = 1; i <= reader.getNumberOfPages(); i++) {
            page = writer.getImportedPage(reader, i);
            Image image = Image.getInstance(page);
            image.scalePercent(15f);
            image.setBorder(Rectangle.BOX);
            image.setBorderWidth(3f);
            image.setBorderColor(new GrayColor(0.5f));
            image.setRotationDegrees(-reader.getPageRotation(i));
            document.add(image);
            document.add(new Paragraph("This is page: " + i));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    // step 5
    document.close();
}

From source file:questions.importpages.HelloWorldImportedPages.java

/**
 * Generates a PDF file with bookmarks./*from w w w .java 2 s.  c  o m*/
 * 
 * @param filename
 *            the filename of the PDF file.
 */
private static void createPdf(String filename) {
    // we create a document with multiple pages and bookmarks
    Document document = new Document(PageSize.A4);
    try {
        PdfWriter.getInstance(document, new FileOutputStream(filename));
        document.open();
        document.add(new Paragraph(
                "In this document, we are going to say hello to different beings in different languages."));
        document.newPage();
        Paragraph hello = new Paragraph(
                "(English:) hello, " + "(Esperanto:) he, alo, saluton, (Latin:) heu, ave, "
                        + "(French:) all\u00f4, (Italian:) ciao, (German:) hallo, he, heda, holla, "
                        + "(Portuguese:) al\u00f4, ol\u00e1, hei, psiu, bom d\u00eda, (Dutch:) hallo, dag, "
                        + "(Spanish:) ola, eh, (Catalan:) au, bah, eh, ep, "
                        + "(Swedish:) hej, hejsan(Danish:) hallo, dav, davs, goddag, hej, "
                        + "(Norwegian:) hei; morn, (Papiamento:) halo; hallo; k\u00ed tal, "
                        + "(Faeroese:) hall\u00f3, hoyr, (Turkish:) alo, merhaba, (Albanian:) tungjatjeta");
        Chapter universe = new Chapter("To the Universe:", 1);
        Section section;
        section = universe.addSection("to the World:");
        section.add(hello);
        section = universe.addSection("to the Sun:");
        section.add(hello);
        section = universe.addSection("to the Moon:");
        section.add(hello);
        section = universe.addSection("to the Stars:");
        section.add(hello);
        document.add(universe);
        Chapter people = new Chapter("To the People:", 2);
        section = people.addSection("to mothers and fathers:");
        section.add(hello);
        section = people.addSection("to brothers and sisters:");
        section.add(hello);
        section = people.addSection("to wives and husbands:");
        section.add(hello);
        section = people.addSection("to sons and daughters:");
        section.add(hello);
        section = people.addSection("to complete strangers:");
        section.add(hello);
        document.add(people);
        document.setPageSize(PageSize.A4.rotate());
        Chapter animals = new Chapter("To the Animals:", 3);
        section = animals.addSection("to cats and dogs:");
        section.add(hello);
        section = animals.addSection("to birds and bees:");
        section.add(hello);
        section = animals.addSection("to farm animals and wild animals:");
        section.add(hello);
        section = animals.addSection("to bugs and beatles:");
        section.add(hello);
        section = animals.addSection("to fish and shellfish:");
        section.add(hello);
        document.add(animals);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:questions.importpages.NameCards.java

public static void createSheet(int p) throws DocumentException, IOException {
    Rectangle rect = new Rectangle(PageSize.A4);
    Document document = new Document(rect);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(SHEET[p - 1]));
    document.open();/*  ww w  .  j  a  v a  2  s. co  m*/
    PdfContentByte canvas = writer.getDirectContentUnder();
    PdfReader reader = new PdfReader(NameCard.CARD);
    PdfImportedPage front = writer.getImportedPage(reader, p);
    float x = rect.getWidth() / 2 - front.getWidth();
    float y = (rect.getHeight() - (front.getHeight() * 5)) / 2;
    canvas.setLineWidth(0.5f);
    canvas.moveTo(x, y - 15);
    canvas.lineTo(x, y);
    canvas.lineTo(x - 15, y);
    canvas.moveTo(x + front.getWidth(), y - 15);
    canvas.lineTo(x + front.getWidth(), y);
    canvas.moveTo(x + front.getWidth() * 2, y - 15);
    canvas.lineTo(x + front.getWidth() * 2, y);
    canvas.lineTo(x + front.getWidth() * 2 + 15, y);
    canvas.stroke();
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 2; j++) {
            canvas.addTemplate(front, x, y);
            x += front.getWidth();
        }
        x = rect.getWidth() / 2 - front.getWidth();
        y += front.getHeight();
        canvas.moveTo(x, y);
        canvas.lineTo(x - 15, y);
        canvas.moveTo(x + front.getWidth() * 2, y);
        canvas.lineTo(x + front.getWidth() * 2 + 15, y);
        canvas.stroke();
    }
    canvas.moveTo(x, y + 15);
    canvas.lineTo(x, y);
    canvas.moveTo(x + front.getWidth(), y + 15);
    canvas.lineTo(x + front.getWidth(), y);
    canvas.moveTo(x + front.getWidth() * 2, y + 15);
    canvas.lineTo(x + front.getWidth() * 2, y);
    canvas.stroke();
    document.close();
}

From source file:questions.ocg.StatusBars1.java

public void createPdf() {
    try {//from  www. j  a  v a 2 s  . c  om
        Document document = new Document(PageSize.A4, 10, 10, 10, 10);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));

        document.open();

        //define Layers

        PdfLayer colorLayer = PdfLayer.createTitle("Color", writer);
        colorLayerColored = new PdfLayer("Colored", writer);
        colorLayerColored.setOn(true);
        colorLayer.addChild(colorLayerColored);
        colorLayerGreyed = new PdfLayer("Greyed", writer);
        colorLayerGreyed.setOn(false);
        colorLayer.addChild(colorLayerGreyed);
        ArrayList<PdfLayer> radio = new ArrayList<PdfLayer>();
        radio.add(colorLayerColored);
        radio.add(colorLayerGreyed);
        writer.addOCGRadioGroup(radio);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        PdfPCell cell;
        for (int i = 0; i <= 100; i++) {
            cell = new PdfPCell(new Phrase("percentage: " + i));
            table.addCell(cell);
            cell = new PdfPCell(getImage(writer.getDirectContent(), i));
            table.addCell(cell);
        }
        document.add(table);
        document.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:questions.ocg.StatusBars2.java

public void createPdf() {
    try {/*from   www  .jav a2s. c o m*/
        Document document = new Document(PageSize.A4, 10, 10, 10, 10);
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));

        document.open();

        //define Layers

        PdfLayer colorLayer = PdfLayer.createTitle("Color", writer);
        colorLayerColored = new PdfLayer("Colored", writer);
        colorLayerColored.setOn(true);
        colorLayer.addChild(colorLayerColored);
        colorLayerGreyed = new PdfLayer("Greyed", writer);
        colorLayerGreyed.setOn(false);
        colorLayer.addChild(colorLayerGreyed);
        ArrayList<PdfLayer> radio = new ArrayList<PdfLayer>();
        radio.add(colorLayerColored);
        radio.add(colorLayerGreyed);
        writer.addOCGRadioGroup(radio);

        PdfPTable table = new PdfPTable(2);
        table.setWidthPercentage(100);
        PdfPCell cell;
        for (int i = 0; i <= 100; i++) {
            cell = new PdfPCell(new Phrase("percentage: " + i));
            table.addCell(cell);
            cell = new PdfPCell();
            cell.setCellEvent(new StatusBar(i));
            table.addCell(cell);
        }
        document.add(table);
        document.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:questions.tables.AddTableAsHeaderFooter.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A4, 50, 50, 50, 100);
    try {/*  w  w  w .j a  v a 2s. c o m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        writer.setPageEvent(new AddTableAsHeaderFooter());
        document.open();
        String text = "Lots of text. ";
        for (int i = 0; i < 5; i++)
            text += text;
        for (int i = 0; i < 20; i++)
            document.add(new Paragraph(text));
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}