List of usage examples for com.lowagie.text List setIndentationLeft
public void setIndentationLeft(float indentation)
From source file:com.aryjr.nheengatu.pdf.RomanList.java
License:Open Source License
/** * Adds an <CODE>Object</CODE> to the <CODE>List</CODE>. * * @param o the object to add.//from w w w . j a v a2s . c o m * @return true if adding the object succeeded */ public boolean add(Object o) { if (o instanceof ListItem) { ListItem item = (ListItem) o; final TagsManager tm = TagsManager.getInstance(); Chunk chunk; if (listStyleType != null && listStyleType.equals("lower-roman")) chunk = new Chunk(toRomanLowerCase(first + list.size()), tm.getFont()); else if (listStyleType != null && listStyleType.equals("upper-roman")) chunk = new Chunk(toRomanUppercase(first + list.size()), tm.getFont()); else if (listStyleType != null && listStyleType.equals("lower-alpha")) chunk = new Chunk(nextLetter(), tm.getFont()); else if (listStyleType != null && listStyleType.equals("upper-alpha")) chunk = new Chunk(nextLetter(), tm.getFont()); else chunk = new Chunk(String.valueOf(first + list.size()), tm.getFont()); chunk.append(" - "); item.setListSymbol(chunk); item.setIndentationLeft(symbolIndent); item.setIndentationRight(0); list.add(item); } else if (o instanceof List) { List nested = (List) o; nested.setIndentationLeft(nested.getIndentationLeft() + symbolIndent); first--; return list.add(nested); } else if (o instanceof String) { return this.add(new ListItem((String) o)); } return false; }
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.java 2 s . c om*/ 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:fr.opensagres.odfdom.converter.pdf.internal.stylable.StylableList.java
License:Open Source License
@SuppressWarnings("unchecked") private void addElement(Element element, boolean addLabel) { if (element instanceof Chunk) { // may it happen? Chunk ch = (Chunk) element;/*from w ww . jav a 2s .c o m*/ StylableParagraph p = new StylableParagraph(null, null); p.setFont(ch.getFont()); p.addElement(ch); element = p.getElement(); } if (element instanceof Phrase) { Phrase p = (Phrase) element; StylableListItem li = new StylableListItem(p); // determine font, it may be set explicitly or use paragraph font Font symbolFont = symbol.getFont(); if (symbolFont.isStandardFont()) { ArrayList<Chunk> chunks = p.getChunks(); for (Chunk chunk : chunks) { // use first specified font if (!chunk.getFont().isStandardFont()) { symbolFont = chunk.getFont(); break; } } if (symbolFont.isStandardFont()) { // use paragraph font symbolFont = p.getFont(); } } // determine line height float lineHeight = StylableParagraph.DEFAULT_LINE_HEIGHT; boolean lineHeightProportional = true; if (element instanceof IStylableElement) { IStylableElement stylableElement = (IStylableElement) element; Style style = stylableElement.getLastStyleApplied(); if (style != null) { StyleParagraphProperties paragraphProperties = style.getParagraphProperties(); StyleLineHeight lineHeightObj = paragraphProperties.getLineHeight(); if (lineHeightObj != null && lineHeightObj.getLineHeight() != null) { lineHeight = lineHeightObj.getLineHeight(); lineHeightProportional = lineHeightObj.isLineHeightProportional(); } } } if (addLabel) { if (numbered || lettered || romanNumbered) { StringBuilder sbuf = new StringBuilder(preSymbol); int index = first + list.size(); if (lettered) { sbuf.append(RomanAlphabetFactory.getString(index, lowercase)); } else if (romanNumbered) { sbuf.append(RomanNumberFactory.getString(index, lowercase)); } else { sbuf.append(index); } sbuf.append(postSymbol); li.setListSymbol(sbuf.toString(), symbolFont, lineHeight, lineHeightProportional); } else { li.setListSymbol(symbol.getContent(), symbolFont, lineHeight, lineHeightProportional); } } else { li.setListSymbol("", symbolFont, lineHeight, lineHeightProportional); } li.setIndentationLeft(symbolIndent); li.setIndentationRight(0.0f); list.add(li); } else if (element instanceof List) { List l = (List) element; // open office specifies absolute list indentation // but iText computes indentation relative to parent list // so we have to set difference l.setIndentationLeft(l.getIndentationLeft() - this.getIndentationLeft()); first--; list.add(l); } }
From source file:fr.opensagres.xdocreport.itext.extension.ExtendedPdfPCell.java
License:Open Source License
@Override public void addElement(Element element) { this.empty = false; if (element instanceof ListItem) { List aList = new List(); aList.setIndentationLeft(((ListItem) element).getIndentationLeft()); aList.add(element);/*from w w w . ja v a 2 s . com*/ super.addElement(aList); } else { super.addElement(element); } }
From source file:org.gbif.ipt.task.Eml2Rtf.java
License:Apache License
/** * Add methods section./*from w ww. j av a 2 s . c om*/ * * @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.odftoolkit.odfdom.converter.internal.itext.stylable.StylableList.java
License:Open Source License
@SuppressWarnings("unchecked") private void addElement(Element element, boolean addLabel) { if (element instanceof Paragraph) { Paragraph p = (Paragraph) element; ListItem li = new StylableListItem(p); if (addLabel) { if (numbered || lettered || romanNumbered) { Chunk chunk = new Chunk(preSymbol, symbol.getFont()); int index = first + list.size(); if (lettered) { chunk.append(RomanAlphabetFactory.getString(index, lowercase)); } else if (romanNumbered) { chunk.append(RomanNumberFactory.getString(index, lowercase)); } else { chunk.append(String.valueOf(index)); }/*from w ww . j a v a 2 s. c o m*/ chunk.append(postSymbol); li.setListSymbol(chunk); } else { li.setListSymbol(symbol); } } else { li.setListSymbol(new Chunk("", symbol.getFont())); } li.setIndentationLeft(symbolIndent, autoindent); li.setIndentationRight(0.0f); list.add(li); } else if (element instanceof List) { List l = (List) element; // open office specifies absolute list indentation // but iText computes indentation relative to parent list // so we have to set difference l.setIndentationLeft(l.getIndentationLeft() - this.getIndentationLeft()); first--; list.add(l); } }
From source file:org.sonar.report.pdf.DefaultPDFReporter.java
License:Open Source License
private void printProjectInfo(Project project, Section section) throws DocumentException, org.dom4j.DocumentException { List data = new List(); data.add(new ListItem(super.getTextProperty("general.name") + ": " + project.getName())); data.add(new ListItem(super.getTextProperty("general.description") + ": " + project.getDescription())); data.add(new ListItem(super.getTextProperty("general.modules") + ": ")); List sublist = new List(); if (project.getSubprojects().size() != 0) { Iterator<Project> it = project.getSubprojects().iterator(); while (it.hasNext()) { sublist.add(new ListItem(it.next().getName())); }/*from w w w . jav a 2 s. co m*/ } else { sublist.add(new ListItem(super.getTextProperty("general.no_modules"))); } sublist.setIndentationLeft(indentation); data.add(sublist); section.add(data); printMeasures(project.getMeasures(), section); }
From source file:questions.objects.NestedList.java
public static void main(String[] args) { Document document = new Document(); try {/*from w ww. j a v a2s. c om*/ PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); List list; ListItem listItem; List sublist; list = new List(true); list.setPreSymbol("Chapter "); list.setPostSymbol(": "); listItem = new ListItem("Isaac Asimov"); list.add(listItem); sublist = new List(true); sublist.setIndentationLeft(10); sublist.setPreSymbol("1."); sublist.add("The Foundation Trilogy"); sublist.add("The Complete Robot"); sublist.add("Caves of Steel"); sublist.add("The Naked Sun"); list.add(sublist); listItem = new ListItem("John Irving"); list.add(listItem); sublist = new List(true); sublist.setIndentationLeft(10); sublist.setPreSymbol("Section 2."); sublist.add("The World according to Garp"); sublist.add("Hotel New Hampshire"); sublist.add("A prayer for Owen Meany"); sublist.add("Widow for a year"); list.add(sublist); listItem = new ListItem("Kurt Vonnegut"); list.add(listItem); sublist = new List(true); sublist.setIndentationLeft(10); sublist.setPreSymbol("3."); sublist.setPostSymbol("# "); sublist.add("Slaughterhouse 5"); sublist.add("Welcome to the Monkey House"); sublist.add("The great pianola"); sublist.add("Galapagos"); list.add(sublist); document.add(list); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); }