Example usage for com.lowagie.text.pdf PdfPCell PdfPCell

List of usage examples for com.lowagie.text.pdf PdfPCell PdfPCell

Introduction

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

Prototype

public PdfPCell(PdfPTable table, PdfPCell style) 

Source Link

Document

Constructs a PdfPCell with a PdfPtable.

Usage

From source file:classroom.filmfestival_b.Movies13.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {

    // step 1//from w w w . j a v  a  2s. c om
    Document document = new Document();
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter.getInstance(document, os);
        // step 3
        document.open();
        // step 4
        Session session = (Session) MySessionFactory.currentSession();
        Query q = session.createQuery("from FilmTitle order by title");
        java.util.List<FilmTitle> results = q.list();

        PdfPTable table = new PdfPTable(2);
        table.setWidths(new float[] { 1, 5 });
        File f;
        Paragraph p;
        Chunk c;
        PdfPCell cell;
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        for (FilmTitle movie : results) {
            f = new File("resources/classroom/filmposters/" + movie.getFilmId() + ".jpg");
            if (f.exists()) {
                cell = new PdfPCell(Image.getInstance(f.getPath()), true);
                cell.setPadding(2);
            } else {
                cell = new PdfPCell();
            }
            table.addCell(cell);
            p = new Paragraph(20);
            c = new Chunk(movie.getTitle(), bold);
            c.setAnchor("http://cinema.lowagie.com/titel.php?id=" + movie.getFilmId());
            p.add(c);
            c = new Chunk(" (" + movie.getYear() + ") ", italic);
            p.add(c);
            c = new Chunk("IMDB");
            c.setAnchor("http://www.imdb.com/title/tt" + movie.getImdb());
            p.add(c);
            cell = new PdfPCell();
            cell.setUseAscender(true);
            cell.setUseDescender(true);
            cell.addElement(p);
            Set<DirectorName> directors = movie.getDirectorNames();
            List list = new List();
            for (DirectorName director : directors) {
                list.add(director.getName());
            }
            cell.addElement(list);
            table.addCell(cell);
        }
        document.add(table);
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:net.sf.firemox.deckbuilder.BuildBook.java

License:Open Source License

/**
 * /*from ww w .java  2s .  co m*/
 */
@SuppressWarnings("unchecked")
public void build() {
    BufferedReader in = null;
    try {
        in = new BufferedReader(new InputStreamReader(new FileInputStream(MToolKit.getFile(checklist)),
                Charset.forName("ISO-8859-1")));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return;
    }
    // String charset = Charset.forName("ISO-8859-1").name();
    String line = null;
    int cur = 0;
    int row = 0;
    PdfPCell[] cells = new PdfPCell[3];
    PdfPTable table = new PdfPTable(3);
    Document document = new Document(PageSize.A4);
    try {
        PdfWriter.getInstance(document, new FileOutputStream(this.pdfBook));
        document.open();
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

    try {
        in.readLine(); // Removing header line
        String[] tokens = new String[] { "\t", "\\s{2,}" };
        while ((line = in.readLine()) != null) {
            // line = new String(line.getBytes(),charset);
            // Card# Card Name Artist Color Rarity
            String[] fields = null;
            for (String token : tokens) {
                fields = line.split(token);
                if (fields.length == 5) {
                    break;
                }
            }

            if (fields == null || fields.length < 5) {
                System.err.println("Unable to parse " + line);
                continue;
            } else if (fields.length > 5) {
                System.out.println("Too many value found on " + line);
            }
            fields[1] = fields[1].trim();
            fields[1] = fields[1].replaceAll("[ -]", "_");
            fields[1] = fields[1].replaceAll("[/',\\u0092]", "");
            fields[1] = fields[1].replaceAll("", "AE");
            System.out.println("Inserting " + fields[1]);
            if (basicLands.containsKey(fields[1])) {
                int x = basicLands.get(fields[1]);
                cells[cur] = new PdfPCell(getImage(fields[1] + x), true);
                x++;
                basicLands.put(fields[1], x);
            } else {
                cells[cur] = new PdfPCell(getImage(fields[1]), true);
            }
            cur++;
            if (cur == 3) {
                for (int j = 0; j < cells.length; j++) {
                    cells[j].setPadding(2.0f);
                }
                table.getRows().add(new PdfPRow(cells));
                row++;
                cur = 0;
                cells = new PdfPCell[3];
            }
            if (row == 3) {
                table.setWidthPercentage(100);
                document.add(table);
                table = new PdfPTable(3);
                row = 0;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.close();
}