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:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

/**
 * iText paragraph for the TRiDaS wood completeness fields
 * //  w w w  .  java 2 s .c om
 * @return Paragraph
 */
private Paragraph getWoodCompletenessPDF() {
    Paragraph p = new Paragraph();
    p.setLeading(0, 1.2f);
    TridasRadius trad = s.getMeta(Metadata.RADIUS, TridasRadius.class);
    TridasWoodCompleteness woodCompleteness = trad.getWoodCompleteness();

    String pithPresence = null;
    String barkPresence = null;

    p.add(new Chunk("Wood Completeness:\n", subSubSectionFont));

    // Extract pith info
    if (woodCompleteness.getPith() != null) {

        if (woodCompleteness.getPith().getPresence() != null) {
            pithPresence = woodCompleteness.getPith().getPresence().value();
        } else {
            pithPresence = "not specified";
        }

        p.add(new Chunk("- Pith is " + pithPresence + ".\n", bodyFont));
    } else {
        p.add(new Chunk("- No pith details were recorded.\n", bodyFont));
    }

    // Ring count 
    p.add(new Chunk("- A total of " + String.valueOf(s.countRings()) + " rings were measured.", bodyFont));

    // Unmeasured rings
    if (woodCompleteness.isSetNrOfUnmeasuredInnerRings() || woodCompleteness.isSetNrOfUnmeasuredOuterRings()) {
        String txt = " Additional rings were observed but not measured (";
        if (woodCompleteness.isSetNrOfUnmeasuredInnerRings()) {
            txt += String.valueOf(woodCompleteness.getNrOfUnmeasuredInnerRings()) + " towards the pith";
            if (woodCompleteness.isSetNrOfUnmeasuredOuterRings()) {
                txt += " and ";
            }
        }
        if (woodCompleteness.isSetNrOfUnmeasuredOuterRings()) {
            txt += String.valueOf(woodCompleteness.getNrOfUnmeasuredOuterRings()) + " towards the bark";
        }

        txt += ").";

        p.add(new Chunk(txt, bodyFont));
        p.add(new Chunk("\n"));
    } else {
        p.add(new Chunk("\n"));
    }

    // Extract Heartwood and sapwood info
    p.add(getHeartSapwoodDetails(woodCompleteness, WoodType.HEARTWOOD));
    p.add(getHeartSapwoodDetails(woodCompleteness, WoodType.SAPWOOD));

    // Extract last ring under bark info
    if (woodCompleteness.getSapwood().getLastRingUnderBark() != null) {
        TridasLastRingUnderBark lastRing = woodCompleteness.getSapwood().getLastRingUnderBark();
        if (lastRing.getPresence() != null) {
            if (lastRing.getPresence().equals(PresenceAbsence.PRESENT)) {
                p.add(new Chunk("- Last ring under bark is present", bodyFont));

                if (lastRing.getContent() != null) {
                    p.add(new Chunk(
                            " and the user has noted that it is: " + lastRing.getContent().toString() + ".\n",
                            bodyFont));
                } else {
                    p.add(new Chunk(".\n", bodyFont));
                }

            } else if (lastRing.getPresence().equals(PresenceAbsence.ABSENT)) {
                p.add(new Chunk("- Last ring under bark is absent.\n", bodyFont));
            }
        }

    }

    // Extract bark info
    if (woodCompleteness.getBark() != null) {
        if (woodCompleteness.getBark().getPresence().toString().toLowerCase() != null) {
            if (woodCompleteness.getBark().getPresence().value() == "present") {
                p.add(new Chunk("- Bark is present ", bodyFont));
                // Last ring info
                if (woodCompleteness.getSapwood().getLastRingUnderBark() != null) {
                    p.add(new Chunk("and the last ring before the bark is noted as: \""
                            + woodCompleteness.getSapwood().getLastRingUnderBark().getContent().toString()
                            + "\"", bodyFont));
                } else {
                    p.add(new Chunk("but no details about the last ring under the bark were recorded.\n",
                            bodyFont));
                }
            } else if (woodCompleteness.getBark().getPresence().value() == "absent") {

                // Calculate if we have waney edge
                if (woodCompleteness.getSapwood().getPresence().equals(ComplexPresenceAbsence.COMPLETE)) {
                    p.add(new Chunk("- Waney edge present\n", bodyFont));
                } else {
                    p.add(new Chunk("- Bark is absent.\n", bodyFont));
                }
            } else {
                barkPresence = woodCompleteness.getBark().getPresence().value();
                p.add(new Chunk("- Bark is " + barkPresence + "\n", bodyFont));
            }
        } else {
            p.add(new Chunk("- Bark information was not recorded.\n", bodyFont));
        }
    }

    return p;
}

