Example usage for com.lowagie.text Paragraph Paragraph

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

Introduction

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

Prototype

public Paragraph() 

Source Link

Document

Constructs a Paragraph.

Usage

From source file:Agenda.java

public void preparaPDF(Object document) throws IOException, BadElementException, DocumentException {
    //criando novo pdf
    Document pdf = (Document) document;

    //abrindo documento
    pdf.open();/* w  w w. j  a  v a2s.  c  o m*/

    //modificando caracteristicas do documento
    pdf.setPageSize(PageSize.A4);

    //        //VERSAO FUNCIONAL    
    //        //criando paragrafo no texto
    //            Paragraph p = new Paragraph("Relatrio Contatos",            
    //            //editando configuracoes de fontes do texto
    //            FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new Color(255,150,255)));
    //            
    //        //definindo alinhamento
    //            p.setAlignment(Element.ALIGN_CENTER);
    //        
    //        //adiciona as modificaes ao documento
    //            pdf.add(p);

    //VERSAO CORRETA
    Paragraph p = new Paragraph();
    p.setFont(FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new Color(255, 255, 0)));
    p.add(new Phrase("Relatrio Contatos"));
    p.setAlignment(Element.ALIGN_CENTER);
    pdf.add(p);
}

From source file:EmailWithPdf.java

/**
 * Writes the content of a PDF file (using iText API)
 * to the {@link OutputStream}./*from  ww w  . j ava2  s  .c  om*/
 * @param outputStream {@link OutputStream}.
 * @throws Exception
 */
public void writePdf(OutputStream outputStream) throws Exception {
    Document document = new Document();
    PdfWriter.getInstance(document, outputStream);

    document.open();

    document.addTitle("Test PDF");
    document.addSubject("Testing email PDF");
    document.addKeywords("iText, email");
    document.addAuthor("Jee Vang");
    document.addCreator("Jee Vang");

    Paragraph paragraph = new Paragraph();
    paragraph.add(new Chunk("hello!"));
    paragraph.add(new Chunk("hello!"));
    paragraph.add(new Chunk("hello!"));
    paragraph.add(new Chunk("hello!"));
    paragraph.add(new Chunk("hello!"));
    paragraph.add(new Chunk("hello!"));
    paragraph.add(new Chunk("hello!"));
    paragraph.add(new Chunk("hello!"));
    paragraph.add(new Chunk("hello!"));
    document.add(paragraph);

    document.close();
}

From source file:FirstPdf.java

private static void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);/* w ww .  j av  a2s  .  co  m*/
    // Lets write a big header
    preface.add(new Paragraph("Title of the document", catFont));
    addEmptyLine(preface, 1);
    // Will create: Report generated by: _name, _date
    preface.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            smallBold));
    addEmptyLine(preface, 3);
    preface.add(new Paragraph("This document describes something which is very important ", smallBold));
    addEmptyLine(preface, 8);
    preface.add(new Paragraph(
            "This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.de ;-).",
            redFont));
    document.add(preface);
    // Start a new page
    document.newPage();
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private Paragraph createTinyParagraph(String title, String data) {
    Paragraph p = new Paragraph();

    p.setLeading((p.leading() / 2) + 2);
    p.add(new Chunk(title,
            new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 8, com.lowagie.text.Font.NORMAL)));

    p.add(new Chunk(data,
            new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 10, com.lowagie.text.Font.BOLD)));

    return p;//from   w w w  .  java 2 s  . co  m

}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsAddSvg(Airport airport, PdfWriter writer, Document document, String imageFileName) {
    // FREQs Nearest Navaid
    notifyAction("createSheetsAddSvg");
    PdfPTable table = new PdfPTable(1);
    {//from  w w w .  j  a  v a 2  s .  c om
        PdfPCell cell = new PdfPCell();
        cell.setMinimumHeight(height);

        {
            Paragraph p = new Paragraph();
            com.lowagie.text.Font fontWarning = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                    com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
            p.add(new Chunk(" ", fontWarning));
            cell.addElement(p);
        }

        cell.setBorderWidth(borderWidth);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);

        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsFakeShops(Airport airport, Document document) {
    // FREQs Nearest Navaid
    notifyAction("createSheetsFakeShops");
    PdfPTable table = new PdfPTable(1);
    {//ww  w .  j  a v  a 2 s .  co  m
        PdfPCell cell = new PdfPCell();

        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setMinimumHeight(20);

        boolean addWorker = false;
        for (final Runway runway : airport.getRunways()) {
            if (runway.getLength() > 1200 / FEET_PER_METER) {
                addWorker = true;
            }
        }

        boolean addFork = (airport.hasTower());

        Paragraph p = new Paragraph();
        p.setLeading((p.leading() / 2) + 4);
        if (addWorker) {
            try {
                p.add(new Chunk("   "));
                p.add(new Chunk(Image.getInstance(getClass().getResource(Main.imgFolder + "avail_work.png")), 0,
                        -3));
            } catch (BadElementException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        if (addFork) {
            try {
                p.add(new Chunk("   "));
                p.add(new Chunk(Image.getInstance(getClass().getResource(Main.imgFolder + "avail_fork.png")), 0,
                        -3));
            } catch (BadElementException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        cell.addElement(p);

        //cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setBorderWidth(borderWidth);
        cell.setVerticalAlignment(Element.ALIGN_TOP);

        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsLights(Airport airport, Document document) {
    // FREQs Nearest Navaid
    notifyAction("createSheetsLights");
    PdfPTable table = new PdfPTable(1);
    {/*from   w  w w .j  a va  2s . c om*/
        PdfPCell cell = new PdfPCell();

        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setMinimumHeight(20);

        Paragraph p = new Paragraph();
        p.setLeading((p.leading() / 2) + 4);
        com.lowagie.text.Font font = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN, 10,
                com.lowagie.text.Font.NORMAL);

        oneLightDone = false;

        try {
            p.add(new Chunk("   ", font));
            p.add(new Chunk(Image.getInstance(getClass().getResource(Main.imgFolder + "light.png")), 0, 0));
            p.add(new Chunk("   ", font));
        } catch (BadElementException ex) {
            Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
        }

        boolean addABN = airport.hasBeacon();
        if (addABN) {
            p.add(addOneLight("ABN", font));
        }

        boolean addALS = false;
        boolean addPAPI = false;
        for (final Runway runway : airport.getRunways()) {
            if ((runway.hasALSF_I(false) || runway.hasALSF_I(true))
                    || (runway.hasALSF_II(false) || runway.hasALSF_II(true))) {
                addALS = true;
            }

            if ((runway.hasPapi(false) || runway.hasPapi(true))) {
                addPAPI = true;
            }
        }
        if (addALS) {
            p.add(addOneLight("ALS", font));
        }

        if (addPAPI) {
            p.add(addOneLight("PAPI ", font));
            String separ = "";
            for (final Runway runway : airport.getRunways()) {
                if (runway.hasPapi(false)) {
                    p.add(new Chunk(separ + runway.getNumber() + " (3.5)" + degrees + " ", font));
                    separ = ", ";
                }
                if (runway.hasPapi(true)) {
                    p.add(new Chunk(separ + runway.getOppositeNumber() + " (3.5)" + degrees + " ", font));
                    separ = ", ";
                }
            }
        }

        cell.addElement(p);

        //cell.setBorder(com.lowagie.text.Rectangle.NO_BORDER);
        cell.setBorderWidth(borderWidth);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);

        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:airportpainter.util.AirportPainter.java

License:Open Source License

private void createSheetsNotes(Airport airport, Document document) {
    // FREQs Nearest Navaid
    notifyAction("createSheetsNotes");
    PdfPTable table = new PdfPTable(1);
    {//from  w  w w .  j  ava  2  s.  c om
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);

        {
            Paragraph p = new Paragraph();
            com.lowagie.text.Font fontWarning = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                    com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.BOLD);
            p.add(new Chunk("Warning !", fontWarning));
            cell.addElement(p);
        }

        {
            Paragraph p = new Paragraph();
            com.lowagie.text.Font fontText = new com.lowagie.text.Font(com.lowagie.text.Font.TIMES_ROMAN,
                    com.lowagie.text.Font.DEFAULTSIZE, com.lowagie.text.Font.NORMAL);
            p.add(new Chunk(
                    "Do not use this chart in real life, this is a chart suitable to be used only for FlightGear !!!",
                    fontText));
            cell.addElement(p);
        }

        cell.setBorderWidth(borderWidth);
        cell.setVerticalAlignment(Element.ALIGN_CENTER);

        table.addCell(cell);
    }

    table.setWidthPercentage(100);
    try {
        document.add(table);
    } catch (DocumentException ex) {
        Logger.getLogger(AirportPainter.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ambit.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

public void headerTable(Document pdfdoc, org.w3c.dom.Document xmldoc) {
    try {/* w  w  w.  j a  v  a 2  s . c  o m*/
        int header_font_size = 10;
        Image png_left = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        Image png_right = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        png_left.setAlignment(Image.LEFT);
        png_right.setAlignment(Image.RIGHT);
        png_left.scalePercent(60);
        png_right.scalePercent(60);
        //png.scaleAbsolute(76, 67);
        //png.setAlignment(Image.MIDDLE);

        PdfPCell cell;

        float[] widths = { 1f, 5f, 1f };
        float[] widths1 = { 1f };
        PdfPTable table = new PdfPTable(widths);
        PdfPTable table1 = new PdfPTable(widths1);

        table.setWidthPercentage(100);

        cell = new PdfPCell();
        cell.setMinimumHeight(70);
        cell.addElement(new Chunk(png_left, +14, -40));
        table.addCell(cell);

        String Text = "";
        try {

            Text = findNodeValue(xml_QMRF_number, xmldoc);
            Chunk ident_title = new Chunk("QMRF identifier (JRC Inventory):");
            Chunk ident_text = new Chunk(Text);

            Font bi_font = new Font(baseFont, header_font_size, Font.BOLDITALIC);
            Font i_font = new Font(baseFont, header_font_size, Font.ITALIC);

            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            Paragraph p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            ident_title = new Chunk("QMRF Title:");
            Phrase textPhrase = new Phrase();
            createNodePhrase("QSAR_title", xmldoc, textPhrase, i_font);
            ident_title.setFont(bi_font);

            p = new Paragraph();
            p.add(ident_title);
            p.add(textPhrase);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            java.util.Date now = new java.util.Date();
            java.text.DateFormat df = java.text.DateFormat.getDateInstance();
            String date = df.format(now);
            ident_title = new Chunk("Printing Date:");
            ident_text = new Chunk(date);
            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);

            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            p = new Paragraph("");
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);
            cell = new PdfPCell(table1);
            cell.setPadding(0f);
            table.addCell(cell);

        } catch (Throwable x) {
            x.printStackTrace();

        }

        //table.addCell(new PdfPCell(png, true));
        cell.addElement(new Chunk(png_right, +14, -40));
        table.addCell(cell);
        pdfdoc.add(table);
        pdfdoc.add(new Paragraph(16));

    } catch (Exception x) {
        x.printStackTrace();
    }
}

From source file:ambit2.data.qmrf.Qmrf_Xml_Pdf.java

License:Open Source License

public void headerTable(Document pdfdoc, org.w3c.dom.Document xmldoc) {
    try {//  www. j  a v a2 s.c  om
        int header_font_size = 10;
        Image png_left = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        Image png_right = Image
                .getInstance(Qmrf_Xml_Pdf.class.getClassLoader().getResource("ambit/data/qmrf/logo.png"));
        png_left.setAlignment(Image.LEFT);
        png_right.setAlignment(Image.RIGHT);
        png_left.scalePercent(60);
        png_right.scalePercent(60);
        //png.scaleAbsolute(76, 67);
        //png.setAlignment(Image.MIDDLE);

        PdfPCell cell;

        float[] widths = { 1f, 5f, 1f };
        float[] widths1 = { 1f };
        PdfPTable table = new PdfPTable(widths);
        PdfPTable table1 = new PdfPTable(widths1);

        table.setWidthPercentage(100);

        cell = new PdfPCell();
        cell.setMinimumHeight(70);
        cell.addElement(new Chunk(png_left, +14, -40));
        table.addCell(cell);

        String Text = "";
        try {

            Text = findNodeValue(xml_QMRF_number, xmldoc);
            Chunk ident_title = new Chunk("QMRF identifier (ECB Inventory):");
            Chunk ident_text = new Chunk(Text);

            Font bi_font = new Font(baseFont, header_font_size, Font.BOLDITALIC);
            Font i_font = new Font(baseFont, header_font_size, Font.ITALIC);

            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            Paragraph p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            ident_title = new Chunk("QMRF Title:");
            Phrase textPhrase = new Phrase();
            createNodePhrase("QSAR_title", xmldoc, textPhrase, i_font);
            ident_title.setFont(bi_font);

            p = new Paragraph();
            p.add(ident_title);
            p.add(textPhrase);
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            java.util.Date now = new java.util.Date();
            java.text.DateFormat df = java.text.DateFormat.getDateInstance();
            String date = df.format(now);
            ident_title = new Chunk("Printing Date:");
            ident_text = new Chunk(date);
            ident_title.setFont(bi_font);
            ident_text.setFont(i_font);
            p = new Paragraph();
            p.add(ident_title);
            p.add(ident_text);

            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);

            p = new Paragraph("");
            cell = new PdfPCell(p);
            cell.setHorizontalAlignment(Element.ALIGN_LEFT);
            table1.addCell(cell);
            cell = new PdfPCell(table1);
            cell.setPadding(0f);
            table.addCell(cell);

        } catch (Throwable x) {
            x.printStackTrace();

        }

        //table.addCell(new PdfPCell(png, true));
        cell.addElement(new Chunk(png_right, +14, -40));
        table.addCell(cell);
        pdfdoc.add(table);
        pdfdoc.add(new Paragraph(16));

    } catch (Exception x) {
        x.printStackTrace();
    }
}