Pojo classes film database

This is a code example of iText PDF, discover more.

10th October 2015
admin-marketing

Switch code for this example

Movie.java
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

package com.lowagie.filmfestival;

import java.util.ArrayList;
import java.util.List;

/**
 * POJO for an object that corresponds with a record
 * in the table film_movietitle.
 */
public class Movie implements Comparable {
    
    /** The title of the movie. */
    protected String title;
    /** The original title (if different from title). */
    protected String originalTitle = null;
    /** Code used by IMDB */
    protected String imdb;
    /** The year the movie was released. */
    protected int year;
    /** The duration of the movie in minutes. */
    protected int duration;
    /** The list of directors. */
    protected List directors = new ArrayList();
    /** The list of countries. */
    protected List countries= new ArrayList();
    /** The filmfestival entry info. */
    protected Entry entry = null;
    
    /**
     * Adds a director.
     * @param director one of the directors of the movie
     */
    public void addDirector(Director director) {
        directors.add(director);
    }
    
    /**
     * Adds a country.
     * @param country  one of the countries the movie was made by.
     */
    public void addCountry(Country country) {
        countries.add(country);
    }
    
    /**
     * Returns the title in the correct form.
     * @return a title
     */
    public String getMovieTitle() {
        if (title.endsWith(", A"))
            return "A " + title.substring(0, title.length() - 3);
        if (title.endsWith(", The"))
            return "The " + title.substring(0, title.length() - 5);
        return title;
    }
    
    /**
     * Returns the title in the correct form.
     * @return a title
     */
    public String getMovieTitle(boolean prefix) {
        if (title.endsWith(", A"))
        	if (prefix)
        		return "A ";
        	else
        		return title.substring(0, title.length() - 3);
        if (title.endsWith(", The"))
        	if (prefix)
        		return "The ";
        	else
        		return title.substring(0, title.length() - 5);
        if (prefix)
        	return null;
        else
        	return title;
    }
    
    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }
    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }
    /**
     * @return the originalTitle
     */
    public String getOriginalTitle() {
        return originalTitle;
    }
    /**
     * @param originalTitle the originalTitle to set
     */
    public void setOriginalTitle(String originalTitle) {
        this.originalTitle = originalTitle;
    }
    /**
     * @return the imdb
     */
    public String getImdb() {
        return imdb;
    }
    /**
     * @param imdb the imdb to set
     */
    public void setImdb(String imdb) {
        this.imdb = imdb;
    }
    /**
     * @return the year
     */
    public int getYear() {
        return year;
    }
    /**
     * @param year the year to set
     */
    public void setYear(int year) {
        this.year = year;
    }
    /**
     * @return the duration
     */
    public int getDuration() {
        return duration;
    }
    /**
     * @param duration the duration to set
     */
    public void setDuration(int duration) {
        this.duration = duration;
    }
    /**
     * @return the directors
     */
    public List getDirectors() {
        return directors;
    }
    /**
     * @return the countries
     */
    public List getCountries() {
        return countries;
    }
    /**
     * @return the entry
     */
    public Entry getEntry() {
        return entry;
    }
    /**
     * @param entry the entry to set
     */
    public void setEntry(Entry entry) {
        this.entry = entry;
        if (entry.getMovie() == null)
            entry.setMovie(this);
    }

	public int compareTo(Movie o) {
		return title.compareTo(o.title);
	}
    
}
Director.java
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

package com.lowagie.filmfestival;

/**
 * POJO for an object that corresponds with a record
 * in the table film_director.
 */
public class Director {
    
    /** The family name of the director. */
    protected String name;
    /** The given name of the director. */
    protected String givenName;
    
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * @return the givenName
     */
    public String getGivenName() {
        return givenName;
    }
    /**
     * @param givenName the givenName to set
     */
    public void setGivenName(String givenName) {
        this.givenName = givenName;
    }
}
Country.java
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

package com.lowagie.filmfestival;

/**
 * POJO for an object that corresponds with a record
 * in the table film_country.
 */
public class Country {
    /** The name of a country. */
    protected String country;

    /**
     * @return the country
     */
    public String getCountry() {
        return country;
    }

    /**
     * @param country the country to set
     */
    public void setCountry(String country) {
        this.country = country;
    }
}
Entry.java
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

package com.lowagie.filmfestival;

import java.util.ArrayList;
import java.util.List;

/**
 * POJO for an object that corresponds with a record
 * in the table festival_entry.
 */
public class Entry {
    
    /** The festival year. */
    protected int year;
    /** The movie. */
    protected Movie movie;
    /** The category. */
    protected Category category;
    /** The screenings. */
    protected List screenings = new ArrayList();
    
    /**
     * Adds a screening to this entry.
     */
    public void addScreening(Screening screening) {
        screenings.add(screening);
    }
    
    /**
     * @return the year
     */
    public int getYear() {
        return year;
    }
    /**
     * @param year the year to set
     */
    public void setYear(int year) {
        this.year = year;
    }
    /**
     * @return the movie
     */
    public Movie getMovie() {
        return movie;
    }
    /**
     * @param movie the movie to set
     */
    public void setMovie(Movie movie) {
        this.movie = movie;
        if (movie.getEntry() == null)
            movie.setEntry(this);
    }
    /**
     * @return the category
     */
    public Category getCategory() {
        return category;
    }
    /**
     * @param category the category to set
     */
    public void setCategory(Category category) {
        this.category = category;
    }
    /**
     * @return the screenings
     */
    public List getScreenings() {
        return screenings;
    }
}
Category.java
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

package com.lowagie.filmfestival;

/**
 * POJO for an object that corresponds with a record
 * in the table festival_category.
 */
public class Category {
    
    /** The name of the category. */
    protected String name;
    /** A short keyword for the category. */
    protected String keyword;
    /** The color code of the category. */
    protected String color;
    /** The parent category (if any). */
    protected Category parent = null;
    
    /**
     * @return the name
     */
    public String getName() {
        return name;
    }
    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }
    /**
     * @return the keyword
     */
    public String getKeyword() {
        return keyword;
    }
    /**
     * @param keyword the keyword to set
     */
    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }
    /**
     * @return the parent
     */
    public Category getParent() {
        return parent;
    }
    /**
     * @param parent the parent to set
     */
    public void setParent(Category parent) {
        this.parent = parent;
    }
    /**
     * @return the color
     */
    public String getColor() {
        return color;
    }
    /**
     * @param color the color to set
     */
    public void setColor(String color) {
        this.color = color;
    }
}
Screening.java
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

