List of usage examples for com.lowagie.text.pdf ColumnText go
public int go() throws DocumentException
From source file:questions.stamppages.BookmarksToTOC2.java
@SuppressWarnings("unchecked") public static void main(String[] args) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {//from w w w . ja v a 2 s .c o m Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); writer.setPageEvent(new ParagraphBookmarkEvents(true)); document.open(); BufferedReader reader = new BufferedReader(new FileReader(RESOURCE)); String line; Paragraph p; while ((line = reader.readLine()) != null) { p = new Paragraph(line); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); document.add(Chunk.NEWLINE); } reader.close(); document.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } try { PdfReader reader = new PdfReader(baos.toByteArray()); Rectangle rect = reader.getPageSizeWithRotation(1); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); stamper.insertPage(1, rect); ColumnText column = new ColumnText(stamper.getOverContent(1)); column.setSimpleColumn(rect.getLeft(36), rect.getBottom(36), rect.getRight(36), rect.getTop(36)); column.addElement(new Paragraph("TABLE OF CONTENTS")); List<Map> list = SimpleBookmark.getBookmark(reader); Chunk link; String dest; for (Map<String, String> bookmark : list) { link = new Chunk(bookmark.get("Title")); dest = bookmark.get("Named"); link.setAction(PdfAction.gotoLocalPage(dest, false)); column.addElement(new Paragraph(link)); } column.go(); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.stamppages.StampAndAddColumns.java
public static void main(String[] args) { try {//from w w w. j av a 2 s . c om PdfReader reader = new PdfReader(RESOURCE); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); AcroFields form = stamper.getAcroFields(); form.setField("Who", "world"); ColumnText ct = new ColumnText(stamper.getOverContent(1)); String line; Phrase p; BufferedReader br = new BufferedReader(new FileReader(TXT)); while ((line = br.readLine()) != null) { p = new Phrase(line + "\n"); ct.addText(p); } int status = ColumnText.START_COLUMN; ct.setSimpleColumn(100, 700, 495, 100); status = ct.go(); int pageCt = 1; while (ColumnText.hasMoreText(status)) { stamper.insertPage(++pageCt, reader.getPageSize(1)); ct.setYLine(700); ct.setCanvas(stamper.getOverContent(pageCt)); status = ct.go(); } stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.tables.TableColumns.java
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate()); try {/*from ww w. j a v a 2s . c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); // the content of the columns ColumnText content = new ColumnText(writer.getDirectContent()); PdfPTable items = new PdfPTable(2); items.setWidthPercentage(100); for (int i = 0; i < 100; ++i) { items.addCell("item " + i); items.addCell("some item"); } content.addElement(items); // adding the stuff to the document int column = 0; float height = 0; float[][] x = { { document.left(), document.left() + 380 }, { document.right() - 380, document.right() } }; int status = ColumnText.START_COLUMN; while (ColumnText.hasMoreText(status)) { if (column == 0) { PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); table.addCell("EmployeeSheets"); table.addCell("Page " + writer.getPageNumber()); document.add(table); height = table.getTotalHeight(); } content.setSimpleColumn(x[column][0], document.bottom(), x[column][1], document.top() - height - 10); status = content.go(); if (++column >= x.length) { column = 0; document.newPage(); } } } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }