List of usage examples for com.lowagie.text Paragraph Paragraph
public Paragraph(Phrase phrase)
Paragraph
with a certain Phrase
. From source file:classroom.filmfestival_b.Movies09.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1/*from w ww . j av a 2s . com*/ 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(); ColumnText column = new ColumnText(writer.getDirectContent()); column.setSimpleColumn(document.left(), document.bottom(), document.right(), document.top()); float pos; int status; File f; Image img; Paragraph p; Chunk c; 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()) { img = Image.getInstance(f.getPath()); img.setWidthPercentage(0); img.scaleToFit(72, 144); } else { img = null; } 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); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } if (img != null) column.addElement(img); column.addElement(p); column.addElement(list); pos = column.getYLine(); status = column.go(true); if (ColumnText.hasMoreText(status)) { document.newPage(); column.setText(null); column.setYLine(document.top()); } else { column.setYLine(pos); } if (img != null) column.addElement(img); column.addElement(p); column.addElement(list); column.addElement(Chunk.NEWLINE); column.go(); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:classroom.filmfestival_b.Movies10.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1//from ww w. j ava 2s .com Document document = new Document(); float middle = (document.right() + document.left()) / 2; float columns[][] = { { document.left(), document.bottom(), middle - 12, document.top() }, { middle + 12, document.bottom(), document.right(), document.top() } }; 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(); ColumnText column = new ColumnText(writer.getDirectContent()); column.setSimpleColumn(columns[0][0], columns[0][1], columns[0][2], columns[0][3]); float pos; int status; int ccount = 0; File f; Image img; Paragraph p; Chunk c; 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()) { img = Image.getInstance(f.getPath()); img.setWidthPercentage(0); img.scaleToFit(72, 144); } else { img = null; } 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); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } if (img != null) column.addElement(img); column.addElement(p); column.addElement(list); pos = column.getYLine(); status = column.go(true); if (ColumnText.hasMoreText(status)) { column.setText(null); ccount++; if (ccount > 1) { ccount = 0; document.newPage(); column.setSimpleColumn(columns[0][0], columns[0][1], columns[0][2], columns[0][3]); } else { column.setSimpleColumn(columns[1][0], columns[1][1], columns[1][2], columns[1][3]); } } else { column.setYLine(pos); } if (img != null) column.addElement(img); column.addElement(p); column.addElement(list); column.addElement(Chunk.NEWLINE); column.go(); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:classroom.filmfestival_b.Movies11.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1//from w w w.j a v a 2 s . c om Document document = new Document(); document.setMargins(36, 36, 48, 48); float middle = (document.right() + document.left()) / 2; float columns[][] = { { document.left(), document.bottom(), middle - 12, document.top() }, { middle + 12, document.bottom(), document.right(), document.top() } }; try { // step 2 OutputStream os = new FileOutputStream(RESULT); PdfWriter writer = PdfWriter.getInstance(document, os); writer.setPageEvent(new Movies11().new MoviePageEvents(middle, document.top(), document.bottom())); // 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(); ColumnText column = new ColumnText(writer.getDirectContent()); column.setSimpleColumn(columns[0][0], columns[0][1], columns[0][2], columns[0][3]); float pos; int status; int ccount = 0; File f; Image img; Paragraph p; Chunk c; 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()) { img = Image.getInstance(f.getPath()); img.setWidthPercentage(0); img.scaleToFit(72, 144); } else { img = null; } 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); Set<DirectorName> directors = movie.getDirectorNames(); List list = new List(); for (DirectorName director : directors) { list.add(director.getName()); } if (img != null) column.addElement(img); column.addElement(p); column.addElement(list); pos = column.getYLine(); status = column.go(true); if (ColumnText.hasMoreText(status)) { column.setText(null); ccount++; if (ccount > 1) { ccount = 0; document.newPage(); column.setSimpleColumn(columns[0][0], columns[0][1], columns[0][2], columns[0][3]); } else { column.setSimpleColumn(columns[1][0], columns[1][1], columns[1][2], columns[1][3]); } } else { column.setYLine(pos); } if (img != null) column.addElement(img); column.addElement(p); column.addElement(list); column.addElement(Chunk.NEWLINE); column.go(); } // step 5 document.close(); } catch (IOException e) { LOGGER.error("IOException: ", e); } catch (DocumentException e) { LOGGER.error("DocumentException: ", e); } }
From source file:classroom.filmfestival_b.Movies12.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1/*from www . ja v 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; Image img; Paragraph p; Chunk c; 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()) { img = Image.getInstance(f.getPath()); table.addCell(img); } else { table.addCell(""); } 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); table.addCell(p); } 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.Movies13.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1/*from ww w . j av a2 s .co 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; 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_c.Movies17.java
@SuppressWarnings("unchecked") protected static Element directors(FilmTitle movie) { Set<DirectorName> directors = movie.getDirectorNames(); if (directors.size() == 0) { Paragraph p = new Paragraph("various directors"); p.setLeading(16);//w w w .j a va 2 s . co m return p; } if (directors.size() == 1) { DirectorName name = directors.iterator().next(); Paragraph p = new Paragraph(name.getName()); p.setLeading(16); return p; } List list = new List(List.UNORDERED, 10); ListItem li; for (DirectorName director : directors) { li = new ListItem(director.getName()); li.setLeading(16); list.add(li); } return list; }
From source file:classroom.intro.HelloWorld01.java
public static void main(String[] args) { // step 1//w w w . j av a 2 s .c o m Document document = new Document(); try { // step 2 PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World")); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:classroom.intro.HelloWorld02.java
public static void main(String[] args) { Document.compress = false;//www.j a v a2 s .c o m // step 1 Document document = new Document(); try { // step 2 PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World")); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:classroom.intro.HelloWorld03.java
public static void main(String[] args) { // step 1//www . j a v a 2s .com Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setFullCompression(); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World")); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }
From source file:classroom.intro.HelloWorld04.java
public static void main(String[] args) { // step 1/* www .j a va2 s . c o m*/ Document document = new Document(); try { // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); writer.setEncryption("hello".getBytes(), "world".getBytes(), PdfWriter.ALLOW_PRINTING, PdfWriter.ENCRYPTION_AES_128); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World")); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } // step 5 document.close(); }