package com.lowagie.filmfestival;

import java.sql.Date;
import java.sql.Time;

/**
 * POJO for an object that corresponds with a record
 * in the table festival_screening.
 */
public class Screening {
    /** The date of the screening. */
    protected Date date;
    /** The time of the screening. */
    protected Time time;
    /** The location of the screening. */
    protected String location;
    /** Is this a screening for the press only? */
    protected boolean press;
    /** The movie that will be screened. */
    protected Movie movie = null;
    
    /**
     * @return the date
     */
    public Date getDate() {
        return date;
    }
    /**
     * @param date the date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }
    /**
     * @return the time
     */
    public Time getTime() {
        return time;
    }
    /**
     * @param time the time to set
     */
    public void setTime(Time time) {
        this.time = time;
    }
    /**
     * @return the location
     */
    public String getLocation() {
        return location;
    }
    /**
     * @param location the location to set
     */
    public void setLocation(String location) {
        this.location = location;
    }
    /**
     * @return the press
     */
    public boolean isPress() {
        return press;
    }
    /**
     * @param press the press to set
     */
    public void setPress(boolean press) {
        this.press = press;
    }
    /**
     * @return the movie
     */
    public Movie getMovie() {
        return movie;
    }
    /**
     * @param movie the movie to set
     */
    public void setMovie(Movie movie) {
        this.movie = movie;
    }
}
PojoFactory.java
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

package com.lowagie.filmfestival;

import java.io.UnsupportedEncodingException;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.lowagie.database.DatabaseConnection;

/**
 * A factory that makes it easy to query the database using
 * a series of static methods.
 */
public class PojoFactory {
    /** SQL statement to get all the movies of the festival. */
    public static final String MOVIES =
        "SELECT m.id, m.title, m.original_title, m.imdb, m.year, m.duration, "
        + "e.year, c.name, c.keyword, c.color "
        + "FROM film_movietitle m, festival_entry e, festival_category c "
        + "WHERE m.id = e.film_id AND e.category_id = c.id "
        + "ORDER BY m.title";
    /** SQL statement to get the directors of a specific movie. */
    public static final String DIRECTORS =
        "SELECT d.name, d.given_name "
        + "FROM film_director d, film_movie_director md "
        + "WHERE md.film_id = ? AND md.director_id = d.id";
    /** SQL statement to get the movies of a specific director. */
    public static final String MOVIEDIRECTORS =
        "SELECT m.id, m.title, m.original_title, m.imdb, m.year, m.duration "
        + "FROM film_movietitle m, film_movie_director md "
        + "WHERE md.director_id = ? AND md.film_id = m.id "
        + "ORDER BY m.title";
    /** SQL statement to get the countries of a specific movie. */
    public static final String COUNTRIES =
        "SELECT c.country "
        + "FROM film_country c, film_movie_country mc "
        + "WHERE mc.film_id = ? AND mc.country_id = c.id";
    /** SQL statement to get the movies from a specific country. */
    public static final String MOVIECOUNTRIES =
        "SELECT m.id, m.title, m.original_title, m.imdb, m.year, m.duration "
        + "FROM film_movietitle m, film_movie_country mc "
        + "WHERE mc.country_id = ? AND mc.film_id = m.id "
        + "ORDER BY m.title";
    /** SQL statement to get all the days of the festival. */
    public static final String DAYS =
        "SELECT DISTINCT day FROM festival_screening ORDER BY day";
    /** SQL statament to get all the locations at the festival */
    public static final String LOCATIONS =
        "SELECT DISTINCT location FROM festival_screening ORDER by location";
    /** SQL statement to get screenings. */
    public static final String SCREENINGS =
        "SELECT m.title, m.original_title, m.imdb, m.year, m.duration,"
        + "s.day, s.time, s.location, s.press, "
        + "e.year, c.name, c.keyword, c.color, m.id "
        + "FROM festival_screening s, film_movietitle m, "
        + "festival_entry e, festival_category c "
        + "WHERE day = ? AND s.film_id = m.id "
        + "AND m.id = e.film_id AND e.category_id = c.id";
    /** SQL statement to get screenings. */
    public static final String MOVIESCREENINGS =
        "SELECT s.day, s.time, s.location, s.press "
        + "FROM festival_screening s "
        + "WHERE s.film_id = ?";
    /** SQL statement to get screenings. */
    public static final String PRESS =
        "SELECT m.title, m.original_title, m.imdb, m.year, m.duration,"
        + "s.day, s.time, s.location, s.press, "
        + "e.year, c.name, c.keyword, c.color, m.id "
        + "FROM festival_screening s, film_movietitle m, "
        + "festival_entry e, festival_category c "
        + "WHERE s.press=1 AND s.film_id = m.id "
        + "AND m.id = e.film_id AND e.category_id = c.id "
        + "ORDER BY day, time ASC";
    
    /**
     * Fills a Movie POJO using a ResultSet.
     * @param rs a ResultSet with records from table film_movietitle
     * @return a Movie POJO
     * @throws UnsupportedEncodingException 
     */
    public static Movie getMovie(ResultSet rs)
        throws SQLException, UnsupportedEncodingException {
        Movie movie = new Movie();
        movie.setTitle(new String(rs.getBytes("title"), "UTF-8"));
        if (rs.getObject("original_title") != null)
            movie.setOriginalTitle(
               new String(rs.getBytes("original_title"), "UTF-8"));
        movie.setImdb(rs.getString("imdb"));
        movie.setYear(rs.getInt("year"));
        movie.setDuration(rs.getInt("duration"));
        return movie;
    }
    
    /**
     * Fills a Director POJO using a ResultSet.
     * @param rs a ResultSet with records from table file_director
     * @return a Director POJO
     */
    public static Director getDirector(ResultSet rs)
        throws SQLException, UnsupportedEncodingException {
        Director director = new Director();
        director.setName(new String(rs.getBytes("name"), "UTF-8"));
        director.setGivenName(new String(rs.getBytes("given_name"),"UTF-8"));
        return director;
    }
    
