List of usage examples for com.lowagie.text.pdf ColumnText NO_MORE_TEXT
int NO_MORE_TEXT
To view the source code for com.lowagie.text.pdf ColumnText NO_MORE_TEXT.
Click Source Link
From source file:org.areasy.common.doclet.document.Index.java
License:Open Source License
/** * Creates a simple alphabetical index of all * classes and members of the API./*from w ww . j av a 2 s . co m*/ * * @throws Exception If the Index could not be created. */ public void create() throws Exception { if (!DefaultConfiguration.getBooleanConfigValue(ARG_CREATE_INDEX, false)) { log.trace("Index creation disabled."); return; } log.trace("Start creating Index..."); State.setCurrentHeaderType(HEADER_INDEX); State.increasePackageChapter(); // Name of the package (large font) pdfDocument.newPage(); // Create "Index" bookmark String label = DefaultConfiguration.getString(ARG_LB_OUTLINE_INDEX, LB_INDEX); String dest = "INDEX:"; Bookmarks.addRootBookmark(label, dest); Chunk indexChunk = new Chunk(label, Fonts.getFont(TEXT_FONT, BOLD, 30)); indexChunk.setLocalDestination(dest); Paragraph indexParagraph = new Paragraph((float) 30.0, indexChunk); pdfDocument.add(indexParagraph); // we grab the ContentByte and do some stuff with it PdfContentByte cb = pdfWriter.getDirectContent(); ColumnText ct = new ColumnText(cb); ct.setLeading((float) 9.0); float[] right = { 70, 320 }; float[] left = { 300, 550 }; // fill index columns with text String letter = ""; Set keys = memberList.keySet(); // keys must be sorted case unsensitive ArrayList sortedKeys = new ArrayList(keys.size()); // Build sorted list of all entries Iterator keysIterator = keys.iterator(); while (keysIterator.hasNext()) { sortedKeys.add(keysIterator.next()); } Collections.sort(sortedKeys, this); Iterator realNames = sortedKeys.iterator(); while (realNames.hasNext()) { String memberName = (String) realNames.next(); String currentLetter = memberName.substring(0, 1).toUpperCase(); log.trace("Create index entry for " + memberName); // Check if next letter in alphabet is reached if (currentLetter.equalsIgnoreCase(letter) == false) { // If yes, switch to new letter and print it letter = currentLetter.toUpperCase(); Paragraph lphrase = new Paragraph((float) 13.0); lphrase.add(new Chunk("\n\n" + letter + "\n", Fonts.getFont(TEXT_FONT, 12))); ct.addText(lphrase); } // Print member name Paragraph phrase = new Paragraph((float) 10.0); phrase.add(new Chunk("\n" + memberName + " ", Fonts.getFont(TEXT_FONT, 9))); Iterator sortedPages = getSortedPageNumbers(memberName); boolean firstNo = true; while (sortedPages.hasNext()) { Integer pageNo = (Integer) sortedPages.next(); // Always add 1 to the stored value, because the pages were // counted beginning with 0 internally, but their visible // numbering starts with 1 String pageNumberText = String.valueOf(pageNo.intValue() + 1); if (!firstNo) { phrase.add(new Chunk(", ", Fonts.getFont(TEXT_FONT, 9))); } phrase.add(new Chunk(pageNumberText, Fonts.getFont(TEXT_FONT, 9))); firstNo = false; } ct.addText(phrase); } // Now print index by printing columns into document int status = 0; int column = 0; while ((status & ColumnText.NO_MORE_TEXT) == 0) { ct.setSimpleColumn(right[column], 60, left[column], 790, 16, Element.ALIGN_LEFT); status = ct.go(); if ((status & ColumnText.NO_MORE_COLUMN) != 0) { column++; if (column > 1) { pdfDocument.newPage(); column = 0; } } } log.trace("Index created."); }