List of usage examples for com.lowagie.text Chunk Chunk
public Chunk(DrawInterface separator, float tabPosition)
From source file:com.aryjr.nheengatu.pdf.PDFText.java
License:Open Source License
public static Chunk createChunk(final Text htmlText) { final TagsManager tm = TagsManager.getInstance(); final Chunk text = new Chunk(htmlText.getText(), tm.getFont()); return text;//from ww w. j a va 2 s.c om }
From source file:com.aryjr.nheengatu.pdf.PDFText.java
License:Open Source License
public static float getWidth(final Text htmlText) { final TagsManager tm = TagsManager.getInstance(); final Chunk text = new Chunk(htmlText.getText(), tm.getFont()); return text.getWidthPoint(); }
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 ww. j a v a 2 s . 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.bcpv.webapp.displaytag.decorators.ItextTotalWrapper.java
License:Artistic License
/** * Obtain a cell with the given value./*w ww. j av a2s . c om*/ * @param value Value to display in the cell. * @return A cell with the given value. * @throws com.lowagie.text.BadElementException if an error occurs while generating the cell. */ private Cell getCell(String value) throws BadElementException { Cell cell = new Cell(new Chunk(value, this.font)); cell.setLeading(8); cell.setHorizontalAlignment(Element.ALIGN_LEFT); return cell; }
From source file:com.bibisco.export.ITextExporter.java
License:GNU General Public License
@Override public void addText(String pStrText, TextFormatting pTextFormatting) { mLog.debug("Start addText(): " + pStrText); Font lFont = new Font(); lFont.setFamily(mFont.getFamilyname()); lFont.setSize(mFont.getSize());/*from w ww . ja v a 2 s. co m*/ int lIntStyle = 0; if (pTextFormatting.bold) { lIntStyle = lIntStyle | Font.BOLD; } if (pTextFormatting.italic) { lIntStyle = lIntStyle | Font.ITALIC; } if (pTextFormatting.underline) { lIntStyle = lIntStyle | Font.UNDERLINE; } if (pTextFormatting.strike) { lIntStyle = lIntStyle | Font.STRIKETHRU; } lFont.setStyle(lIntStyle); Chunk lChunk = new Chunk(pStrText, lFont); if (mListItem != null) { mListItem.add(lChunk); } else if (mParagraph != null) { mParagraph.add(lChunk); } mLog.debug("End addText()"); }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
License:Apache License
private void printElementHtml(Element element, Object parent, int depth, Font font, int parentLevel) { String tag = element.getName(); Object av;// w w w.jav a 2 s . com if (element instanceof HTMLDocument.RunElement) { HTMLDocument.RunElement re = (HTMLDocument.RunElement) element; int start = re.getStartOffset(); int end = re.getEndOffset(); try { String content = re.getDocument().getText(start, end - start); printAttributesHtml(re); av = re.getAttribute(CSS.Attribute.FONT_SIZE); String fontsize = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.FONT_FAMILY); String fontfamily = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.COLOR); String fontcolor = av == null ? null : av.toString(); if (fontcolor != null || fontsize != null || fontfamily != null) { if (fontfamily == null) fontfamily = font.getFamilyname(); float size = fontsize == null ? font.getSize() : (Float.parseFloat(fontsize) + 9); int style = font.getStyle(); Color color; if (fontcolor != null) { color = Color.decode(fontcolor); } else color = font.getColor(); font = FontFactory.getFont(fontfamily, size, style, color); } if (parent instanceof Paragraph) { ((Paragraph) parent).add(new Chunk(content, font)); } else { System.err.println("chunk with parent " + (parent == null ? "null" : parent.getClass().getName()) + ": " + content); } } catch (BadLocationException e) { e.printStackTrace(); } } else if (element instanceof HTMLDocument.BlockElement) { HTMLDocument.BlockElement be = (HTMLDocument.BlockElement) element; printAttributesHtml(be); av = be.getAttribute(javax.swing.text.html.HTML.Attribute.ALIGN); String align = av == null ? null : av.toString(); if (tag.equalsIgnoreCase("html")) { printElementChildrenHtml(element, parent, depth + 1, font, parentLevel); } else if (tag.equalsIgnoreCase("head")) { // do nothing } else if (tag.equalsIgnoreCase("body")) { printElementChildrenHtml(element, parent, depth + 1, font, parentLevel); } else if (tag.equalsIgnoreCase("p")) { if (parent instanceof Section) { Paragraph paragraph = new Paragraph(); if (align != null) { paragraph.setAlignment(align); } printElementChildrenHtml(element, paragraph, depth + 1, normalFont, parentLevel); ((Section) parent).add(paragraph); } else { System.err.println("p with parent " + (parent == null ? "null" : parent.getClass().getName())); } } else if (tag.equalsIgnoreCase("h1") || tag.equalsIgnoreCase("h2") || tag.equalsIgnoreCase("h3")) { if (parent instanceof Section) { Paragraph title = new Paragraph(); printElementChildrenHtml(element, title, depth + 1, subSectionFont, parentLevel); ((Section) parent).addSection(title, parentLevel == 0 ? 0 : (parentLevel + 1)); } else { System.err .println("list with parent " + (parent == null ? "null" : parent.getClass().getName())); } } else if (tag.equalsIgnoreCase("ul")) { if (parent instanceof Section) { com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f); printElementChildrenHtml(element, list, depth + 1, normalFont, parentLevel); ((Section) parent).add(list); } else { System.err .println("list with parent " + (parent == null ? "null" : parent.getClass().getName())); } } else if (tag.equalsIgnoreCase("ol")) { if (parent instanceof Section) { com.lowagie.text.List list = new com.lowagie.text.List(true, false, 20.0f); printElementChildrenHtml(element, list, depth + 1, normalFont, parentLevel); ((Section) parent).add(list); } else { System.err .println("list with parent " + (parent == null ? "null" : parent.getClass().getName())); } } else if (tag.equalsIgnoreCase("li")) { ListItem li = new ListItem(); li.setSpacingAfter(0.0f); printElementChildrenHtml(element, li, depth + 1, normalFont, parentLevel); ((com.lowagie.text.List) parent).add(li); } else if (tag.equalsIgnoreCase("p-implied")) { if (parent instanceof ListItem) { Paragraph paragraph = new Paragraph(); printElementChildrenHtml(element, paragraph, depth + 1, normalFont, parentLevel); ((ListItem) parent).add(paragraph); } else if (parent instanceof Cell) { Paragraph paragraph = new Paragraph(); printElementChildrenHtml(element, paragraph, depth + 1, normalFont, parentLevel); ((Cell) parent).add(paragraph); } } else if (tag.equalsIgnoreCase("table")) { try { Table table = new Table(3); table.setBorderWidth(1); table.setBorderColor(new Color(0, 128, 128)); table.setPadding(1.0f); table.setSpacing(0.5f); Cell c = new Cell("header"); c.setHeader(true); c.setColspan(3); table.addCell(c); table.endHeaders(); printElementChildrenHtml(element, table, depth + 1, normalFont, parentLevel); // TODO ((Section) parent).add(table); } catch (BadElementException e) { e.printStackTrace(); } } else if (tag.equalsIgnoreCase("tr")) { printElementChildrenHtml(element, parent, depth + 1, normalFont, parentLevel); // TODO } else if (tag.equalsIgnoreCase("td")) { Cell cell = new Cell(); printElementChildrenHtml(element, cell, depth + 1, normalFont, parentLevel); // TODO ((Table) parent).addCell(cell); } else { System.err.println("Unknown element " + element.getName()); printElementChildrenHtml(element, parent, depth + 1, normalFont, parentLevel); } } else { return; // could be BidiElement - not sure what it is } }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
License:Apache License
private Object generateElementHtml(Element element, int depth, Font font) { String tag = element.getName(); Object myself;//from ww w . j a v a 2 s. c o m Object av; if (element instanceof HTMLDocument.RunElement) { HTMLDocument.RunElement re = (HTMLDocument.RunElement) element; int start = re.getStartOffset(); int end = re.getEndOffset(); try { String content = re.getDocument().getText(start, end - start); HtmlAttr htmlattr = printAttributesHtml(re); av = re.getAttribute(CSS.Attribute.FONT_SIZE); String fontsize = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.FONT_FAMILY); String fontfamily = av == null ? null : av.toString(); av = re.getAttribute(CSS.Attribute.COLOR); String fontcolor = av == null ? null : av.toString(); if (fontcolor != null || fontsize != null || fontfamily != null) { if (fontfamily == null) fontfamily = font.getFamilyname(); if (fontsize != null && fontsize.endsWith("pt")) fontsize = fontsize.substring(0, fontsize.indexOf("pt")); float size = fontsize == null ? font.getSize() : (Float.parseFloat(fontsize) + 8); int style = font.getStyle(); Color color; if (fontcolor != null) { color = Color.decode(fontcolor); } else color = font.getColor(); font = FontFactory.getFont(fontfamily, size, style, color); } else if (htmlattr.bold || htmlattr.italic) { String family = font.getFamilyname(); float size = font.getSize(); Color color = font.getColor(); if (htmlattr.bold && htmlattr.italic) font = FontFactory.getFont(family, size, Font.BOLDITALIC, color); else if (htmlattr.italic) font = FontFactory.getFont(family, size, Font.ITALIC, color); else if (htmlattr.bold) font = FontFactory.getFont(family, size, Font.BOLD); } myself = new Chunk(content, font); } catch (BadLocationException e) { e.printStackTrace(); myself = null; } } else if (element instanceof HTMLDocument.BlockElement) { HTMLDocument.BlockElement be = (HTMLDocument.BlockElement) element; HtmlAttr htmlattr = printAttributesHtml(be); if (htmlattr.bold) { System.out.println("+++BOLD!!!"); } av = be.getAttribute(javax.swing.text.html.HTML.Attribute.ALIGN); String align = av == null ? null : av.toString(); if (htmlattr.bold || htmlattr.italic) { String family = font.getFamilyname(); float size = font.getSize(); Color color = font.getColor(); if (htmlattr.bold && htmlattr.italic) font = FontFactory.getFont(family, size, Font.BOLDITALIC, color); else if (htmlattr.italic) font = FontFactory.getFont(family, size, Font.ITALIC, color); else if (htmlattr.bold) font = FontFactory.getFont(family, size, Font.BOLD, Color.blue); } if (tag.equalsIgnoreCase("html")) { myself = generateElementChildrenHtml(element, depth + 1, font); } else if (tag.equalsIgnoreCase("head")) { myself = null; } else if (tag.equalsIgnoreCase("body")) { myself = generateElementChildrenHtml(element, depth + 1, font); } else if (tag.equalsIgnoreCase("p") || tag.equalsIgnoreCase("p-implied")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); Paragraph paragraph = new Paragraph(); paragraph.setFirstLineIndent(0F); for (Object child : children) { if (child instanceof Chunk) { Chunk chunk = (Chunk) child; /*if (!chunk.getContent().equals("\n"))*/ paragraph.add(chunk); } else paragraph.add(child); } if (align != null) paragraph.setAlignment(align); myself = paragraph; } else if (tag.equalsIgnoreCase("h1") || tag.equalsIgnoreCase("h2") || tag.equalsIgnoreCase("h3")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, subSectionFont); Paragraph title = new Paragraph(); for (Object child : children) { title.add(child); } myself = new TempSectionPdf(title); } else if (tag.equalsIgnoreCase("ul")) { com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f); list.setIndentationLeft(25.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { list.add(child); } myself = list; } else if (tag.equalsIgnoreCase("ol")) { com.lowagie.text.List list = new com.lowagie.text.List(true, false, 20.0f); list.setIndentationLeft(25.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { list.add(child); } myself = list; } else if (tag.equalsIgnoreCase("li")) { ListItem li = new ListItem(); li.setSpacingAfter(0.0f); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { li.add(child); } myself = li; } else if (tag.equalsIgnoreCase("table")) { List<Object> rows = generateElementChildrenHtml(element, depth + 1, normalFont); try { int ncols = 0; for (Object row : rows) { if (row instanceof List<?>) { int n = ((List<?>) row).size(); if (n > ncols) ncols = n; } } Table table = new Table(2); table.setBorderWidth(1); table.setBorderColor(new Color(0, 128, 128)); table.setPadding(1.0f); table.setSpacing(0.5f); Cell c = new Cell("header"); c.setHeader(true); c.setColspan(ncols); table.addCell(c); table.endHeaders(); for (Object row : rows) { if (row instanceof List<?>) { for (Object cell : (List<?>) row) { if (cell instanceof Cell) table.addCell((Cell) cell); } } } myself = table; } catch (BadElementException e) { e.printStackTrace(); myself = null; } } else if (tag.equalsIgnoreCase("tr")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); myself = children; } else if (tag.equalsIgnoreCase("td")) { Cell cell = new Cell(); List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); for (Object child : children) { cell.add(child); } myself = cell; } else if (tag.equalsIgnoreCase("div")) { List<Object> children = generateElementChildrenHtml(element, depth + 1, normalFont); Paragraph paragraph = new Paragraph(); paragraph.setFirstLineIndent(0F); for (Object child : children) { paragraph.add(child); } if (align != null) paragraph.setAlignment(align); myself = paragraph; } else { System.err.println("Unknown element " + element.getName()); myself = null; } } else { myself = null; // could be BidiElement - not sure what it is } return myself; }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
License:Apache License
private void printAttributesPdf(Section section, List<AttributeVO> attrs, int parentLevel) { Paragraph sTitle = new Paragraph("Activity Attributes", subSectionFont); Section subsection = section.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1)); com.lowagie.text.List list = new com.lowagie.text.List(false, false, 20.0f); for (AttributeVO attr : attrs) { if (excludeAttribute(attr.getAttributeName(), attr.getAttributeValue())) continue; Phrase phrase = new Phrase(); phrase.add(new Chunk(attr.getAttributeName(), fixedWidthFont)); String v = attr.getAttributeValue(); if (v == null) v = ""; phrase.add(new Chunk(": " + v, normalFont)); list.add(new ListItem(phrase)); }//from www.j a v a 2 s.c o m subsection.add(list); }
From source file:com.centurylink.mdw.designer.pages.ExportHelper.java
License:Apache License
private void printVariablesPdf(Chapter chapter, List<VariableVO> variables, int parentLevel) { Paragraph sTitle = new Paragraph("Process Variables", sectionFont); Section section = chapter.addSection(sTitle, parentLevel == 0 ? 0 : (parentLevel + 1)); com.lowagie.text.List list = new com.lowagie.text.List(false, false, 10.0f); for (VariableVO var : variables) { Phrase phrase = new Phrase(); phrase.add(new Chunk(var.getVariableName(), fixedWidthFont)); String v = var.getVariableType(); if (var.getDescription() != null) v += " (" + var.getDescription() + ")"; phrase.add(new Chunk(": " + v + "\n", normalFont)); list.add(new ListItem(phrase)); }/* w w w. j a v a 2s .co m*/ section.add(list); }
From source file:com.develog.utils.report.engine.export.JRPdfExporter.java
License:Open Source License
/** * *///from w w w. j a v a2s .co m protected Chunk getChunk(Map attributes, String text) throws JRException, DocumentException, IOException { JRFont jrFont = new JRBaseFont(attributes); BaseFont baseFont = null; Exception initialException = null; try { baseFont = BaseFont.createFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded(), true, null, null); } catch (Exception e) { initialException = e; } if (baseFont == null) { byte[] bytes = null; try { bytes = JRLoader.loadBytesFromLocation(jrFont.getPdfFontName()); } catch (JRException e) { throw new JRException("Could not load the following font : " + "\npdfFontName : " + jrFont.getPdfFontName() + "\npdfEncoding : " + jrFont.getPdfEncoding() + "\nisPdfEmbedded : " + jrFont.isPdfEmbedded(), initialException); } baseFont = BaseFont.createFont(jrFont.getPdfFontName(), jrFont.getPdfEncoding(), jrFont.isPdfEmbedded(), true, bytes, null); } Color forecolor = (Color) attributes.get(TextAttribute.FOREGROUND); Color backcolor = (Color) attributes.get(TextAttribute.BACKGROUND); /* if (forecolor == null) { forecolor = Color.black; } */ Font font = new Font(baseFont, (float) jrFont.getSize(), //((jrFont.isBold())?Font.BOLD:0) + //((jrFont.isItalic())?Font.ITALIC:0) + (jrFont.isUnderline() ? Font.UNDERLINE : 0) | (jrFont.isStrikeThrough() ? Font.STRIKETHRU : 0), forecolor); Chunk chunk = new Chunk(text, font); if (backcolor != null) { chunk.setBackground(backcolor); } return chunk; }