    /**
     * Fills a Country POJO using a ResultSet.
     * @param rs a ResultSet with records from table file_director
     * @return a Director POJO
     */
    public static Country getCountry(ResultSet rs) throws SQLException {
        Country country = new Country();
        country.setCountry(rs.getString("country"));
        return country;
    }
    
    /**
     * Fills an Entry POJO using a ResultSet.
     * @param rs a resultSet with records from table festival_entry
     * @return an Entry POJO
     */
    public static Entry getEntry(ResultSet rs) throws SQLException {
        Entry entry = new Entry();
        entry.setYear(rs.getInt("year"));
        return entry;
    }
    
    /**
     * Fills a Category POJO using a ResultSet.
     * @param rs a resultSet with records from table festival_category
     * @return a Category POJO
     */
    public static Category getCategory(ResultSet rs) throws SQLException {
        Category category = new Category();
        category.setName(rs.getString("name"));
        category.setKeyword(rs.getString("keyword"));
        category.setColor(rs.getString("color"));
        return category;
    }
    
    /**
     * Fills a Screening POJO using a ResultSet.
     * @param rs a ResultSet with records from table festival_screening
     * @return a Screening POJO
     */
    public static Screening getScreening(ResultSet rs) throws SQLException {
        Screening screening = new Screening();
        screening.setDate(rs.getDate("day"));
        screening.setTime(rs.getTime("time"));
        screening.setLocation(rs.getString("location"));
        screening.setPress(rs.getInt("press") == 1);
        return screening;
    }

    /**
     * Returns a list with Screening objects, if you pass
     * a DatabaseConnection and a day.
     * @param connection a connection to the film festival database
     * @param day a day (java.sql.Date)
     * @return a List of Screening POJOs
     * @throws UnsupportedEncodingException 
     */
    public static List getScreenings(
        DatabaseConnection connection, Date day)
        throws SQLException, UnsupportedEncodingException {
        List list = new ArrayList();
        PreparedStatement stm =
            connection.createPreparedStatement(SCREENINGS);
        stm.setDate(1, day);
        ResultSet rs = stm.executeQuery();
        Screening screening;
        Movie movie;
        Entry entry;
        Category category;
        while (rs.next()) {
            screening = getScreening(rs);
            movie = getMovie(rs);
            for (Director director :
                getDirectors(connection, rs.getInt("id"))) {
                movie.addDirector(director);
            }
            for (Country country :
                getCountries(connection, rs.getInt("id"))) {
                movie.addCountry(country);
            }
            entry = getEntry(rs);
            category = getCategory(rs);
            entry.setCategory(category);
            entry.setMovie(movie);
            movie.setEntry(entry);
            screening.setMovie(movie);
            list.add(screening);
        }
        stm.close();
        return list;
    }

    /**
     * Returns a list with Screening objects, if you pass
     * a DatabaseConnection and a day.
     * @param connection a connection to the film festival database
     * @param film_id a movie id
     * @return a List of Screening POJOs
     * @throws UnsupportedEncodingException 
     */
    public static List getScreenings(
        DatabaseConnection connection, int film_id)
        throws SQLException, UnsupportedEncodingException {
        List list = new ArrayList();
        PreparedStatement stm =
            connection.createPreparedStatement(MOVIESCREENINGS);
        stm.setInt(1, film_id);
        ResultSet rs = stm.executeQuery();
        Screening screening;
        while (rs.next()) {
            screening = getScreening(rs);
            list.add(screening);
        }
        stm.close();
        return list;
    }

    /**
     * Returns a list with Screening objects, if you pass
     * a DatabaseConnection and a day.
     * @param connection a connection to the film festival database
     * @param day a day (java.sql.Date)
     * @return a List of Screening POJOs
     * @throws UnsupportedEncodingException 
     */
    public static List getPressPreviews(DatabaseConnection connection)
        throws SQLException, UnsupportedEncodingException {
        List list = new ArrayList();
        Statement stm = connection.createStatement();
        ResultSet rs = stm.executeQuery(PRESS);
        Screening screening;
        Movie movie;
        Entry entry;
        Category category;
        while (rs.next()) {
            screening = getScreening(rs);
            movie = getMovie(rs);
            for (Director director : getDirectors(connection, rs.getInt("id"))) {
                movie.addDirector(director);
            }
            for (Country country : getCountries(connection, rs.getInt("id"))) {
                movie.addCountry(country);
            }
            entry = getEntry(rs);
            category = getCategory(rs);
            entry.setCategory(category);
            entry.setMovie(movie);
            movie.setEntry(entry);
            screening.setMovie(movie);
            list.add(screening);
        }
        stm.close();
        return list;
    }
    
    /**
     * Returns a list with Movie objects.
     * @param connection a connection to the filmfestival database
     * @return a List of Screening POJOs
     * @throws SQLException 
     * @throws UnsupportedEncodingException 
     */
    public static List getMovies(DatabaseConnection connection)
        throws SQLException, UnsupportedEncodingException {
        List list = new ArrayList();
        Statement stm = connection.createStatement();
        ResultSet rs = stm.executeQuery(MOVIES);
        Movie movie;
        Entry entry;
        Category category;
        while (rs.next()) {
            movie = getMovie(rs);
            entry = getEntry(rs);
            category = getCategory(rs);
            entry.setCategory(category);
            for (Screening screening : getScreenings(connection, rs.getInt("id"))) {
                entry.addScreening(screening);
            }
            movie.setEntry(entry);
            for (Director director : getDirectors(connection, rs.getInt("id"))) {
                movie.addDirector(director);
            }
            for (Country country : getCountries(connection, rs.getInt("id"))) {
                movie.addCountry(country);
            }
            list.add(movie);
        }
        return list;
    }
    
    /**
     * Returns a list with Director objects.
     * @param connection a connection to the filmfestival database
     * @param director_id the id of a movie
     * @return a List of Screening POJOs
     * @throws SQLException 
     * @throws UnsupportedEncodingException 
     */
    public static List getDirectors(
        DatabaseConnection connection, int movie_id)
        throws SQLException, UnsupportedEncodingException {
        List list = new ArrayList();
        PreparedStatement directors =
            connection.createPreparedStatement(DIRECTORS);
        directors.setInt(1, movie_id);
        ResultSet rs = directors.executeQuery();
        while (rs.next()) {
            list.add(getDirector(rs));
        }
        return list;
    }
    
