Example usage for com.lowagie.text List List

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

Introduction

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

Prototype

public List() 

Source Link

Document

Constructs a List.

Usage

From source file:classroom.filmfestival_b.Movies13.java

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

    // step 1//from w ww .  j av  a2s  .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:classroom.filmfestival_b.Movies14.java

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

    // step 1//w ww.j  av  a 2  s  .c o  m
    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 = new PdfPCell();
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        p = new Paragraph("FILMFESTIVAL", bold);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        cell.setColspan(2);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell();
        cell.setFixedHeight(20);
        cell.setColspan(2);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setCellEvent(new Movies14().new PageCell());
        table.addCell(cell);
        table.setHeaderRows(2);
        table.setFooterRows(1);
        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:classroom.filmfestival_b.Movies15.java

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

    // step 1//  w w  w.  ja va2  s .  c o  m
    Document document = new Document();
    try {
        // step 2
        OutputStream os = new FileOutputStream(RESULT);
        PdfWriter writer = 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.setComplete(false);
        table.setWidths(new float[] { 1, 5 });
        File f;
        Paragraph p;
        Chunk c;
        PdfPCell cell = new PdfPCell();
        Font bold = new Font(Font.HELVETICA, 12, Font.BOLD);
        Font italic = new Font(Font.HELVETICA, 12, Font.ITALIC);
        p = new Paragraph("FILMFESTIVAL", bold);
        p.setAlignment(Element.ALIGN_CENTER);
        cell.addElement(p);
        cell.setColspan(2);
        cell.setBorder(PdfPCell.NO_BORDER);
        table.addCell(cell);
        cell = new PdfPCell();
        cell.setFixedHeight(20);
        cell.setColspan(2);
        cell.setBorder(PdfPCell.NO_BORDER);
        cell.setCellEvent(new Movies14().new PageCell());
        table.addCell(cell);
        table.setHeaderRows(2);
        table.setFooterRows(1);
        int counter = 10;
        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);
            if (counter % 10 == 0) {
                document.add(table);
            }
            System.out.println(writer.getPageNumber());
            counter++;
        }
        table.setComplete(true);
        document.add(table);
        // step 5
        document.close();
    } catch (IOException e) {
        LOGGER.error("IOException: ", e);
    } catch (DocumentException e) {
        LOGGER.error("DocumentException: ", e);
    }
}

From source file:Driver.RunTestCases.java

License:Open Source License

public void generateReport() {

    File file = new File("Report1.pdf");
    FileOutputStream fileout = null;
    try {/*from w w w  . j av  a  2s  .com*/
        fileout = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    Document document = new Document();
    try {
        PdfWriter.getInstance(document, fileout);
    } catch (DocumentException e) {
        e.printStackTrace();
    }
    document.addAuthor("AGTT");
    document.addTitle("AGTT Report");

    document.open();
    Boolean status = true;
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new FileReader("Results.txt"));
        String line = null;
        String testCase = null;
        Chunk chunk = null;
        int index = 0;
        List list = new List();
        while ((line = reader.readLine()) != null) {
            if (line.contains("Case")) {

                if (index > 0) {
                    System.out.println(line + status + list.size());
                    if (status == false) {
                        chunk.setBackground(Color.RED);
                    }
                    if (status == true) {
                        chunk.setBackground(Color.GREEN);
                    }
                    document.add(chunk);
                    document.add((Element) list);
                    status = true;
                    list = new List();
                    testCase = null;
                }
                chunk = new Chunk(line + "\n");
                Font font = new Font(Font.TIMES_ROMAN);
                font.setSize(18);
                chunk.setFont(font);
                index++;
            } else {
                if (line.contains("not")) {
                    status = false;
                }
                list.add(line);
            }
            //   document.add(chunk);
        }
    } catch (IOException | DocumentException e) {
        e.printStackTrace();
    }
    document.close();
}

From source file:fr.opensagres.xdocreport.itext.extension.ExtendedPdfPCell.java

License:Open Source License

@Override
public void addElement(Element element) {
    this.empty = false;
    if (element instanceof ListItem) {
        List aList = new List();
        aList.setIndentationLeft(((ListItem) element).getIndentationLeft());
        aList.add(element);/* www . j  a  va 2 s.c  o  m*/
        super.addElement(aList);
    } else {
        super.addElement(element);
    }
}

From source file:org.sonar.report.pdf.DefaultPDFReporter.java

License:Open Source License

private void printProjectInfo(Project project, Section section)
        throws DocumentException, org.dom4j.DocumentException {
    List data = new List();
    data.add(new ListItem(super.getTextProperty("general.name") + ": " + project.getName()));
    data.add(new ListItem(super.getTextProperty("general.description") + ": " + project.getDescription()));
    data.add(new ListItem(super.getTextProperty("general.modules") + ": "));

    List sublist = new List();
    if (project.getSubprojects().size() != 0) {
        Iterator<Project> it = project.getSubprojects().iterator();
        while (it.hasNext()) {
            sublist.add(new ListItem(it.next().getName()));
        }//from   ww w  .j  av  a2s . c  om
    } else {
        sublist.add(new ListItem(super.getTextProperty("general.no_modules")));
    }

    sublist.setIndentationLeft(indentation);
    data.add(sublist);
    section.add(data);
    printMeasures(project.getMeasures(), section);
}

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

License:Apache License

/**
 * Start a list of items inside the current section (must be present)
 *//*  www . jav a  2  s .c om*/
public void startList() {
    if (sections.size() == 0)
        throw new IllegalArgumentException("Cannot start a list if there is no section");

    list = new List();
    list.setNumbered(false);
    list.setLettered(true);
    list.setAlignindent(true);
    // list.setAutoindent(true);
    list.setIndentationLeft(20);
}