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:datasoul.servicelist.ServiceListExporterDocument.java

License:Open Source License

private LinkedList<Paragraph> addChordsShape(ArrayList<String> chordsName) throws DocumentException {
    ChordsDB chordsDB = ChordsDB.getInstance();
    String notCatalogued = "";
    LinkedList<Chunk> images = new LinkedList<Chunk>();
    LinkedList<File> filesToDelete = new LinkedList<File>();
    LinkedList<Paragraph> ret = new LinkedList<Paragraph>();

    for (int i = 0; i < chordsName.size(); i++) {
        Chord chord = chordsDB.getChordByName(chordsName.get(i));
        if (chord != null) {
            ChordShapePanel csp = new ChordShapePanel(2, chord.getName(), chord.getShape());
            BufferedImage im = csp.createImage();
            try {
                File tmp = File.createTempFile("datasoul-img", ".png");
                tmp.deleteOnExit();/*from ww w.j a  va2s  .  c o m*/
                filesToDelete.add(tmp);

                ImageIO.write(im, "png", tmp);
                Chunk c = new Chunk(Image.getInstance(tmp.getAbsolutePath()), 0, 0, false);
                images.add(c);
            } catch (IOException e) {
                JOptionPane.showMessageDialog(null, java.util.ResourceBundle
                        .getBundle("datasoul/internationalize").getString("INTERNAL ERROR: ") + e.getMessage());
            }
        } else {
            notCatalogued += chordsName.get(i);
        }
    }

    Paragraph p = new Paragraph();

    if (!images.isEmpty()) {
        for (Chunk c : images) {
            p.add(c);
        }
        p.setLeading(images.getFirst().getImage().getScaledHeight());
        p.setKeepTogether(true);
    }

    ret.add(p);

    if (!notCatalogued.equals("")) {
        p = new Paragraph(
                java.util.ResourceBundle.getBundle("datasoul/internationalize")
                        .getString("THE FOLLOWING CHORDS ARE NOT CATALOGED: ") + notCatalogued,
                FontFactory.getFont(FontFactory.HELVETICA, 8));
        ret.add(p);
    }

    for (File f : filesToDelete) {
        try {
            f.delete();
        } catch (Exception e) {
            //ignore, it will be deleted on exit
        }
    }

    return ret;
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Set the logo of Humboldt on the left corner and the current date on the
 * right corner/*from   w  w  w .j  av  a2s .c o  m*/
 * 
 * @param document
 *            reference of the pdfDocument object
 */
protected void addHeading(Document document) {
    Paragraph paragraph = new Paragraph();
    PdfPTable table = createMyStandardTable(2);

    table.setTotalWidth(TABLEWIDTH);
    PdfPCell cell;

    Image img = new ResourceLoader("pdf/humboldt_logo.png").getImage();
    img.setAlignment(Element.ALIGN_BOTTOM);
    img.scaleToFit(205f, 65f);
    cell = new PdfPCell(img);

    cell.setBorder(0);
    table.addCell(cell);

    String date = new SimpleDateFormat("dd.MM.yyyy", Locale.GERMAN).format(Calendar.getInstance().getTime());

    cell = new PdfPCell(new Phrase(date));
    cell.setBorder(0);
    cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
    cell.setVerticalAlignment(Element.ALIGN_BOTTOM);
    table.addCell(cell);

    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);
    cell = new PdfPCell(new Phrase(""));
    cell.setBorder(Rectangle.BOTTOM);
    table.addCell(cell);

    paragraph.add(table);
    addEmptyLine(paragraph, 1);

    try {
        document.add(paragraph);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

/**
 * Adds a signature field with a date field to the document. Should be the
 * last part that is added to the document.
 * //from  w ww .j  a va2  s .c o m
 * @param document
 *            represents the PDF before it is saved
 * @param role
 *            word for the kind of person that shall sign the paper
 */
protected void addSignatureField(Document document, String role) {
    Paragraph paragraph = new Paragraph();

    //this table contains the signatureTable and the dataTable.
    // this purpose makes it easier to format
    PdfPTable table = createMyStandardTable(2);

    //the first column is double times greater than the second column
    try {
        table.setWidths(new float[] { 10f, 20f });
    } catch (DocumentException e) {
        e.printStackTrace();
    }

    //create and fill date table
    PdfPTable dateTable = new PdfPTable(1);

    PdfPCell cell = new PdfPCell(new Phrase(""));
    //just the bottom border will be displayed (line for date)
    cell.setBorderWidthTop(0);
    cell.setBorderWidthLeft(0);
    cell.setBorderWidthRight(0);

    dateTable.addCell(cell);

    cell = new PdfPCell(new Phrase("Datum"));
    cell.setBorder(0);

    dateTable.addCell(cell);

    //put date table into the 'parent' table
    cell = new PdfPCell(dateTable);
    cell.setBorder(0);
    table.addCell(cell);

    //create and fill signature table
    PdfPTable signatureTable = new PdfPTable(1);
    cell = new PdfPCell(new Phrase(""));
    //just the bottom border will be displayed (line for signature)
    cell.setBorderWidthTop(0);
    cell.setBorderWidthLeft(0);
    cell.setBorderWidthRight(0);

    signatureTable.addCell(cell);

    cell = new PdfPCell(new Phrase("Unterschrift " + role));
    cell.setBorder(0);

    signatureTable.addCell(cell);

    //put signature table into the 'parent' table
    cell = new PdfPCell(signatureTable);
    cell.setBorder(0);
    table.addCell(cell);

    paragraph.add(table);
    try {
        document.add(paragraph);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

protected static void addEmptyLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph(" "));
    }/*from w  w w  .j  a v a2s  .c  o  m*/
}

From source file:de.dhbw.humbuch.util.PDFHandler.java

protected static void addEmptyLineToDocument(Document document, int number) {
    Paragraph paragraph = new Paragraph();
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph(" "));
    }/*from   w ww.  ja  v a  2s. c  o m*/

    try {
        document.add(paragraph);
    } catch (DocumentException e) {
        System.err.println("Could not add empty line to documnet " + e.getStackTrace());
    }
}