    /**
     * Returns a list with Country objects.
     * @param connection a connection to the filmfestival database
     * @param movie_id the id of a movie
     * @return a List of Screening POJOs
     * @throws SQLException 
     * @throws UnsupportedEncodingException 
     */
    public static List getCountries(
        DatabaseConnection connection, int movie_id)
        throws SQLException, UnsupportedEncodingException {
        List list = new ArrayList();
        PreparedStatement countries =
            connection.createPreparedStatement(COUNTRIES);
        countries.setInt(1, movie_id);
        ResultSet rs = countries.executeQuery();
        while (rs.next()) {
            list.add(getCountry(rs));
        }
        return list;
    }
    
    /**
     * Returns a list with Movie objects.
     * @param connection a connection to the filmfestival database
     * @param director_id the id of a director
     * @return a List of Screening POJOs
     * @throws SQLException 
     * @throws UnsupportedEncodingException 
     */
    public static List getMovies(
        DatabaseConnection connection, int director_id)
        throws SQLException, UnsupportedEncodingException {
        List list = new ArrayList();
        PreparedStatement movies =
            connection.createPreparedStatement(MOVIEDIRECTORS);
        movies.setInt(1, director_id);
        ResultSet rs = movies.executeQuery();
        Movie movie;
        while (rs.next()) {
            movie = getMovie(rs);
            for (Country country : getCountries(connection, rs.getInt("id"))) {
                movie.addCountry(country);
            }
            list.add(movie);
        }
        return list;
    }
    
    /**
     * Returns a list with Movie objects.
     * @param connection a connection to the filmfestival database
     * @param country_id the id of a country
     * @return a List of Screening POJOs
     * @throws SQLException 
     * @throws UnsupportedEncodingException 
     */
    public static List getMovies(
       DatabaseConnection connection, String country_id)
        throws SQLException, UnsupportedEncodingException {
        List list = new ArrayList();
        PreparedStatement movies =
            connection.createPreparedStatement(MOVIECOUNTRIES);
        movies.setString(1, country_id);
        ResultSet rs = movies.executeQuery();
        while (rs.next()) {
            Movie movie = getMovie(rs);
            for (Director director : getDirectors(connection, rs.getInt("id"))) {
                movie.addDirector(director);
            }
            list.add(movie);
        }
        return list;
    }
    
    /**
     * Returns an ArrayList containing all the filmfestival days.
     * @param connection a connection to the database.
     * @return a list containing dates.
     */
    public static List getDays(DatabaseConnection connection)
        throws SQLException {
        List list = new ArrayList();
        Statement stm = connection.createStatement();
        ResultSet rs = stm.executeQuery(DAYS);
        while (rs.next()) {
            list.add(rs.getDate("day"));
        }
        stm.close();
        return list;
    }
    
    /**
     * Returns an ArrayList containing all the screening locations.
     * @param connection a connection to the database.
     * @return a list containing location codes.
     */
    public static List getLocations(DatabaseConnection connection)
        throws SQLException {
        List list = new ArrayList();
        Statement stm = connection.createStatement();
        ResultSet rs =
            stm.executeQuery(LOCATIONS);
        while (rs.next()) {
            list.add(rs.getString("location"));
        }
        stm.close();
        return list;
    }
}
FilmFonts.java
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

package com.lowagie.filmfestival;

import com.itextpdf.text.Font;
import com.itextpdf.text.Font.FontFamily;

/**
 * Contains a series of static Font objects that are used throughout the book.
 */
public class FilmFonts {

    /** A font used in our PDF file */
    public static final Font NORMAL = new Font(FontFamily.HELVETICA, 12, Font.NORMAL);
    /** A font used in our PDF file */
    public static final Font BOLD = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
    /** A font used in our PDF file */
    public static final Font ITALIC = new Font(FontFamily.HELVETICA, 12, Font.ITALIC);
    /** A font used in our PDF file */
    public static final Font BOLDITALIC = new Font(FontFamily.HELVETICA, 12, Font.BOLDITALIC);

}
MovieComparator.java
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

package com.lowagie.filmfestival;

import java.util.Comparator;

/**
 * Compares movies based on their title or the year, they're made in.
 */
public class MovieComparator implements Comparator {

    /** Type for movies have to be sorted by title. */
    public static int BY_TITLE = 0;
    /** Type for movies have to be sorted by production year. */
    public static int BY_YEAR = 1;
    
    /** The type; can be BY_TITLE or BY_YEAR. */
    protected int type;
    
    /**
     * Creates an instance of the MovieComparator.
     * @param type defines how the movies will be sorted;
     * can be BY_TITLE or BY_YEAR
     */
    public MovieComparator(int type) {
        this.type = type;
    }

    /**
     * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
     */
    public int compare(Movie m1, Movie m2) {
        if (type == BY_YEAR) {
            int c = m1.getYear() - m2.getYear();
            if (c != 0)
                return c;
        }
        return m1.getTitle().compareTo(m2.getTitle());
    }

}
PojoToElementFactory.java
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

package com.lowagie.filmfestival;

import com.itextpdf.text.Chunk;
import com.itextpdf.text.Element;
import com.itextpdf.text.List;
import com.itextpdf.text.Phrase;

public class PojoToElementFactory {

    /**
     * Creates a Phrase containing the title of a Movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    public static final Phrase getMovieTitlePhrase(final Movie movie) {
        return new Phrase(movie.getMovieTitle(), FilmFonts.NORMAL);
    }
    
    /**
     * Creates a Phrase containing the original title of a Movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    public static final Phrase getOriginalTitlePhrase(final Movie movie) {
        if (movie.getOriginalTitle() == null)
            return new Phrase("", FilmFonts.NORMAL);
        return new Phrase(movie.getOriginalTitle(), FilmFonts.ITALIC);
    }
    
    /**
     * Creates a Phrase containing the name of a Director.
     * @param director a Director object
     * @return a Phrase object
     */
    public static final Phrase getDirectorPhrase(final Director director) {
        Phrase phrase = new Phrase();
        phrase.add(new Chunk(director.getName(), FilmFonts.BOLD));
        phrase.add(new Chunk(", ", FilmFonts.BOLD));
        phrase.add(new Chunk(director.getGivenName(), FilmFonts.NORMAL));
        return phrase;
    }
    
