List of usage examples for com.lowagie.text.pdf PdfPCell setUseDescender
public void setUseDescender(boolean useDescender)
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 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; 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//from w ww. java 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 = 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//from w w w. j ava 2s .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:classroom.filmfestival_c.Movies17.java
protected static void addScreening(PdfPTable outer, FestivalScreening screening) throws DocumentException { FilmTitle movie = screening.getFilmTitle(); // we construct a 3 column table PdfPTable table = new PdfPTable(3); table.setWidths(WIDTHS);//from www .j av a 2 s . co m // the first cell with the full title spans all the columns PdfPCell cell = new PdfPCell(); cell.addElement(fullTitle(screening)); cell.setColspan(3); cell.setBorder(PdfPCell.NO_BORDER); setColor(movie, cell); table.addCell(cell); cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); cell.setUseAscender(true); cell.setUseDescender(true); table.addCell(cell); cell = new PdfPCell(); cell.addElement(directors(movie)); cell.setBorder(PdfPCell.NO_BORDER); cell.setUseAscender(true); cell.setUseDescender(true); table.addCell(cell); cell = new PdfPCell(); cell.addElement(screenings(screening)); cell.setBorder(PdfPCell.NO_BORDER); cell.setUseAscender(true); cell.setUseDescender(true); table.addCell(cell); outer.addCell(table); }
From source file:classroom.filmfestival_c.Movies17.java
protected static Element fullTitle(FestivalScreening screening) throws DocumentException { FilmTitle movie = screening.getFilmTitle(); // a table with 3 cells PdfPTable table = new PdfPTable(3); table.setWidths(INNER);/*from www . j av a 2 s .c o m*/ table.setWidthPercentage(100); // the title(s) Paragraph p = new Paragraph(); p.add(new Phrase(movie.getTitle(), BOLD)); p.setLeading(16); // maybe an alternative title if (movie.getATitle().trim().length() > 0) { p.add(new Phrase(" (" + movie.getATitle() + ")")); } PdfPCell cell = new PdfPCell(); cell.addElement(p); cell.setBorder(PdfPCell.NO_BORDER); cell.setUseAscender(true); cell.setUseDescender(true); table.addCell(cell); // eXploreZone? cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); if (isExploreZone(movie)) { cell.setBackgroundColor(WHITE); cell.setUseAscender(true); cell.setUseDescender(true); cell.addElement(new Paragraph("eXplore")); } table.addCell(cell); // Duration / shortfilm cell = new PdfPCell(); cell.setBorder(PdfPCell.NO_BORDER); cell.setBackgroundColor(WHITE); cell.setUseAscender(true); cell.setUseDescender(true); StringBuffer buf = new StringBuffer(); buf.append(movie.getDuration()); buf.append('\''); if (getExtra(screening) > 0) { buf.append(" + KF"); buf.append(getExtra(screening)); buf.append('\''); } p = new Paragraph(buf.toString()); p.setAlignment(Element.ALIGN_CENTER); cell.addElement(p); table.addCell(cell); return table; }
From source file:com.gtdfree.test.TableBorders.java
License:Open Source License
private static PdfPCell makeCell(String text, int vAlignment, int hAlignment, Font font, float leading, float padding, Rectangle borders, boolean ascender, boolean descender) { Paragraph p = new Paragraph(text, font); p.setLeading(leading);/*from w w w.j a v a2s . c o m*/ PdfPCell cell = new PdfPCell(p); cell.setLeading(leading, 0); cell.setVerticalAlignment(vAlignment); cell.setHorizontalAlignment(hAlignment); cell.cloneNonPositionParameters(borders); cell.setUseAscender(ascender); cell.setUseDescender(descender); cell.setUseBorderPadding(true); cell.setPadding(padding); return cell; }
From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java
License:Apache License
/** * Creates the pdf footer./* w w w . j a v a 2s . co m*/ * * @param pdfPTable * the pdf P table * @param font * the font * @throws DocumentException * the document exception * @throws IOException * Signals that an I/O exception has occurred. */ public void createPdfFooter(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException { final float width = pdfPTable.getWidthPercentage(); final int headerWidth = (int) width; font = getFont(); final PdfPCell footerCell = new PdfPCell(new Phrase(getFooter(), font)); footerCell.setHorizontalAlignment(Element.ALIGN_CENTER); footerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); footerCell.setColspan(headerWidth); footerCell.setBorder(0); footerCell.setUseDescender(true); pdfPTable.addCell(footerCell); pdfPTable.setFooterRows(1); }
From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java
License:Apache License
/** * Creates the pdf headers./* w ww .ja v a 2 s. c o m*/ * * @param pdfPTable * the pdf P table * @param font * the font * @throws DocumentException * the document exception * @throws IOException * Signals that an I/O exception has occurred. */ public void createPdfHeaders(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException { font = getFont(); final float width = pdfPTable.getWidthPercentage(); final int headerWidth = (int) width; final PdfPCell headersCells = new PdfPCell(new Phrase(getHeader(), font)); headersCells.setHorizontalAlignment(Element.ALIGN_CENTER); headersCells.setColspan(headerWidth); headersCells.setUseDescender(true); headersCells.setBorder(0); pdfPTable.addCell(headersCells); for (int i = 0; i < this.model.getColumnCount(); i++) { if (this.model.isVisible(i)) { final PdfPCell cell = new PdfPCell(new Phrase(Lables.get(this.model.getActualColumnName(i)), font)); cell.setRotation(getRotationDegree()); cell.setHorizontalAlignment(Element.ALIGN_CENTER); pdfPTable.addCell(cell); } } // Please explain pdfPTable.setHeaderRows(3); createPdfFooter(pdfPTable, font); }
From source file:nl.dykema.jxmlnote.spikes.Spacing.java
License:Open Source License
/** * Main method.// w w w.ja va 2 s .c om * @param args no arguments needed * @throws DocumentException * @throws IOException */ public static void main(String[] args) throws DocumentException, IOException { // step 1 Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(RESULT)); // step 3 document.open(); // step 4 PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); Phrase p = new Phrase( "Dr. iText or: How I Learned to Stop Worrying " + "and Love the Portable Document Format."); PdfPCell cell = new PdfPCell(p); table.addCell("default leading / spacing"); table.addCell(cell); table.addCell("absolute leading: 20"); cell.setLeading(20f, 0f); table.addCell(cell); table.addCell("absolute leading: 3; relative leading: 1.2"); cell.setLeading(3f, 1.2f); table.addCell(cell); table.addCell("absolute leading: 0; relative leading: 1.2"); cell.setLeading(0f, 1.2f); table.addCell(cell); table.addCell("no leading at all"); cell.setLeading(0f, 0f); table.addCell(cell); cell = new PdfPCell(new Phrase("Dr. iText or: How I Learned to Stop Worrying and Love PDF")); table.addCell("padding 10"); cell.setPadding(10); table.addCell(cell); table.addCell("padding 0"); cell.setPadding(0); table.addCell(cell); table.addCell("different padding for left, right, top and bottom"); cell.setPaddingLeft(20); cell.setPaddingRight(50); cell.setPaddingTop(0); cell.setPaddingBottom(5); table.addCell(cell); p = new Phrase("iText in Action Second Edition"); table.getDefaultCell().setPadding(2); table.getDefaultCell().setUseAscender(false); table.getDefaultCell().setUseDescender(false); table.addCell("padding 2; no ascender, no descender"); table.addCell(p); table.getDefaultCell().setUseAscender(true); table.getDefaultCell().setUseDescender(false); table.addCell("padding 2; ascender, no descender"); table.addCell(p); table.getDefaultCell().setUseAscender(false); table.getDefaultCell().setUseDescender(true); table.addCell("padding 2; descender, no ascender"); table.addCell(p); table.getDefaultCell().setUseAscender(true); table.getDefaultCell().setUseDescender(true); table.addCell("padding 2; ascender and descender"); cell.setPadding(2); cell.setUseAscender(true); cell.setUseDescender(true); table.addCell(p); document.add(table); // step 5 document.close(); }
From source file:org.areasy.common.doclet.document.tags.TagTD.java
License:Open Source License
private PdfPCell createCell(Element[] content) { int defaultAlign = (getType() == TAG_TH) ? Element.ALIGN_CENTER : Element.ALIGN_LEFT; String align = getInheritedAttribute("align", false); String valign = getInheritedAttribute("valign", false); String bgcolor = getInheritedAttribute("bgcolor", true); int alignment = HtmlTagUtility.getAlignment(align, defaultAlign); PdfPCell cell = PDFUtility.createElementCell(2, alignment, content); cell.setHorizontalAlignment(HtmlTagUtility.getAlignment(align, defaultAlign)); cell.setVerticalAlignment(HtmlTagUtility.getVerticalAlignment(valign, Element.ALIGN_MIDDLE)); cell.setBackgroundColor(HtmlTagUtility.getColor(bgcolor)); cell.setColspan(parseSpan(getAttribute("colspan"))); cell.setUseAscender(true); // needs newer iText cell.setUseDescender(true); // needs newer iText cell.setUseBorderPadding(true); // needs newer iText if (getAttribute("nowrap") != null) cell.setNoWrap(true);/* w w w .j a va 2 s.c o m*/ if (getType() == TAG_TH) cell.setMarkupAttribute(HEADER_INDICATOR_ATTR, "true"); return cell; }