List of usage examples for com.lowagie.text.pdf PdfPCell setUseAscender
public void setUseAscender(boolean useAscender)
From source file:classroom.filmfestival_b.Movies13.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1/*from w w w . jav a 2s .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 www. ja va2 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 = 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 a v a 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 w ww . j a va 2s .c om // 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);// w w w . j a va 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);//w w w. java 2 s .co 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:fr.opensagres.xdocreport.itext.extension.SimpleTable.java
License:Open Source License
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); try {//from w w w. ja v a 2 s. c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("SimpleTable.pdf")); document.open(); PdfPTable table = new PdfPTable(2); PdfPCell cell; Paragraph p = new Paragraph("Text Text Text "); table.addCell("cell"); table.addCell(p); table.addCell("cell"); cell = new PdfPCell(p); p = new Paragraph("Text Text Text "); //Chunk c = new Chunk( "zzzzzzzzzz" ); //cell.setPadding( 0f ); //cell.getColumn().setAdjustFirstLine( false ); // make a room for borders //cell.setUseBorderPadding( false ); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setBackgroundColor(Color.red); cell.addElement(p); cell.setUseAscender(true); //cell.addElement(c ); // cell.setPaddingTop( 0f ); // cell.setPaddingLeft( 20f ); table.addCell(cell); //table.addCell( "cell" ); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:nl.dykema.jxmlnote.spikes.Spacing.java
License:Open Source License
/** * Main method./*from ww w . ja v a2s . co m*/ * @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);//from w w w. jav a2s .co m if (getType() == TAG_TH) cell.setMarkupAttribute(HEADER_INDICATOR_ATTR, "true"); return cell; }
From source file:org.areasy.common.doclet.utilities.PDFUtility.java
License:Open Source License
/** * Create a cell element./*from w ww . j a va 2 s .c o m*/ */ public static PdfPCell createElementCell(int padding, int alignment, Element[] elements) { Element mainElement; // If there are no nested tables in content if (!hasTablesOrLists(elements)) { Paragraph para = new Paragraph(); para.setAlignment(alignment); for (int i = 0; i < elements.length; i++) { try { para.add(elements[i]); } catch (Exception e) { String msg = "Failed to add element to paragraph: " + e.toString(); DocletUtility.error(msg); } } mainElement = para; } else { PdfPTable cellTable = new PdfPTable(1); Paragraph currInnerPara = null; for (int i = 0; i < elements.length; i++) { Element element = elements[i]; /* Check for special element created by TagTABLE */ if (element instanceof TableParagraph) element = ((TableParagraph) elements[i]).getTable(); if (element instanceof PdfPTable || element instanceof List) { if (currInnerPara != null) { PdfPCell innerCell = createElementCell(0, alignment, currInnerPara); innerCell.setUseDescender(true); // needs newer iText innerCell.setUseAscender(true); // needs newer iText innerCell.setPaddingBottom(2.0f); cellTable.addCell(innerCell); } currInnerPara = null; cellTable.addCell(createElementCell(0, alignment, element)); } else { if (currInnerPara == null) { currInnerPara = new Paragraph(); currInnerPara.setAlignment(alignment); } try { currInnerPara.add(element); } catch (Exception e) { String msg = "Failed to add element to inner paragraph: " + e.toString(); DocletUtility.error(msg); } } } if (currInnerPara != null) cellTable.addCell(createElementCell(0, alignment, currInnerPara)); mainElement = cellTable; } return createElementCell(padding, alignment, mainElement); }