From source file:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

private Paragraph getHeartSapwoodDetails(TridasWoodCompleteness woodCompleteness, WoodType type) {
    Paragraph p = new Paragraph();

    String presence = null;/*w w w  .  j  av  a  2 s  . co m*/
    String presenceStr = null;
    String missingRings = null;
    String missingRingsStr = null;
    String foundationStr = null;
    String woodTypeStr = null;
    Integer nrSapwoodRings = null;

    // Extract data from woodcompleteness based on type
    if (type == WoodType.HEARTWOOD) {
        // Extract Heartwood details
        woodTypeStr = "heartwood";
        if (woodCompleteness.getHeartwood() != null) {

            // Presence / Absence
            if (woodCompleteness.getHeartwood().getPresence() != null) {
                if (woodCompleteness.getHeartwood().getPresence().equals(ComplexPresenceAbsence.UNKNOWN)) {
                    // if heartwood presence is unknown all other details are irrelevant
                    p.add(new Chunk("- No " + woodTypeStr + " details recorded.", bodyFont));
                    return p;
                } else {
                    presence = woodCompleteness.getHeartwood().getPresence().value();
                }
            }

            // Missing rings
            if (woodCompleteness.getHeartwood().getMissingHeartwoodRingsToPith() != null) {
                missingRingsStr = woodCompleteness.getHeartwood().getMissingHeartwoodRingsToPith().toString();
                missingRings = missingRingsStr;
            } else {
                missingRingsStr = "an unknown number of";
            }

            // Missing rings foundation
            if (woodCompleteness.getHeartwood().getMissingHeartwoodRingsToPithFoundation() != null) {
                foundationStr = woodCompleteness.getHeartwood().getMissingHeartwoodRingsToPithFoundation()
                        .toString().toLowerCase();
            } else {
                foundationStr = "unspecified reasons";
            }

        } else {
            p.add(new Chunk("- No " + woodTypeStr + " details recorded.", bodyFont));
            return p;
        }
    } else if (type == WoodType.SAPWOOD) {
        // Extract Sapwood details
        woodTypeStr = "sapwood";
        if (woodCompleteness.getSapwood() != null) {

            // Presence / Absence
            if (woodCompleteness.getSapwood().getPresence() != null) {
                if (woodCompleteness.getSapwood().getPresence().equals(ComplexPresenceAbsence.UNKNOWN)) {
                    // if sapwood presence is unknown all other details are irrelevant
                    p.add(new Chunk("- No " + woodTypeStr + " details recorded.", bodyFont));
                    return p;
                } else {
                    presence = woodCompleteness.getSapwood().getPresence().value();
                }
            }

            // Missing rings
            if (woodCompleteness.getSapwood().getMissingSapwoodRingsToBark() != null) {
                missingRingsStr = woodCompleteness.getSapwood().getMissingSapwoodRingsToBark().toString();
                missingRings = missingRingsStr;
            } else {
                missingRingsStr = "an unknown number of";
            }

            // No. of rings present
            if (woodCompleteness.getSapwood().getNrOfSapwoodRings() != null) {
                nrSapwoodRings = woodCompleteness.getSapwood().getNrOfSapwoodRings();
            }

            // Missing rings foundation
            if (woodCompleteness.getSapwood().getMissingSapwoodRingsToBarkFoundation() != null) {
                foundationStr = woodCompleteness.getSapwood().getMissingSapwoodRingsToBarkFoundation()
                        .toString().toLowerCase();
            } else {
                foundationStr = "unspecified reasons";
            }
        } else {
            p.add(new Chunk("- No " + woodTypeStr + " details recorded.", bodyFont));
            return p;
        }

    } else {
        return null;
    }

    // Set output strings for presence/absence
    if (presence == "unknown") {
        //presenceStr = "- Whether " + woodTypeStr + " is present or not is unknown";
        presenceStr = "";
    } else if (presence == null) {
        //presenceStr = "- Presence of " + woodTypeStr + " has not been specified";
        presenceStr = "";
    } else {
        presenceStr = "- " + woodTypeStr.substring(0, 1).toUpperCase() + woodTypeStr.substring(1) + " is "
                + presence;
        if (woodTypeStr == "sapwood" && nrSapwoodRings != null) {
            presenceStr += ". A total of " + nrSapwoodRings + " sapwood rings were identified";
        }
    }

    // Compile paragraph   
    p.add(new Chunk(presenceStr, bodyFont));
    if (missingRings != null) {
        p.add(new Chunk(". The analyst records that " + missingRingsStr, bodyFont));
        if (missingRingsStr.equals("1")) {
            p.add(new Chunk(" ring is ", bodyFont));
        } else {
            p.add(new Chunk(" rings are ", bodyFont));
        }
        p.add(new Chunk("missing, the justification of which is noted as: \"" + foundationStr + "\".",
                bodyFont));
    } else if (presence == "complete") {
        // Wood is complete so no mention required about missing rings
        p.add(new Chunk(". ", bodyFont));
    } else {
        //p.add(new Chunk(". Details about missing " + woodTypeStr + " rings was not recorded.", bodyFont));
        p.add(new Chunk("", bodyFont));
    }

    return p;

}