    /**
     * Creates a Phrase containing the name of a Country.
     * @param country a Country object
     * @return a Phrase object
     */
    public static final Phrase getCountryPhrase(final Country country) {
        return new Phrase(country.getCountry(), FilmFonts.NORMAL);
    }
    
    /**
     * Creates a list with directors.
     * @param movie a Movie object
     * @return a List object
     */
    public static final List getDirectorList(Movie movie) {
        List list = new List();
        for (Director director : movie.getDirectors()) {
            list.add(String.format(
               "%s, %s", director.getName(), director.getGivenName()));
        }
        return list;
    }
    
    /**
     * Creates a list with countries.
     * @param movie a Movie object
     * @return a List object
     */
    public static final List getCountryList(Movie movie) {
        List list = new List();
        for (Country country : movie.getCountries()) {
            list.add(country.getCountry());
        }
        return list;
    }

    /**
     * Creates a phrase with the production year of a movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    public static final Element getYearPhrase(Movie movie) {
        Phrase p = new Phrase();
        p.add(new Chunk("Year: ", FilmFonts.BOLD));
        p.add(new Chunk(String.valueOf(movie.getYear()), FilmFonts.NORMAL));
        return p;
    }

    /**
     * Creates a phrase with the run length of a movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    public static final Element getDurationPhrase(Movie movie) {
        Phrase p = new Phrase();
        p.add(new Chunk("Duration: ", FilmFonts.BOLD));
        p.add(new Chunk(String.valueOf(movie.getDuration()), FilmFonts.NORMAL));
        return p;
    }
}
Movie.cs
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
using System.Collections.Generic;

/**
 * POJO for an object that corresponds with a record
 * in the table film_movietitle.
 */
 namespace kuujinbo.iTextInAction2Ed.Intro_1_2 {
  public class Movie {
// =========================================================================== 
    /** The title of the movie. */
    public string Title { get; set; }
    /** The original title (if different from title). */
    public string OriginalTitle { get; set; }
    /** Code used by IMDB */
    public string Imdb { get; set; }
    /** The year the movie was released. */
    public int Year { get; set; }
    /** The duration of the movie in minutes. */
    public int Duration { get; set; }
    /** The list of directors. */
    private List _directors = new List();
    public List Directors { 
      get { return _directors; }
    }
    /** The list of countries. */
    private List _countries = new List();
    public List Countries { 
      get { return _countries; }
    }
// ---------------------------------------------------------------------------
    /** The filmfestival entry info. */
    private Entry _entry;
    public Entry entry { 
      get { return _entry; }
      set {
        _entry = value;
        if (_entry.movie == null) _entry.movie = this;
      } 
    }
// ---------------------------------------------------------------------------
    /**
     * Adds a director.
     * @param director one of the directors of the movie
     */
    public void AddDirector(Director director) {
      _directors.Add(director);
    }
// ---------------------------------------------------------------------------
    /**
     * Adds a country.
     * @param country  one of the countries the movie was made by.
     */
    public void AddCountry(Country country) {
      _countries.Add(country);    
    }
// ---------------------------------------------------------------------------
    /**
     * Returns the title in the correct form.
     * @return a title
     */
    public string MovieTitle {
      get {
        var title = Title;
        if (!string.IsNullOrEmpty(title)) {
          if (title.EndsWith(", A"))
              return "A " + title.Substring(0, title.Length - 3);
          if (title.EndsWith(", The"))
              return "The " + title.Substring(0, title.Length - 5);
          return title;
        }
        return null;
      }
    } 
// ---------------------------------------------------------------------------    
    /**
     * Returns the title in the correct form.
     * @return a title
     */
    public string GetMovieTitle(bool prefix) {
      var title = Title;
      if (title.EndsWith(", A")) {
      return prefix ? "A " : title.Substring(0, title.Length - 3);
      }
      
      if (title.EndsWith(", The")) {
        return prefix ? "The " : title.Substring(0, title.Length - 5);
      }
      
      return prefix ? null : title;
    }    
// =========================================================================== 
  }
}
Director.cs
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

/**
 * POJO for an object that corresponds with a record
 * in the table film_director.
 */
namespace kuujinbo.iTextInAction2Ed.Intro_1_2 {
  public class Director {
// =========================================================================== 
    public string Name { get; set; }
    public string GivenName { get; set; }
// =========================================================================== 
  }
}
Country.cs
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

/**
 * POJO for an object that corresponds with a record
 * in the table film_country.
 */
namespace kuujinbo.iTextInAction2Ed.Intro_1_2 {
  public class Country {
// =========================================================================== 
    public string Name { get; set; }
// =========================================================================== 
  }
}
Entry.cs
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
using System;
using System.Collections.Generic;
/**
 * POJO for an object that corresponds with a record
 * in the table festival_entry.
 */
namespace kuujinbo.iTextInAction2Ed.Intro_1_2 {
  public class Entry {
// =========================================================================== 
    /** The festival year. */
    public int Year { get; set; }
    /** The category. */
    public Category category { get; set; }
// ---------------------------------------------------------------------------
    /** The movie. */
    private Movie _movie;
    public Movie movie { 
      get { return _movie; }
      set {
        _movie = value;
        if (_movie.entry == null) _movie.entry = this;
      } 
    }    
// ---------------------------------------------------------------------------
    /** The screenings. */
    private List _screenings = new List();
    public List Screenings { 
      get { return _screenings; }
    }
// ---------------------------------------------------------------------------
    /**
     * Adds a screening to this entry.
     */
    public void AddScreening(Screening screening) {
      _screenings.Add(screening);    
    }
// =========================================================================== 
  }
}
Category.cs
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

/**
 * POJO for an object that corresponds with a record
 * in the table festival_category.
 */
namespace kuujinbo.iTextInAction2Ed.Intro_1_2 {
  public class Category {
// =========================================================================== 
    /** The name of the category. */
    public string Name { get; set; }
    /** A short keyword for the category. */
    public string Keyword { get; set; }
    /** The color code of the category. */
    public string color { get; set; }
    /** The parent category (if any). */
    public Category Parent { get; set; }    
// =========================================================================== 
  }
} 
Screening.cs
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
using System;

/**
 * POJO for an object that corresponds with a record
 * in the table festival_screening.
 */
namespace kuujinbo.iTextInAction2Ed.Intro_1_2 {
  public class Screening {
// =========================================================================== 
    /** The date of the screening. */
    public string Date { get; set; }
    /** The time of the screening. */
    public string Time { get; set; }
    /** The location of the screening. */
    public String Location { get; set; }
    /** Is this a screening for the press only? */
    public bool Press { get; set; }
    /** The movie that will be screened. */
    public Movie movie { get; set; }
// =========================================================================== 
  }
}
PojoFactory.cs
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

/**
 * A factory that makes it easy to query the database using
 * a series of static methods using System.Data.SQLite:
 * http://sqlite.phxsoftware.com/
 * ###########################################################################
 * System.Data.SQLite is the ADO.NET 2.0/3.5 provider for the
 * SQLite database engine:
 * http://www.sqlite.org/
 * ###########################################################################
 * 
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 * before July 2010, ADO.NET data provider **DEPENDENT** code was used.
 * this has been fixed. if you want to use a different provider see the 
 * README.txt file. the change requires minimumal effort.
 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 */
namespace kuujinbo.iTextInAction2Ed.Intro_1_2 {
  public class PojoFactory {
// =========================================================================== 
    /**
     * Fills a Movie POJO using a DbDataReader.
     * @param rs a DbDataReader with records from table film_movietitle
     * @return a Movie POJO
     */
    public static Movie GetMovie(DbDataReader r) {
      return new Movie() {
        Title = r["title"].ToString(), 
        OriginalTitle = r["original_title"] != null 
            ? r["original_title"].ToString() : "",
        Imdb = r["imdb"].ToString(), 
        Year = Convert.ToInt32(r["year"]),
        Duration = Convert.ToInt32(r["duration"])
      };
    }
// ---------------------------------------------------------------------------
    /**
     * Fills a Director POJO using a DbDataReader.
     * @param rs a DbDataReader with records from table file_director
     * @return a Director POJO
     */
    public static Director GetDirector(DbDataReader r) {
      return new Director() {
        Name = r["name"].ToString(), 
        GivenName = r["given_name"].ToString()
      };
    }
// ---------------------------------------------------------------------------
    /**
     * Fills a Country POJO using a DbDataReader.
     * @param rs a DbDataReader with records from table file_director
     * @return a Country POJO
     */
    public static Country GetCountry(DbDataReader r) {
      return new Country() {
        Name = r["country"].ToString()
      };
    }
// ---------------------------------------------------------------------------
    /**
     * Fills an Entry POJO using a DbDataReader.
     * @param rs a DbDataReader with records from table festival_entry
     * @return an Entry POJO
     */
    public static Entry GetEntry(DbDataReader r) {
      return new Entry() {
        Year = Convert.ToInt32(r["year"])
      };
    }
// ---------------------------------------------------------------------------
    /**
     * Fills a Category POJO using a DbDataReader.
     * @param rs a DbDataReader with records from table festival_category
     * @return a Category POJO
     */
    public static Category GetCategory(DbDataReader r) {
      return new Category() {
        Name = r["name"].ToString(), 
        Keyword = r["keyword"].ToString(),
        color = r["color"].ToString()
      };
    }
// ---------------------------------------------------------------------------
    /**
     * Fills a Screening POJO using a DbDataReader.
     * @param rs a DbDataReader with records from table festival_screening
     * @return a Screening POJO
     */
    public static Screening GetScreening(DbDataReader r)  {
      return new Screening() {
        Date = r["day"].ToString(), 
        Time = r["time"].ToString(),
        Location = r["location"].ToString(), 
        Press = Convert.ToInt32(r["press"]) == 1
      };
    }
// ---------------------------------------------------------------------------
    /**
     * Returns a list with Screening objects
     * @param film_id a movie id
     * @return a List of Screening POJOs
     */
    public static List GetScreenings(int film_id) {
      List list = new List();
      using (var c =  AdoDB.Provider.CreateConnection()) {
        c.ConnectionString = AdoDB.CS;
        using (DbCommand cmd = c.CreateCommand()) {
          cmd.CommandText = AdoDB.MOVIESCREENINGS;
          cmd.Parameters.Add(cmd.CreateParameter());
          cmd.Parameters[0].ParameterName = "@film_id";
          cmd.Parameters[0].Value = film_id;
          c.Open();
          using (var r = cmd.ExecuteReader()) {
            while (r.Read()) {
              list.Add(GetScreening(r));
            }
          }
        }
      }
      return list;
    }    
// ---------------------------------------------------------------------------
    /**
     * Returns a list with Screening objects, if you pass
     * a stringified date.
     * @param day stringified date "yyyy-MM-dd"
     * @return a List of Screening POJOs
     */
    public static List GetScreenings(string day)  {
      List list = new List();
      using (var c =  AdoDB.Provider.CreateConnection()) {
        c.ConnectionString = AdoDB.CS;
        using (DbCommand cmd = c.CreateCommand()) {
          cmd.CommandText = AdoDB.SCREENINGS;
          cmd.Parameters.Add(cmd.CreateParameter());
          cmd.Parameters[0].ParameterName = "@day";
          cmd.Parameters[0].Value = day;
          c.Open();
          using (var r = cmd.ExecuteReader()) {
            while (r.Read()) {
              Screening screening = GetScreening(r);
              Movie movie = GetMovie(r);
              foreach (var d in GetDirectors(Convert.ToInt32(r["id"]))) {
                movie.AddDirector(d);
              }
              foreach (var cn in GetCountries(Convert.ToInt32(r["id"]))) {
                movie.AddCountry(cn);
              }
              Entry entry = GetEntry(r);
              Category category = GetCategory(r);
              entry.category = category;
              entry.movie = movie;
              movie.entry = entry;
              screening.movie = movie;
              list.Add(screening);
            }
          }
        }
      }
      return list;
    }
// ---------------------------------------------------------------------------    
    /**
     * Returns a list with Movie objects.
     */
    public static IEnumerable GetMovies() {
      return GetMovies(false);
    }
    /*
     * @param sort_by_year => LINQ sort by movie year
     */
    public static IEnumerable GetMovies(bool sort_by_year) {
      List list = new List();
      using (var c =  AdoDB.Provider.CreateConnection()) {
        c.ConnectionString = AdoDB.CS;
        using (DbCommand cmd = c.CreateCommand()) {
          cmd.CommandText = AdoDB.MOVIES;
          c.Open();
          using (var r = cmd.ExecuteReader()) {
            while (r.Read()) {
              Movie movie = GetMovie(r);
              Entry entry = GetEntry(r);
              Category category = GetCategory(r);
              entry.category = category;
              int film_id = Convert.ToInt32(r["id"]);
              foreach ( Screening screening in GetScreenings(film_id) ) {
                entry.AddScreening(screening);
              }
              movie.entry = entry;
              foreach ( Director director in GetDirectors(film_id) ) {
                movie.AddDirector(director);
              }
              foreach ( Country country in GetCountries(film_id) ) {
                movie.AddCountry(country);
              }
              list.Add(movie);
            }
          }
        }
      }
      if (!sort_by_year) {
        return list;
      }
      else {
        return from m in list orderby m.Year, m.Title select m;
      }
    }    
// ---------------------------------------------------------------------------
    /**
     * Returns a list with Movie objects.
     * @param director_id the id of a director
     * @return a List of Screening POJOs
     */
    // default => return collection
    public static IEnumerable GetMovies(int director_id) 
    { return GetMovies(director_id, false);  }
    /*
     * @param sort_by_year => LINQ sort by movie year
     */
    public static IEnumerable GetMovies(
        int director_id, bool sort_by_year) 
    {
      List list = new List();
      using (var c =  AdoDB.Provider.CreateConnection()) {
        c.ConnectionString = AdoDB.CS;
        using (DbCommand cmd = c.CreateCommand()) {
          cmd.CommandText = AdoDB.MOVIEDIRECTORS;
          cmd.Parameters.Add(cmd.CreateParameter());
          cmd.Parameters[0].ParameterName = "@director_id";
          cmd.Parameters[0].Value = director_id;
          c.Open();
          using (var r = cmd.ExecuteReader()) {
            while (r.Read()) {
              list.Add(GetMovie(r));
            }
          }
        }
      }
      if (!sort_by_year) {
        return list;
      }
      else {
        return from m in list orderby m.Year, m.Title select m;      
      }      
    } 
// ---------------------------------------------------------------------------    
    /**
     * Returns a list with Movie objects.
     * @param country_id the id of a country
     * @return a List of Screening POJOs
     */
    // default => return collection
    public static IEnumerable GetMovies(string country_id)
    { return GetMovies(country_id, false); }
    /*
     * @param sort_by_year => LINQ sort by movie year
     */
    public static IEnumerable GetMovies(
        string country_id, bool sort_by_year
    ) {
      List list = new List();
      using (var c =  AdoDB.Provider.CreateConnection()) {
        c.ConnectionString = AdoDB.CS;
        using (DbCommand cmd = c.CreateCommand()) {
          cmd.CommandText = AdoDB.MOVIECOUNTRIES;
          cmd.Parameters.Add(cmd.CreateParameter());
          cmd.Parameters[0].ParameterName = "@country_id";
          cmd.Parameters[0].Value = country_id;
          c.Open();
          using (var r = cmd.ExecuteReader()) {
            while (r.Read()) {
              Movie movie = GetMovie(r);
              foreach ( Director d in GetDirectors(Convert.ToInt32(r["id"])) ) {
                movie.AddDirector(d);
              }            
              list.Add(movie);
            }
          }
        }
      }    
      if (!sort_by_year) {
        return list;
      }
      else {
        return from m in list orderby m.Year, m.Title select m;     
      }
    }       
// ---------------------------------------------------------------------------
    /**
     * Returns a list with Country objects.
     * @param connection a connection to the filmfestival database
     * @param movie_id the id of a movie
     * @return a List of Screening POJOs
     */
    public static List GetCountries(int film_id) {
      List list = new List();
      using (var c =  AdoDB.Provider.CreateConnection()) {
        c.ConnectionString = AdoDB.CS;
        using (DbCommand cmd = c.CreateCommand()) {
          cmd.CommandText = AdoDB.COUNTRIES;
          cmd.Parameters.Add(cmd.CreateParameter());
          cmd.Parameters[0].ParameterName = "@film_id";
          cmd.Parameters[0].Value = film_id;
          c.Open();
          using (var r = cmd.ExecuteReader()) {
            while (r.Read()) {
              list.Add(GetCountry(r));
            }
          }
        }
      }
      return list;
    }
// ---------------------------------------------------------------------------
    /**
     * Returns a list with Screening objects
     * @return a List of Screening POJOs
     */
    public static List GetPressPreviews() {
      List list = new List();
      using (var c =  AdoDB.Provider.CreateConnection()) {
        c.ConnectionString = AdoDB.CS;
        using (DbCommand cmd = c.CreateCommand()) {
          cmd.CommandText = AdoDB.PRESS;
          c.Open();
          using (var r = cmd.ExecuteReader()) {
            while (r.Read()) {
              Screening screening = GetScreening(r);
              Movie movie = GetMovie(r);
              int film_id = Convert.ToInt32(r["id"]);
              foreach (Director d in GetDirectors(film_id) ) {
                movie.AddDirector(d);
              }
              foreach ( Country country in GetCountries(film_id) ) {
                movie.AddCountry(country);
              }
              Entry entry = GetEntry(r);
              Category category = GetCategory(r);
              entry.category = category;
              entry.movie = movie;
              movie.entry = entry;
              screening.movie = movie;
              list.Add(screening);            
            }
          }
        }
      }      
      return list;
    }
// ---------------------------------------------------------------------------    
    /**
     * Returns a list with Director objects.
     * @param film_id the id of a movie
     */
    public static List GetDirectors(int film_id) {
      List list = new List();
      using (var c =  AdoDB.Provider.CreateConnection()) {
        c.ConnectionString = AdoDB.CS;
        using (DbCommand cmd = c.CreateCommand()) {
          cmd.CommandText = AdoDB.DIRECTORS;
          cmd.Parameters.Add(cmd.CreateParameter());
          cmd.Parameters[0].ParameterName = "@film_id";
          cmd.Parameters[0].Value = film_id;
          c.Open();
          using (var r = cmd.ExecuteReader()) {
            while (r.Read()) {
              list.Add(GetDirector(r));
            }
          }
        }
      }
      return list;
    }
// ---------------------------------------------------------------------------        
    /**
     * Returns an List containing all the filmfestival days.
     * @return a list containing days.
     */
    public static List GetDays() {
      List list = new List();
      using (var c =  AdoDB.Provider.CreateConnection()) {
        c.ConnectionString = AdoDB.CS;
        using (DbCommand cmd = c.CreateCommand()) {
          cmd.CommandText = AdoDB.DAYS;
          c.Open();
          using (var r = cmd.ExecuteReader()) {
            while (r.Read()) {
              list.Add(r.GetString(0));
            }
          }
        }
      }        
      return list;
    }
// ---------------------------------------------------------------------------    
//    /**
//     * Returns an List containing all the screening locations.
//     * @return a list containing location codes.
//     */
    public static List GetLocations() {
      List list = new List();
      using (var c =  AdoDB.Provider.CreateConnection()) {
        c.ConnectionString = AdoDB.CS;
        using (DbCommand cmd = c.CreateCommand()) {
          cmd.CommandText = AdoDB.LOCATIONS;
          c.Open();
          using (var r = cmd.ExecuteReader()) {
            while (r.Read()) {
              list.Add(r.GetString(0));
            }
          }
        }
      }        
      return list;
    }
// =========================================================================== 
  }
}
FilmFonts.cs
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
using iTextSharp.text;
using iTextSharp.text.pdf;

/**
 * Contains a series of static Font objects that are used throughout the book.
 */
namespace kuujinbo.iTextInAction2Ed.Intro_1_2 {
  public class FilmFonts {
// =========================================================================== 
    /** A font used in our PDF file */
    public static Font NORMAL = new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL);
    /** A font used in our PDF file */
    public static Font BOLD = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD);
    /** A font used in our PDF file */
    public static Font ITALIC = new Font(Font.FontFamily.HELVETICA, 12, Font.ITALIC);
    /** A font used in our PDF file */
    public static Font BOLDITALIC = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLDITALIC);