From source file:ec.edu.uce.erp.web.common.util.CustomPDFExporter.java

private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    // We add one empty line
    addEmptyLine(preface, 1);//from   w w w .j  av  a 2 s.  com
    // Lets write a big header
    preface.add(new Paragraph(mapValuesPDF.get(ConstantesReporte.TITULO), titleFont));

    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.com ;-).",
    //            redFont));

    document.add(preface);
}

From source file:edu.harvard.mcz.imagecapture.encoder.LabelEncoder.java

License:Open Source License

@SuppressWarnings("hiding")
public static boolean printList(List<UnitTrayLabel> taxa) throws PrintFailedException {
    boolean result = false;
    UnitTrayLabel label = new UnitTrayLabel();
    LabelEncoder encoder = new LabelEncoder(label);
    Image image = encoder.getImage();
    int counter = 0;
    try {/*from   w w w. ja  v  a  2  s.c o  m*/
        Document document = new Document();
        PdfWriter.getInstance(document, new FileOutputStream("labels.pdf"));
        document.setPageSize(PageSize.LETTER);
        document.open();

        PdfPTable table = new PdfPTable(4);
        table.setWidthPercentage(100f);
        //table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
        float[] cellWidths = { 30f, 20f, 30f, 20f };
        table.setWidths(cellWidths);

        UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle();
        if (taxa == null) {
            taxa = uls.findAll();
        }
        Iterator<UnitTrayLabel> i = taxa.iterator();
        PdfPCell cell = null;
        PdfPCell cell_barcode = null;
        // Create two lists of 12 cells, the first 6 of each representing
        // the left hand column of 6 labels, the second 6 of each 
        // representing the right hand column.  
        // cells holds the text for each label, cells_barcode the barcode.
        ArrayList<PdfPCell> cells = new ArrayList<PdfPCell>(12);
        ArrayList<PdfPCell> cells_barcode = new ArrayList<PdfPCell>(12);
        for (int x = 0; x < 12; x++) {
            cells.add(null);
            cells_barcode.add(null);
        }
        int cellCounter = 0;
        while (i.hasNext()) {
            // Loop through all of the taxa (unit tray labels) found to print 
            label = i.next();
            for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) {
                // For each taxon, loop through the number of requested copies 
                // Generate a text and a barcode cell for each, and add to array for page
                log.debug("Label " + toPrint + " of " + label.getNumberToPrint());
                cell = new PdfPCell();
                cell.setBorderColor(Color.LIGHT_GRAY);
                cell.setVerticalAlignment(PdfPCell.ALIGN_TOP);
                cell.disableBorderSide(PdfPCell.RIGHT);
                cell.setPaddingLeft(3);

                String higherNames = "";
                if (label.getTribe().trim().length() > 0) {
                    higherNames = label.getFamily() + ": " + label.getSubfamily() + ": " + label.getTribe();
                } else {
                    higherNames = label.getFamily() + ": " + label.getSubfamily();
                }
                Paragraph higher = new Paragraph();
                higher.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                higher.add(new Chunk(higherNames));
                cell.addElement(higher);

                Paragraph name = new Paragraph();
                Chunk genus = new Chunk(label.getGenus().trim() + " ");
                genus.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                Chunk species = new Chunk(label.getSpecificEpithet().trim());
                Chunk normal = null; // normal font prefix to preceed specific epithet (nr. <i>epithet</i>)
                if (label.getSpecificEpithet().contains(".") || label.getSpecificEpithet().contains("[")) {
                    if (label.getSpecificEpithet().startsWith("nr. ")) {
                        normal = new Chunk("nr. ");
                        normal.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                        species = new Chunk(label.getSpecificEpithet().trim().substring(4));
                        species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                    } else {
                        species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                    }
                } else {
                    species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                }
                String s = "";
                if (label.getSubspecificEpithet().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk subspecies = new Chunk(s + label.getSubspecificEpithet().trim());
                if (label.getSubspecificEpithet().contains(".")
                        || label.getSubspecificEpithet().contains("[")) {
                    subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));
                } else {
                    subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                }
                if (label.getInfraspecificRank().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk infraRank = new Chunk(s + label.getInfraspecificRank().trim());
                infraRank.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));

                if (label.getInfraspecificEpithet().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk infra = new Chunk(s + label.getInfraspecificEpithet().trim());
                infra.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC));
                if (label.getUnNamedForm().trim().length() > 0) {
                    s = " ";
                } else {
                    s = "";
                }
                Chunk unNamed = new Chunk(s + label.getUnNamedForm().trim());
                unNamed.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL));

                name.add(genus);
                if (normal != null) {
                    name.add(normal);
                }
                name.add(species);
                name.add(subspecies);
                name.add(infraRank);
                name.add(infra);
                name.add(unNamed);
                cell.addElement(name);

                Paragraph authorship = new Paragraph();
                authorship.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                if (label.getAuthorship() != null && label.getAuthorship().length() > 0) {
                    Chunk c_authorship = new Chunk(label.getAuthorship());
                    authorship.add(c_authorship);
                }
                cell.addElement(authorship);
                //cell.addElement(new Paragraph(" "));
                if (label.getDrawerNumber() != null && label.getDrawerNumber().length() > 0) {
                    Paragraph drawerNumber = new Paragraph();
                    drawerNumber.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                    Chunk c_drawerNumber = new Chunk(label.getDrawerNumber());
                    drawerNumber.add(c_drawerNumber);
                    cell.addElement(drawerNumber);
                } else {
                    if (label.getCollection() != null && label.getCollection().length() > 0) {
                        Paragraph collection = new Paragraph();
                        collection.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL));
                        Chunk c_collection = new Chunk(label.getCollection());
                        collection.add(c_collection);
                        cell.addElement(collection);
                    }
                }

                cell_barcode = new PdfPCell();
                cell_barcode.setBorderColor(Color.LIGHT_GRAY);
                cell_barcode.disableBorderSide(PdfPCell.LEFT);
                cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP);

                encoder = new LabelEncoder(label);
                image = encoder.getImage();
                image.setAlignment(Image.ALIGN_TOP);
                cell_barcode.addElement(image);

                cells.add(cellCounter, cell);
                cells_barcode.add(cellCounter, cell_barcode);

                cellCounter++;
                // If we have hit a full set of 12 labels, add them to the document
                // in two columns, filling left column first, then right
                if (cellCounter == 12) {
                    // add a page of 12 cells in columns of two.
                    for (int x = 0; x < 6; x++) {
                        if (cells.get(x) == null) {
                            PdfPCell c = new PdfPCell();
                            c.setBorder(0);
                            table.addCell(c);
                            table.addCell(c);
                        } else {
                            table.addCell(cells.get(x));
                            table.addCell(cells_barcode.get(x));
                        }
                        if (cells.get(x + 6) == null) {
                            PdfPCell c = new PdfPCell();
                            c.setBorder(0);
                            table.addCell(c);
                            table.addCell(c);
                        } else {
                            table.addCell(cells.get(x + 6));
                            table.addCell(cells_barcode.get(x + 6));
                        }
                    }
                    // Reset to begin next page
                    cellCounter = 0;
                    document.add(table);
                    table = new PdfPTable(4);
                    table.setWidthPercentage(100f);
                    table.setWidths(cellWidths);
                    for (int x = 0; x < 12; x++) {
                        cells.set(x, null);
                        cells_barcode.set(x, null);
                    }
                }
            } // end loop through toPrint (for a taxon)
            counter++;
        } // end while results has next (for all taxa requested)
          // get any remaining cells in pairs
        for (int x = 0; x < 6; x++) {
            if (cells.get(x) == null) {
                PdfPCell c = new PdfPCell();
                c.setBorder(0);
                table.addCell(c);
                table.addCell(c);
            } else {
                table.addCell(cells.get(x));
                table.addCell(cells_barcode.get(x));
            }
            if (cells.get(x + 6) == null) {
                PdfPCell c = new PdfPCell();
                c.setBorder(0);
                table.addCell(c);
                table.addCell(c);
            } else {
                table.addCell(cells.get(x + 6));
                table.addCell(cells_barcode.get(x + 6));
            }
        }
        // add any remaining cells
        document.add(table);
        try {
            document.close();
        } catch (Exception e) {
            throw new PrintFailedException("No labels to print." + e.getMessage());
        }
        // Check to see if there was content in the document.
        if (counter == 0) {
            result = false;
        } else {
            // Printed to pdf ok.
            result = true;
            // Increment number printed.
            i = taxa.iterator();
            while (i.hasNext()) {
                label = i.next();
                for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) {
                    label.setPrinted(label.getPrinted() + 1);
                }
                label.setNumberToPrint(0);
                try {
                    uls.attachDirty(label);
                } catch (SaveFailedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new PrintFailedException("File not found.");
    } catch (DocumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new PrintFailedException("Error buiding PDF document.");
    } catch (OutOfMemoryError e) {
        System.out.println("Out of memory error. " + e.getMessage());
        System.out.println("Failed.  Too many labels.");
        throw new PrintFailedException("Ran out of memory, too many labels at once.");
    }
    return result;
}