From source file:org.tellervo.desktop.print.SeriesReport.java

License:Open Source License

/**
 * iText paragraph of element and sample info
 * @return Paragraph//from w  w w. j  a  va2s  .  co m
 */
private Paragraph getElementAndSampleInfo() {
    Paragraph p = new Paragraph();

    TridasElement telem = s.getMeta(Metadata.ELEMENT, TridasElement.class);
    TridasSample tsamp = s.getMeta(Metadata.SAMPLE, TridasSample.class);

    p.add(new Chunk("Element and sample details:\n", subSubSectionFont));

    p.add(new Chunk("- Taxon:  ", bodyFont));
    p.add(new Chunk(telem.getTaxon().getNormal() + "\n", bodyFontItalic));
    p.add(new Chunk("- Element type: " + telem.getType().getNormal() + "\n", bodyFont));
    p.add(new Chunk("- Sample type: " + tsamp.getType().getNormal() + "\n", bodyFont));
    return p;

}

From source file:org.tpspencer.tal.mvc.document.DocumentWriterImpl.java

License:Apache License

public void start(String title, String appTitle, String author, String creator) {
    document.addTitle(title);//  ww w .j av  a2  s  .c  om
    document.addSubject(appTitle);
    document.addCreator(creator);
    document.addAuthor(author);
    document.addCreationDate();

    Paragraph page = new Paragraph();
    page.add(new Paragraph()); // Empty line

    page.add(new Paragraph(title, titleFont));
    page.add(new Paragraph(appTitle, subHeadingFont));

    try {
        document.add(page);
    } catch (DocumentException e) {
        throw new IllegalArgumentException(
                "Cannot add title page to document, likely an incorrect argument when setting chapter up", e);
    }
}

From source file:permit.PermitPdf.java

License:Open Source License