// =========================================================================== 
  }
}
PojoToElementFactory.cs
/*
 * This class is part of the book "iText in Action - 2nd Edition"
 * written by Bruno Lowagie (ISBN: 9781935182610)
 * For more info, go to: http://itextpdf.com/examples/
 * This example only works with the AGPL version of iText.
 */
using System.Collections.Generic;
using iTextSharp.text;
using iTextSharp.text.pdf;

namespace kuujinbo.iTextInAction2Ed.Intro_1_2 {
  public class PojoToElementFactory {
// =========================================================================== 
    /**
     * Creates a Phrase containing the title of a Movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    public static Phrase GetMovieTitlePhrase(Movie movie) {
      return new Phrase(movie.MovieTitle, FilmFonts.NORMAL);
    }
// ---------------------------------------------------------------------------    
    /**
     * Creates a Phrase containing the original title of a Movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    public static Phrase GetOriginalTitlePhrase(Movie movie) {
      return  string.IsNullOrEmpty(movie.OriginalTitle)
        ? new Phrase("", FilmFonts.NORMAL)
        : new Phrase(movie.OriginalTitle, FilmFonts.ITALIC)
        ;
    }
// ---------------------------------------------------------------------------    
    /**
     * Creates a Phrase containing the name of a Director.
     * @param director a Director object
     * @return a Phrase object
     */
    public static Phrase GetDirectorPhrase(Director director) {
      Phrase phrase = new Phrase();
      phrase.Add(new Chunk(director.Name, FilmFonts.BOLD));
      phrase.Add(new Chunk(", ", FilmFonts.BOLD));
      phrase.Add(new Chunk(director.GivenName, FilmFonts.NORMAL));
      return phrase;
    }
// ---------------------------------------------------------------------------    
    /**
     * Creates a Phrase containing the name of a Country.
     * @param country a Country object
     * @return a Phrase object
     */
    public static Phrase GetCountryPhrase(Country country) {
      return new Phrase(country.Name, FilmFonts.NORMAL);
    }
// ---------------------------------------------------------------------------    
    /**
     * Creates a list with directors.
     * @param movie a Movie object
     * @return a List object
     */
    public static List GetDirectorList(Movie movie) {
      var list = new List();
      foreach (Director director in movie.Directors ) {
        list.Add(string.Format(
          "{0}, {1}", director.Name, director.GivenName
        ));
      }
      return list;
    }
// ---------------------------------------------------------------------------    
    /**
     * Creates a list with countries.
     * @param movie a Movie object
     * @return a List object
     */
    public static List GetCountryList(Movie movie) {
      var list = new List();
      foreach (Country country in movie.Countries) {
        list.Add(country.Name);
      }
      return list;
    }
// ---------------------------------------------------------------------------
    /**
     * Creates a phrase with the production year of a movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    // public static Element GetYearPhrase(Movie movie) {
    public static Phrase GetYearPhrase(Movie movie) {
      Phrase p = new Phrase();
      p.Add(new Chunk("Year: ", FilmFonts.BOLD));
      p.Add(new Chunk(movie.Year.ToString(), FilmFonts.NORMAL));
      return p;
    }
// ---------------------------------------------------------------------------
    /**
     * Creates a phrase with the run length of a movie.
     * @param movie a Movie object
     * @return a Phrase object
     */
    // public static Element getDurationPhrase(Movie movie) {
    public static Phrase GetDurationPhrase(Movie movie) {
      Phrase p = new Phrase();
      p.Add(new Chunk("Duration: ", FilmFonts.BOLD));
      p.Add(new Chunk(movie.Duration.ToString(), FilmFonts.NORMAL));
      return p;
    }
// =========================================================================== 
  }
}
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now