From source file:EplanPrinter.RTFWrite.java

License:Open Source License

public String addItem(String comment, String category, String group) throws DocumentException, IOException {
    if (cg.compareTo(group) != 0) {
        count = 1;// ww  w . j a v  a2s  .com
        cg = group;
        cc = category;

        Font groupContent = new Font();
        groupContent.setStyle("bold");
        groupContent.setStyle("underline");
        groupContent.setSize(12);
        Paragraph g = new Paragraph(group, groupContent);

        Font catContent = new Font();
        catContent.setSize(12);
        Paragraph c = new Paragraph(category, catContent);
        c.setIndentationLeft(30);
        document.add(g);
        document.add(c);
    } else if (cc.compareTo(category) != 0) {
        count = 1;
        cc = category;
        Paragraph c = new Paragraph(category);
        c.setIndentationLeft(30);
        document.add(c);
    }
    Paragraph p = new Paragraph();
    //document.add(p);
    String test = count + ". " + comment;
    test = test.replaceAll("<p>", " ");
    test = test.replaceAll("</p>", " ");

    if (test.indexOf("<ol>") != -1) {
        test = test.replaceAll("<ol>", "");
        test = test.replaceAll("</ol>", "");
        test = test.replaceAll("</li>", "<br />");
        int subCount = 1;
        while (test.indexOf("<li>") != -1) {
            test = test.replaceFirst("<li>", subCount + ". ");
            subCount++;
        }
        int marker = test.lastIndexOf("<br />");
        String sub1 = test.substring(0, marker);
        String sub2 = test.substring(marker);
        sub2 = sub2.replaceAll("<br />", "");
        test = sub1 + sub2;
    }
    if (test.indexOf("<ul>") != -1) {
        test = test.replaceAll("<ul>", "");
        test = test.replaceAll("</ul>", "");
        test = test.replaceAll("</li>", "<br />");
        int c = 149;
        char ch = (char) 149;
        test = test.replaceAll("<li>", "&bull;");
        int marker = test.lastIndexOf("<br />");
        String sub1 = test.substring(0, marker);
        String sub2 = test.substring(marker);
        sub2 = sub2.replaceAll("<br />", "");
        test = sub1 + sub2;
    }

    StringReader str = new StringReader(test);
    List<Element> e = HTMLWorker.parseToList(str, null);
    for (int k = 0; k < e.size(); ++k) {
        p.add((com.lowagie.text.Element) e.get(k));
    }

    p.setIndentationLeft(40);
    p.setFirstLineIndent(30);
    document.add(p);

    count = count + 1;

    return "";
}

From source file:es.uniovi.asw.personalletter.PDFTextWritter.java

/**
 * Ttulo del documento.//from   w ww  .j av  a  2 s .c  o  m
 * @param document Documento en cuestin
 * @throws DocumentException Excepcion generada por algn problema
 */
private void addTitlePage(Document document) throws DocumentException {
    Paragraph preface = new Paragraph();
    addEmptyLine(preface, 1);
    preface.add(new Paragraph("CitizensLoader PDF", 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.com ;-).",
    //            redFont));
    //
    //      document.add(preface);
    //      // Start a new page
    //      document.newPage();
    document.add(preface);
    addEmptyLine(preface, 2);
}

From source file:es.uniovi.asw.personalletter.PDFTextWritter.java

private void addEmptyLine(Paragraph paragraph, int number) {
    for (int i = 0; i < number; i++) {
        paragraph.add(new Paragraph(" "));
    }//from   www.  jav a  2 s .  co m
}