void writePage(HttpServletResponse res, Permit permit) {
    ////w  ww.j a v  a  2 s  .  c  o  m
    // paper size legal (A4) 8.5 x 11
    // page 1-inch = 72 points
    //
    String fileName = "row_permit_" + permit.getId() + ".pdf";
    Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11"
    Document document = new Document(pageSize, 36, 36, 18, 18);
    ServletOutputStream out = null;
    Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL);
    Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD);
    Font fnts = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL);
    Font fntbs = new Font(Font.TIMES_ROMAN, 8, Font.BOLD);
    String spacer = "   ";
    PdfPTable header = getHeader();
    Bond bond = permit.getBond();
    Invoice invoice = permit.getInvoice();
    if (bond == null)
        bond = new Bond();
    if (invoice == null)
        invoice = new Invoice();
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter writer = PdfWriter.getInstance(document, baos);
        String str = "";
        document.open();
        document.add(header);
        //
        // title
        float[] width = { 100f }; // one cell
        PdfPTable table = new PdfPTable(width);
        table.setWidthPercentage(100.0f);
        PdfPCell cell = new PdfPCell(new Phrase("Right Of Way Excavation Permit", fntb));
        //         
        cell.setBorder(Rectangle.BOTTOM);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        document.add(table);
        //
        // we need these later
        Paragraph pp = new Paragraph();
        Chunk ch = new Chunk(" ", fntb);
        Phrase phrase = new Phrase();
        //
        float[] widths = { 14f, 20f, 17f, 18f, 13f, 20f }; // percentages
        table = new PdfPTable(widths);
        table.setWidthPercentage(100.0f);
        table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
        //
        // first row
        cell = new PdfPCell(new Phrase("Company", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getCompany().getName(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Status", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getStatus(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Permit", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getPermit_num(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //
        // 2nd row
        //
        cell = new PdfPCell(new Phrase("Responsible", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getContact().getFullName(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Inspector", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getReviewer().getFullName(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Date Issued", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getDate(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //
        // 3rd row
        cell = new PdfPCell(new Phrase("Project", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getProject(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Permit Fee", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("$" + permit.getFee(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Start Date", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(permit.getStart_date(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        //
        // 4th row
        cell = new PdfPCell(new Phrase("Bond Amount", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("$" + bond.getAmount(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Expiration Date", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(bond.getExpire_date(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Invoice", fntb));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase(invoice.getStatus(), fnt));
        cell.setBorder(Rectangle.NO_BORDER);
        table.addCell(cell);
        document.add(table);
        //
        phrase = new Phrase(new Chunk(spacer, fnt));
        document.add(phrase);
        //
        float[] widths2 = { 25f, 15f, 15f, 25f, 10f, 10f };
        table = new PdfPTable(widths2);
        table.setWidthPercentage(100.0f);
        cell = new PdfPCell(new Phrase("Address", fntb));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Cut Type", fntb));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Utility", fntb));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Description", fntb));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Width", fntb));
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Length", fntb));
        table.addCell(cell);
        List<Excavation> list = permit.getExcavations();
        if (list != null && list.size() > 0) {
            for (Excavation one : list) {
                cell = new PdfPCell(new Phrase(one.getAddress().getAddress(), fnt));
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(one.getCut_type(), fnt));
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(one.getUtility_type().getName(), fnt));
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(one.getCut_description(), fnt));
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(one.getWidth(), fnt));
                table.addCell(cell);
                cell = new PdfPCell(new Phrase(one.getLength(), fnt));
                table.addCell(cell);
            }
        }
        document.add(table);
        //
        pp = new Paragraph();
        pp.setIndentationLeft(12);
        pp.setAlignment(Element.ALIGN_LEFT);
        pp.setLeading(0f, 1f);
        ch = new Chunk("\nSpecial Provisions\n", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        ch = new Chunk(permit.getNotes() + "\n", fnt);
        phrase.add(ch);
        pp.add(phrase);
        document.add(pp);
        //
        pp = new Paragraph();
        pp.setIndentationLeft(12);
        pp.setAlignment(Element.ALIGN_LEFT);
        ch = new Chunk("Standards Conditions of Approval\n", fntb);
        phrase = new Phrase();
        phrase.add(ch);
        pp.add(phrase);
        document.add(pp);
        //
        pp = new Paragraph();
        pp.setIndentationLeft(12);
        pp.setAlignment(Element.ALIGN_LEFT);
        pp.setLeading(0f, 1f);
        ch = new Chunk("1 - " + conditions[0] + "\n", fntbs);
        phrase = new Phrase();
        phrase.add(ch);
        pp.add(phrase);
        document.add(pp);
        //
        int jj = 1;
        for (int j = 1; j < conditions.length; j++) {
            jj = j + 1;
            pp = new Paragraph();
            pp.setLeading(0f, 1f);
            pp.setIndentationLeft(12);
            pp.setAlignment(Element.ALIGN_LEFT);
            ch = new Chunk(jj + " - " + conditions[j] + "\n", fnts);
            phrase = new Phrase();
            phrase.add(ch);
            pp.add(phrase);
            document.add(pp);
        }

        pp = new Paragraph();
        pp.setIndentationLeft(20);
        pp.setAlignment(Element.ALIGN_RIGHT);
        ch = new Chunk("\n\n___________________\n", fnt);
        phrase = new Phrase();
        phrase.add(ch);
        pp.add(phrase);
        ch = new Chunk(permit.getReviewer().getFullName(), fnt);
        phrase = new Phrase();
        phrase.add(ch);
        pp.add(phrase);
        document.add(pp);
        document.close();
        writer.close();
        res.setHeader("Expires", "0");
        res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
        res.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        res.setHeader("Pragma", "public");
        //
        // setting the content type
        res.setContentType("application/pdf");
        //
        // the contentlength is needed for MSIE!!!
        res.setContentLength(baos.size());
        //
        out = res.getOutputStream();
        if (out != null) {
            baos.writeTo(out);
        }
    } catch (Exception ex) {
        logger.error(ex);
    }

}

From source file:questions.objects.DifferentLeadings.java

public static void main(String[] args) {
    Document document = new Document(PageSize.A7);
    try {/* ww  w  .j a  v a  2  s .  c o  m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();
        Chunk space = new Chunk(' ');
        String text = "Quick brown fox jumps over the lazy dog.";
        Phrase phrase1 = new Phrase(text, new Font(Font.HELVETICA, 12));
        Phrase phrase2 = new Phrase(new Chunk(text, new Font(Font.TIMES_ROMAN, 24)));
        Phrase phrase3 = new Phrase(text, new Font(Font.COURIER, 8));
        Phrase phrase4 = new Phrase(text, new Font(Font.HELVETICA, 4));
        Paragraph paragraph = new Paragraph();
        paragraph.add(phrase1);
        paragraph.add(space);
        paragraph.add(phrase2);
        paragraph.add(space);
        paragraph.add(phrase3);
        paragraph.add(space);
        paragraph.add(phrase4);
        paragraph.setMultipliedLeading(1.5f);
        paragraph.setAlignment(Element.ALIGN_JUSTIFIED);
        ColumnText column = new ColumnText(writer.getDirectContent());
        column.setSimpleColumn(document.left(), document.bottom(), document.right(), document.top());
        column.addElement(paragraph);
        column.go();
        document.newPage();
        document.add(paragraph);
    } catch (DocumentException de) {
        System.err.println(de.getMessage());
    } catch (IOException ioe) {
        System.err.println(ioe.getMessage());
    }
    document.close();
}

From source file:questions.separators.DottedGlue.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*ww w  . j a  va  2 s .  c  om*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();

        PdfContentByte canvas = writer.getDirectContent();
        canvas.moveTo(document.left(), document.top());
        canvas.lineTo(document.left(), 550);
        canvas.moveTo(document.right(), document.top());
        canvas.lineTo(document.right(), 550);
        canvas.stroke();

        Chunk separator = new Chunk(new DottedLineSeparator());

        // two parts
        Paragraph p1 = new Paragraph();
        p1.add(new Chunk("Chapter 1"));
        p1.add(separator);
        p1.add(new Chunk("p 10"));

        // 3 parts
        Paragraph p2 = new Paragraph();
        p2.add(new Chunk("Chapter 2"));
        p2.add(separator);
        p2.add(new Chunk("x"));
        p2.add(separator);
        p2.add(new Chunk("y"));

        // line ends with separator
        Paragraph p3 = new Paragraph();
        p3.add(new Chunk("Chapter 3"));
        p3.add(separator);

        // line starts with a separator
        Paragraph p4 = new Paragraph();
        p4.add(separator);
        p4.add(new Chunk("chapter 4"));

        // line IS a separator
        Paragraph p5 = new Paragraph();
        p5.add(separator);

        // line IS a separator + leading
        Paragraph p6 = new Paragraph(40);
        p6.add(separator);

        // separator galore
        Paragraph p7 = new Paragraph();
        p7.setAlignment(Element.ALIGN_JUSTIFIED);
        for (int i = 0; i < 10; i++) {
            p7.add(new Chunk("This is a test hippopotamus hippopotamus"));
            if (i % 4 == 0)
                p7.add(" hippopotamus hippopotamus hippopotamus hippopotamus");
            p7.add(separator);
        }

        document.add(p1);
        document.add(p1);
        document.add(p2);
        document.add(p3);
        document.add(p4);
        document.add(p5);
        document.add(p6);
        document.add(p7);

        ColumnText ct = new ColumnText(writer.getDirectContent());
        ct.addElement(p1);
        ct.addElement(p1);
        ct.addElement(p2);
        ct.addElement(p3);
        ct.addElement(p4);
        ct.addElement(p5);
        ct.addElement(p6);
        ct.addElement(p7);
        ct.setSimpleColumn(36, 36, 436, 536);
        ct.go();
        canvas.rectangle(36, 36, 400, 500);
        canvas.stroke();
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:questions.separators.LineSeparator1.java

public static void main(String[] args) {
    Document document = new Document();
    try {// w  ww.java  2 s.c  o m
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();

        Paragraph separator = new Paragraph(0);
        separator.add(new Chunk(new LineSeparator(1, 80, Color.RED, Element.ALIGN_LEFT, -2)));

        ColumnText column = new ColumnText(writer.getDirectContent());
        for (int i = 0; i < 5; i++) {
            column.addElement(StarSeparators.TEXT);
            column.addElement(separator);
        }
        column.setSimpleColumn(36, 36, 295, 806);
        column.go();
        column.setSimpleColumn(300, 36, 559, 806);
        column.go();
        document.newPage();

        for (int i = 0; i < 10; i++) {
            document.add(StarSeparators.TEXT);
            document.add(separator);
        }
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:questions.separators.LineSeparator3.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*from  ww  w  .  j a v a2s.c o m*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();

        Paragraph p = new Paragraph(StarSeparators.TEXT);
        VerticalPositionMark separator = new LineSeparator(1, 100, Color.RED, Element.ALIGN_RIGHT, -2);
        p.add(separator);

        ColumnText column = new ColumnText(writer.getDirectContent());
        for (int i = 0; i < 5; i++) {
            column.addElement(p);
        }
        column.setSimpleColumn(36, 36, 295, 806);
        column.go();
        column.setSimpleColumn(300, 36, 559, 806);
        column.go();
        document.newPage();

        for (int i = 0; i < 10; i++) {
            document.add(p);
        }
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}

From source file:questions.separators.PascalsTriangle.java

public static void main(String[] args) {
    Document document = new Document();
    try {/*  w w  w .j  av  a 2  s.c  o m*/
        PdfWriter.getInstance(document, new FileOutputStream(RESULT));
        document.open();

        Chunk separator = new Chunk(new VerticalPositionMark());
        int[] line = { 0, 1, 0 };

        Paragraph p;
        int n;
        int[] tmp;
        for (int i = 0; i < 20; i++) {
            p = new Paragraph(separator);
            n = line.length;
            tmp = new int[n + 1];
            tmp[0] = line[0];
            tmp[n] = line[n - 1];
            tmp[n - 1] = line[n - 2];
            for (int j = 1; j < n - 1; j++) {
                p.add(new Chunk(String.valueOf(line[j])));
                p.add(separator);
                tmp[j] = line[j] + line[j - 1];
            }
            document.add(p);
            line = tmp;
        }
        document.close();
    } catch (Exception de) {
        de.printStackTrace();
    }
}