List of usage examples for com.lowagie.text List List
public List(boolean numbered, float symbolIndent)
List
. From source file:classroom.filmfestival_c.Movies17.java
@SuppressWarnings("unchecked") protected static Element directors(FilmTitle movie) { Set<DirectorName> directors = movie.getDirectorNames(); if (directors.size() == 0) { Paragraph p = new Paragraph("various directors"); p.setLeading(16);/*www . ja v a2s .c om*/ return p; } if (directors.size() == 1) { DirectorName name = directors.iterator().next(); Paragraph p = new Paragraph(name.getName()); p.setLeading(16); return p; } List list = new List(List.UNORDERED, 10); ListItem li; for (DirectorName director : directors) { li = new ListItem(director.getName()); li.setLeading(16); list.add(li); } return list; }
From source file:classroom.filmfestival_c.Movies17.java
@SuppressWarnings({ "unchecked", "deprecation" }) protected static Element screenings(FestivalScreening screening) { // the specific screening Paragraph p = getScreening(screening, BOLDSMALL); p.setLeading(16);/*from ww w.j a v a 2 s . com*/ FilmTitle movie = screening.getFilmTitle(); Set<FestivalScreening> screenings = movie.getFestivalScreenings(); if (screenings.size() == 1) { return p; } // the alternative screenings List list = new List(List.UNORDERED, 10); list.add(new ListItem(p)); ListItem li; for (FestivalScreening ascreening : screenings) { if (ascreening.getId().equals(screening.getId())) continue; GregorianCalendar gc = new GregorianCalendar(); gc.setTime(ascreening.getId().getDay()); if (gc.get(GregorianCalendar.YEAR) != YEAR) continue; li = new ListItem(getScreening(ascreening, SMALL)); li.setLeading(12); list.add(li); } return list; }
From source file:com.amphisoft.epub2pdf.content.XhtmlHandler.java
License:Open Source License
@Override public void startElement(String uri, String localName, String qName, Attributes attributes) { /*/*w ww . j ava 2s .c o m*/ if("ol".equals(qName) || "ul".equals(qName) || "li".equals(qName)) { System.err.print(qName + " "); } */ currentSaxElemId = saxElemIdCounter; Map<String, String> attrMap = new HashMap<String, String>(); // parse attributes for (int ai = 0; ai < attributes.getLength(); ai++) { attrMap.put(attributes.getQName(ai), attributes.getValue(ai)); } String idAttr = attrMap.get("id"); if (idAttr == null) { idAttr = ""; } String className = attrMap.get("class"); if (className == null) { className = ""; } SaxElement sE = new SaxElement(qName, saxElemIdCounter++, className, idAttr, currentITextStyle); //printlnerr("startElement: " + sE.toString()); saxElementStack.push(sE); try { if (attrMap.get("class") != null) { String[] elemClasses = attrMap.get("class").split(" "); for (String eClass : elemClasses) { StyleSpecText classTextStyles = styleMap.getTextStyleSpecFor(qName, eClass); if (classTextStyles != null) { sE.applyTextStyles(classTextStyles); } } } if (attrMap.get("style") != null) { // TODO this needs more thought, and careful tracking of which tags are still open, etc. //String styleSource = attrMap.get("style"); //CssStyleMap styleTagStyles = cssParser.getStylesFromStyleTag(styleSource); // ... } if (sE.textStyles == null) { try { int stackSize = saxElementStack.size(); if (stackSize > 1) { SaxElement enclosingElement = saxElementStack.elementAt(stackSize - 2); StyleSpecText enclosingSST = enclosingElement.textStyles; if (enclosingSST != null) sE.applyTextStyles(enclosingSST); } } catch (Exception e) { } } StyleSpecText currentTextStyles = sE.textStyles; if (currentTextStyles != null) { if (currentTextStyles.isBold()) { currentITextStyle |= Font.BOLD; } if (currentTextStyles.isItalic()) { currentITextStyle |= Font.ITALIC; } } //System.err.println("PUSH -> " + saxElementStack); previousTag = currentTag; currentTag = qName; if (document.isOpen()) { if (XhtmlTags.NEWLINE.equals(qName)) { if (stack.size() > 0) { TextElementArray currentTEA = (TextElementArray) stack.peek(); currentTEA.add(Chunk.NEWLINE); } else if (specialParagraph != null) { specialParagraph.add(Chunk.NEWLINE); } } updateStack(); String xmlElementId = attrMap.get("id"); if (XhtmlTags.ANCHOR.equals(qName)) { //concession to nonconformists... if (xmlElementId == null) { xmlElementId = attrMap.get("name"); } Anchor anchor = textFactory.newAnchor(); String ref = attrMap.get(XhtmlTags.REFERENCE); if (ref != null) { int aNameStartIdx = ref.lastIndexOf("#") + 1; ref = ref.substring(aNameStartIdx); anchor.setReference(ref); } if (xmlElementId != null) { anchor.setName(xmlElementId); } pushToStack(anchor); } else { if (xmlElementId != null) { //flushStack(); Anchor dest = textFactory.newAnchor(); dest.setName(xmlElementId); pushToStack(dest); //flushStack(); } for (int i = 0; i < 6; i++) { if (XhtmlTags.H[i].equals(qName)) { flushStack(); freshParagraph = true; currentITextStyle |= Font.BOLD; specialParagraph = textFactory.newHeadline(i + 1); return; } } if ("blockquote".equals(qName)) { flushStack(); freshParagraph = true; Paragraph p = textFactory.newParagraph(); p.setIndentationLeft(50); p.setIndentationRight(20); p.setAlignment(defaultAlignment); pushToStack(p); } else if (XhtmlTags.PARAGRAPH.equals(qName)) { flushStack(); freshParagraph = true; Paragraph p = textFactory.newParagraph(); pushToStack(p); } else if (XhtmlTags.DIV.equals(qName)) { if (stack.size() > 0 && stack.peek().getChunks().size() > 0) { flushStack(); } if (stack.size() == 0) { Paragraph brandNewParagraph = textFactory.newParagraph(); pushToStack(brandNewParagraph); freshParagraph = true; } } else if (XhtmlTags.PRE.equals(qName)) { flushStack(); freshParagraph = true; Paragraph p = textFactory.newParagraphPre(); pushToStack(p); } else if (XhtmlTags.ORDEREDLIST.equals(qName)) { flushStack(); List oList = new List(List.ORDERED, 10); pushToStack(oList); } else if (XhtmlTags.UNORDEREDLIST.equals(qName)) { flushStack(); List uList = new List(List.UNORDERED, 10); pushToStack(uList); } else if (XhtmlTags.LISTITEM.equals(qName)) { freshParagraph = true; ListItem listItem = new ListItem(); pushToStack(listItem); } else if (XhtmlTags.IMAGE.equals(qName)) { handleImage(attributes); } else if (qName != null && qName.endsWith("image")) { handleSvgImage(attributes); } else if (XhtmlTags.LINK.equals(qName)) { // if it's a stylesheet, parse it & update current-style if ("stylesheet".equals(attrMap.get("rel")) && "text/css".equals(attrMap.get("type")) && attrMap.get("href") != null) { String cssHref = xhtmlDir.getAbsoluteFile().toURI().toString() + attrMap.get("href"); CssStyleMap stylesFromLink = cssParser.getStylesFromFileURI(cssHref); if (stylesFromLink != null) { styleMap.updateWith(stylesFromLink); } } } else if (XhtmlTags.STYLE.equals(qName)) { inStyleTag = true; } else if (XhtmlTags.EM.equals(qName) || "I".equals(qName.toUpperCase())) { currentITextStyle |= Font.ITALIC; } else if (XhtmlTags.STRONG.equals(currentTag) || "B".equals(qName.toUpperCase())) { currentITextStyle |= Font.BOLD; } } } else if (XhtmlTags.BODY.equals(qName)) { document.open(); freshParagraph = true; } } catch (Exception e) { e.printStackTrace(); } //printlnerr("leaving startElement " + localName + "; stack: " + stackStatus()); }
From source file:com.concursive.connect.web.modules.wiki.utils.WikiPDFUtils.java
License:Open Source License
private static boolean parseContent(WikiPDFContext context, Wiki wiki, String content, Document document, PdfPCell cell, Connection db, ArrayList<Integer> wikiListTodo, ArrayList<Integer> wikiListDone, float cellWidth) throws Exception { LOG.debug("PARSING CONTENT: " + content); // Parse the wiki page int lastIndent = 0; boolean preTag = false; boolean pre = false; boolean code = false; boolean header = true; try {/*from ww w. ja v a 2 s .co m*/ BufferedReader in = new BufferedReader(new StringReader(content)); String line = null; ArrayList unorderedParents = null; List thisList = null; Paragraph codeParagraph = null; while ((line = in.readLine()) != null) { // Tables if (line.startsWith("|")) { // @todo Close all ordered lists, unordered lists, and paragraphs // Parse the table line = parseTable(context, wiki, line, document, db, wikiListTodo, wikiListDone, in); if (line == null) { continue; } } // Forms if (line.startsWith("[{form")) { // @todo close any lists or paragraphs // parseForm operates over all the lines that make up the form, // it will have to look forward so it returns an unparsed line parseForm(context, db, in, line, document, cell); continue; } // Handle code blocks // @todo chunk the content similar to WikiToHTMLUtils otherwise inaccurate if (line.startsWith("<pre>") || line.startsWith("<code>")) { if (!code && !pre) { if (line.startsWith("<pre>")) { preTag = true; pre = true; } else if (line.startsWith("<code>")) { code = true; } codeParagraph = new Paragraph("", codeFont); codeParagraph.setSpacingBefore(10); if (pre && line.length() > ("<pre>").length()) { int endOfLine = line.length(); if (line.endsWith("</pre>")) { endOfLine = line.indexOf("</pre>"); } // This line has some extra content that needs to be added codeParagraph.add(new Chunk( line.substring(line.indexOf("<pre>") + 5, endOfLine) + Chunk.NEWLINE)); } if (code && line.length() > ("<code>").length()) { int endOfLine = line.length(); if (line.endsWith("</code>")) { endOfLine = line.indexOf("</code>"); } // This line has some extra content that needs to be added codeParagraph.add(new Chunk( line.substring(line.indexOf("<code>") + 6, endOfLine) + Chunk.NEWLINE)); } // See if this is a single line block if (preTag && line.endsWith("</pre>")) { // This is a single line block, so finish processing it } else if (code && line.endsWith("</code>")) { // This is a single line block, so finish processing it } else { // There are more lines to process, so do that continue; } } } if (line.startsWith("</code>") || line.endsWith("</code>")) { if (code) { code = false; if (line.indexOf("</code>") > 0 && !line.startsWith("<code>")) { // This line has some extra content that needs to be added codeParagraph .add(new Chunk(line.substring(0, line.indexOf("</code>")) + Chunk.NEWLINE)); } // Draw the final content PdfPTable codeTable = new PdfPTable(1); codeTable.setWidthPercentage(100); codeTable.setSpacingBefore(10); PdfPCell codeCell = new PdfPCell(codeParagraph); codeCell.setPadding(20); codeCell.setBorderColor(new Color(100, 100, 100)); codeCell.setBackgroundColor(new Color(200, 200, 200)); // codeCell.setNoWrap(true); codeTable.addCell(codeCell); LOG.debug("document.add(codeTable)"); document.add(codeTable); continue; } } if (line.startsWith("</pre>") || line.endsWith("</pre>")) { if (pre) { preTag = false; pre = false; if (line.indexOf("</pre>") > 0 && !line.startsWith("<pre>")) { // This line has some extra content that needs to be added codeParagraph.add(new Chunk(line.substring(0, line.indexOf("</pre>")) + Chunk.NEWLINE)); } // Draw the final content PdfPTable codeTable = new PdfPTable(1); codeTable.setWidthPercentage(100); codeTable.setSpacingBefore(10); PdfPCell codeCell = new PdfPCell(codeParagraph); codeCell.setPadding(20); codeCell.setBorderColor(new Color(100, 100, 100)); codeCell.setBackgroundColor(new Color(200, 200, 200)); // codeCell.setNoWrap(true); codeTable.addCell(codeCell); LOG.debug("document.add(codeTable)"); document.add(codeTable); continue; } } if (code || preTag) { // Append the chunk codeParagraph.add(new Chunk(line + Chunk.NEWLINE)); continue; } // Section if (line.startsWith("=") && line.endsWith("=")) { // @todo close any open lists or paragraphs int hCount = parseHCount(line, "="); if (hCount > 6) { hCount = 6; } String section = line.substring(line.indexOf("=") + hCount, line.lastIndexOf("=") - hCount + 1); header = true; context.foundHeader(hCount); String headerAnchor = null; // Store the h2's with anchors for table of contents or index if (hCount == 2) { headerAnchor = StringUtils.toHtmlValue(section).replace(" ", "_"); context.getHeaderAnchors().put(headerAnchor, section); } if (hCount == 3) { Paragraph title = new Paragraph(section.trim(), section2Font); title.setSpacingBefore(10); if (cell != null) { LOG.debug("phrase.add(title)"); cell.addElement(title); } else { LOG.debug("document.add(title)"); document.add(title); } } else if (hCount > 3) { Paragraph title = new Paragraph(section.trim(), section3Font); title.setSpacingBefore(10); if (cell != null) { LOG.debug("phrase.add(title)"); cell.addElement(title); } else { LOG.debug("document.add(title)"); document.add(title); } } else { Paragraph title = new Paragraph(section.trim(), sectionFont); title.setSpacingBefore(10); if (cell != null) { LOG.debug("phrase.add(title)"); cell.addElement(title); } else { LOG.debug("document.add(title)"); document.add(title); } } continue; } if (header) { header = false; if (line.trim().equals("")) { // remove the extra space a user may leave after a header continue; } } // Determine if this is a bulleted list if (line.startsWith("*") || line.startsWith("#")) { // Initialize the list array if (unorderedParents == null) { unorderedParents = new ArrayList(); // if (phrase != null) { // LOG.debug("phrase.add(new Paragraph(Chunk.NEWLINE))"); // phrase.add(new Paragraph(Chunk.NEWLINE)); // } else { // LOG.debug("document.add(new Paragraph(Chunk.NEWLINE))"); // document.add(new Paragraph(Chunk.NEWLINE)); // } } // Get the indent level boolean ol = line.startsWith("#"); int hCount = WikiPDFUtils.parseHCount(line, ol ? "#" : "*"); // Determine a shift in the tree if (lastIndent == 0) { if (ol) { thisList = new List(ol, 20); } else { thisList = new List(ol, 10); thisList.setListSymbol( new Chunk("\u2022", FontFactory.getFont(FontFactory.HELVETICA, 12))); } thisList.setIndentationLeft(36); thisList.setIndentationRight(36); unorderedParents.add(thisList); } else { if (hCount > lastIndent) { if (ol) { thisList = new List(ol, 20); } else { thisList = new List(ol, 10); thisList.setListSymbol( new Chunk("\u2022", FontFactory.getFont(FontFactory.HELVETICA, 12))); } thisList.setIndentationLeft(36); thisList.setIndentationRight(36); ((List) unorderedParents.get(unorderedParents.size() - 1)).add(thisList); unorderedParents.add(thisList); } else if (hCount < lastIndent) { unorderedParents.remove(unorderedParents.size() - 1); thisList = (List) unorderedParents.get(unorderedParents.size() - 1); } } lastIndent = hCount; // Append the item... Paragraph thisItem = new Paragraph(); parseLine(context, line.substring(hCount).trim(), thisItem, db, wikiListTodo, cellWidth, cell); thisList.add(new ListItem(thisItem)); continue; } // List is finished, so append it to the document before working on // other paragraphs if (unorderedParents != null) { if (cell != null) { LOG.debug("phrase.add((List) unorderedParents.get(0))"); cell.addElement((List) unorderedParents.get(0)); } else { LOG.debug("document.add((List) unorderedParents.get(0))"); document.add((List) unorderedParents.get(0)); } unorderedParents = null; thisList = null; lastIndent = 0; } // Otherwise a simple paragraph Paragraph paragraph = new Paragraph(); parseLine(context, line, paragraph, db, wikiListTodo, cellWidth, cell); if (cell != null) { LOG.debug("phrase.add(paragraph)"); if (cell.getHorizontalAlignment() == Element.ALIGN_CENTER) { paragraph.setAlignment(Element.ALIGN_CENTER); } paragraph.setSpacingBefore(5); cell.addElement(paragraph); } else { LOG.debug("document.add(paragraph)"); paragraph.setSpacingBefore(5); document.add(paragraph); } } // Cleanup now that the lines are finished if (pre || code) { PdfPTable codeTable = new PdfPTable(1); codeTable.setWidthPercentage(100); codeTable.setSpacingBefore(10); PdfPCell codeCell = new PdfPCell(codeParagraph); codeCell.setPadding(20); codeCell.setBorderColor(new Color(100, 100, 100)); codeCell.setBackgroundColor(new Color(200, 200, 200)); // codeCell.setNoWrap(true); codeTable.addCell(codeCell); LOG.debug("document.add(codeTable)"); document.add(codeTable); } if (unorderedParents != null) { if (cell != null) { LOG.debug("phrase.add((List) unorderedParents.get(0))"); cell.addElement((List) unorderedParents.get(0)); } else { LOG.debug("document.add((List) unorderedParents.get(0))"); document.add((List) unorderedParents.get(0)); } } in.close(); } catch (Exception e) { LOG.error("parseContent", e); } return true; }
From source file:de.xirp.report.ReportGenerator.java
License:Open Source License
/** * Returns a default formatted list for the given list type. * /* w ww.ja v a 2s. c om*/ * @param type * The list type. * @return A default formatted list. */ private static List getList(ListType type) { switch (type) { case BULLET: List list = new List(false, 20); list.setListSymbol(new Chunk("\u2022", FontFactory.getFont( //$NON-NLS-1$ FontFactory.HELVETICA, 12, Font.BOLD))); return list; case DASH: return new List(false, 20); case NUMBER: return new List(true, 20); } return null; }
From source file:org.areasy.common.doclet.document.tags.HtmlTag.java
License:Open Source License
/** * Adds elements of a nested tag to the contents * of this HTML tag.//from ww w.java2 s . com * * @param elements The PDF elements of the nexted tag. */ public void addNestedTagContent(Element[] elements) { // special hack for list elements without specified // list type (<li> tags without <ul> or <ol>) boolean missingList = false; for (int i = 0; i < elements.length; i++) { if (elements[i] instanceof ListItem) missingList = true; } List list = null; if (missingList) list = new List(false, 8); for (int i = 0; i < elements.length; i++) { if (missingList && elements[i] instanceof ListItem) list.add(elements[i]); else getContentPdf().add(elements[i]); } if (missingList && list != null) getContentPdf().add(list); }
From source file:org.areasy.common.doclet.document.tags.TagUL.java
License:Open Source License
/** * @param parent * @param type */ public TagUL(HtmlTag parent, int type) { super(parent, type); list = new List(false, 8); }
From source file:org.gbif.ipt.task.Eml2Rtf.java
License:Apache License
/** * Add methods section.// w w w.ja va2 s . co m * * @param doc Document * @param eml EML * @throws DocumentException if problem occurs during add */ private void addMethods(Document doc, Eml eml) throws DocumentException { if (exists(eml.getMethodSteps()) && !eml.getMethodSteps().isEmpty() || exists(eml.getStudyExtent()) || exists(eml.getStudyExtent()) || exists(eml.getStudyExtent())) { Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_JUSTIFIED); p.setFont(font); p.add(new Phrase(getText("rtf.methods"), fontTitle)); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); if (exists(eml.getStudyExtent())) { p.add(new Phrase(getText("rtf.methods.studyExtent"), fontTitle)); p.add(Chunk.NEWLINE); p.add(eml.getStudyExtent().replace("\r\n", "\n")); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); } if (exists(eml.getStudyExtent())) { p.add(new Phrase(getText("rtf.methods.sampling"), fontTitle)); p.add(Chunk.NEWLINE); p.add(eml.getSampleDescription().replace("\r\n", "\n")); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); } if (exists(eml.getQualityControl())) { p.add(new Phrase(getText("rtf.methods.quality"), fontTitle)); p.add(Chunk.NEWLINE); p.add(eml.getQualityControl().replace("\r\n", "\n")); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); } if (eml.getMethodSteps().size() == 1) { p.add(new Phrase(getText("rtf.methods.description"), fontTitle)); p.add(Chunk.NEWLINE); p.add(eml.getMethodSteps().get(0).replace("\r\n", "\n")); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); } else if (eml.getMethodSteps().size() > 1) { p.add(new Phrase(getText("rtf.methods.description") + ". ", fontTitle)); p.add(Chunk.NEWLINE); p.add(Chunk.NEWLINE); List list = new List(List.UNORDERED, 0); list.setIndentationLeft(20); for (String method : eml.getMethodSteps()) { list.add(new ListItem(method.replace("\r\n", "\n"), font)); } p.add(list); } doc.add(p); p.clear(); } }
From source file:org.pz.platypus.plugin.pdf.PdfOutfile.java
License:Open Source License
/** * Adds a new bullet list to the stack of bulleted lists. (These are saved in a stack because * lists can nest).//from w w w . ja v a 2s . c om * * @param bulletSymbol symbol to be used as the bullet marker (an iText Chunk) */ public void startPlainBulletList(final Chunk bulletSymbol) { // set the skip to 0 lines, output old text, start a new paragraph. float initialParaSkip = pdfData.getParagraphSkip(); int initialParaSkipSource = pdfData.getParagraphSkipLine(); pdfData.setParagraphSkip(0f, new Source(0, initialParaSkipSource)); startNewParagraph(); // then reset the paragraph skip to the previous value. pdfData.setParagraphSkip(initialParaSkip, new Source(0, initialParaSkipSource)); // create the bullet list Chunk bulletMarker = bulletSymbol; float indentMargin = 18f; // for the nonce, all indents are 1/4" List bulletList = new List(List.UNORDERED, indentMargin); if (bulletMarker == null || bulletMarker.isEmpty()) { bulletMarker = new Chunk(DefaultValues.BULLET); } bulletList.setListSymbol(bulletMarker); bulletLists.add(bulletList); }
From source file:questions.objects.NestingLists.java
public static void main(String[] args) throws IOException, DocumentException { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open();//from w w w . j a va2 s . c o m List list1 = new List(List.ORDERED, 20); list1.add(new ListItem(new Chunk("Level 1 - Item 1"))); list1.add(new ListItem(new Chunk("Level 1 - Item 2"))); list1.add(new ListItem(new Chunk("Level 1 - Item 3"))); List list2 = new List(List.ORDERED, 20); list2.add(new ListItem(new Chunk("Level 2 - Item 1"))); list2.add(new ListItem(new Chunk("Level 2 - Item 2"))); List list3 = new List(List.ORDERED, 20); list3.add(new ListItem(new Chunk("Level 3 - Item 1"))); list3.add(new ListItem(new Chunk("Level 3 - Item 2"))); list3.add(new ListItem(new Chunk("Level 3 - Item 3"))); list3.add(new ListItem(new Chunk("Level 3 - Item 4"))); list2.add(list3); list1.add(list2); list1.add(new ListItem(new Chunk("Level 1 - Item 4"))); document.add(list1); document.close(); }