List of usage examples for com.lowagie.text.pdf ColumnText setSimpleColumn
public void setSimpleColumn(float llx, float lly, float urx, float ury)
From source file:classroom.filmfestival_b.Movies09.java
@SuppressWarnings("unchecked") public static void main(String[] args) { // step 1/*w w w .j av a 2 s. co 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(); 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//ww w . j a v a2 s . c o m 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/*www .j a v a 2s . co m*/ 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_c.Movies25.java
@SuppressWarnings("unchecked") public static boolean addText(String s, PdfContentByte canvas, float[] f, float size, boolean simulate) throws DocumentException, IOException { StyleSheet styles = new StyleSheet(); styles.loadTagStyle("p", "size", size + "px"); styles.loadTagStyle("p", "align", "justify"); styles.loadTagStyle("p", "hyphenation", "en_us"); ArrayList<Element> objects = HTMLWorker.parseToList(new StringReader(s), styles, null); ColumnText ct = new ColumnText(canvas); ct.setAlignment(Element.ALIGN_JUSTIFIED); ct.setLeading(size * 1.2f);/*from w w w .j a va2s . c om*/ ct.setSimpleColumn(f[1] + 2, f[2] + 2, f[3] - 2, f[4]); for (Element element : objects) { ct.addElement(element); } return ColumnText.hasMoreText(ct.go(simulate)); }
From source file:classroom.newspaper_a.Newspaper04.java
public static void putText(PdfContentByte canvas, Phrase phrase, float llx, float lly, float urx, float ury) throws DocumentException { ColumnText column = new ColumnText(canvas); column.setAlignment(Element.ALIGN_CENTER); column.setSimpleColumn(llx, lly, urx, ury); column.setText(phrase);/*from ww w.ja va2 s. c om*/ column.go(true); float offset = (column.getYLine() - lly) / 2f; column.setText(phrase); column.setYLine(ury - offset); column.go(); }
From source file:classroom.newspaper_a.Newspaper05.java
public static void putText(PdfContentByte canvas, Phrase p, float llx, float lly, float w, float h) throws DocumentException { PdfTemplate template = canvas.createTemplate(h, w); ColumnText column = new ColumnText(template); column.setSimpleColumn(0, 0, h, w); column.setAlignment(Element.ALIGN_CENTER); column.setText(p);//from ww w . j a v a 2 s . c o m column.go(true); float offset = w - (column.getYLine() / 2f); column.setText(p); column.setYLine(offset); column.go(); canvas.addTemplate(template, 0, 1, -1, 0, llx + w, lly); }
From source file:corner.orm.tapestry.pdf.components.AbstractColumnText.java
License:Apache License
/** * @see corner.orm.tapestry.pdf.components.AbstractPdfComponent#renderPdf(corner.orm.tapestry.pdf.PdfWriterDelegate, com.lowagie.text.Document) *///from w ww. j a v a 2 s . co m @Override public void renderPdf(PdfWriterDelegate writer, Document doc) { Defense.notNull(getRectangle(), "?"); ColumnText ct = new ColumnText(writer.getPdfWriter().getDirectContent()); String[] p = getRectangle().split(","); ct.setSimpleColumn(Float.valueOf(p[0]), Float.valueOf(p[1]), Float.valueOf(p[2]), Float.valueOf(p[3])); // System.out.println("ColumnText??:"+getRectangle()); setCurrentColumnTextWidth(Float.valueOf(p[2]) - Float.valueOf(p[0])); setColumnTextStartHeight(Float.valueOf(Float.valueOf(p[3]))); renderColumnText(ct, writer, doc); go(ct); }
From source file:corner.orm.tapestry.pdf.components.AbstractPdfTableDisplay.java
License:Apache License
protected ColumnText createTempColumnText(PdfWriterDelegate writer) { ColumnText tmpCT = new ColumnText(writer.getPdfWriter().getDirectContentUnder()); String[] p = getRectangle().split(","); tmpCT.setSimpleColumn(Float.valueOf(p[0]), Float.valueOf(p[1]), Float.valueOf(p[2]), Float.valueOf(p[3])); return tmpCT; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableDocumentSection.java
License:Open Source License
private List<ColumnText> fillTable(float height) { // copy text for simulation List<ColumnText> tt = null; if (breakHandlingParent == null && colIdx >= layoutTable.getNumberOfColumns()) { // more column breaks than available column // we try not to lose content // but results may be different than in open office // anyway it is logical error made by document creator tt = new ArrayList<ColumnText>(); ColumnText t = createColumnText(); tt.add(t);/* ww w . ja v a2 s . c o m*/ for (int i = 0; i < texts.size(); i++) { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100.0f); PdfPCell cell = new PdfPCell(); cell.setBorder(Table.NO_BORDER); cell.setPadding(0.0f); cell.setColumn(ColumnText.duplicate(texts.get(i))); table.addCell(cell); t.addElement(table); } } else { tt = new ArrayList<ColumnText>(texts); for (int i = 0; i < tt.size(); i++) { tt.set(i, ColumnText.duplicate(tt.get(i))); } } // clear layout table clearTable(layoutTable, true); setWidthIfNecessary(); // try to fill cells with text ColumnText t = tt.get(0); for (PdfPCell cell : layoutTable.getRow(0).getCells()) { cell.setFixedHeight(height >= 0.0f ? height : -1.0f); cell.setColumn(ColumnText.duplicate(t)); // t.setSimpleColumn(cell.getLeft() + cell.getPaddingLeft(), height >= 0.0f ? -height : PdfPRow.BOTTOM_LIMIT, cell.getRight() - cell.getPaddingRight(), 0); int res = 0; try { res = t.go(true); } catch (DocumentException e) { throw new ODFConverterException(e); } if (!ColumnText.hasMoreText(res)) { // no overflow in current column if (tt.size() == 1) { // no more text return null; } else { // some text waiting for new column tt.remove(0); t = tt.get(0); } } } return tt; }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.elements.StylableDocumentSection.java
License:Open Source License
private List<ColumnText> fillTable(float height) { // copy text for simulation List<ColumnText> tt = null; if (breakHandlingParent == null && colIdx >= layoutTable.getNumberOfColumns()) { // more column breaks than available column // we try not to lose content // but results may be different than in open office // anyway it is logical error made by document creator tt = new ArrayList<ColumnText>(); ColumnText t = createColumnText(); tt.add(t);//www . j ava 2s .co m for (int i = 0; i < texts.size(); i++) { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100.0f); PdfPCell cell = new PdfPCell(); cell.setBorder(Table.NO_BORDER); cell.setPadding(0.0f); cell.setColumn(ColumnText.duplicate(texts.get(i))); table.addCell(cell); t.addElement(table); } } else { tt = new ArrayList<ColumnText>(texts); for (int i = 0; i < tt.size(); i++) { tt.set(i, ColumnText.duplicate(tt.get(i))); } } // clear layout table clearTable(layoutTable, true); setWidthIfNecessary(); // try to fill cells with text ColumnText t = tt.get(0); for (PdfPCell cell : layoutTable.getRow(0).getCells()) { cell.setFixedHeight(height >= 0.0f ? height : -1.0f); cell.setColumn(ColumnText.duplicate(t)); // t.setSimpleColumn(cell.getLeft() + cell.getPaddingLeft(), height >= 0.0f ? -height : PdfPRow.BOTTOM_LIMIT, cell.getRight() - cell.getPaddingRight(), 0); int res = 0; try { res = t.go(true); } catch (DocumentException e) { throw new XWPFConverterException(e); } if (!ColumnText.hasMoreText(res)) { // no overflow in current column if (tt.size() == 1) { // no more text return null; } else { // some text waiting for new column tt.remove(0); t = tt.get(0); } } } return tt; }