public static IElement GetElement(this DataTuple dt)
        {
            Paragraph p = new Paragraph();

            // add colon if simple string
            string label = dt.Label.AddDelimiter(':', s => s.EndsWithAlphanum());

            p.AddAll(new IElement[] {
                new Chunk(label, TextSharpFonts.ItemBoldFont),
                new Chunk(dt.Value + " ", TextSharpFonts.ItemFont),
                new Chunk(dt.Unit, TextSharpFonts.ItemFont)
            });
            return p;
        }
Example #2
0
	    /*
	     * (non-Javadoc)
	     * 
	     * @see
	     * com.itextpdf.tool.xml.TagProcessor#endElement(com.itextpdf.tool.xml.Tag,
	     * java.util.List, com.itextpdf.text.Document)
	     */
	    public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) {
		    HtmlCell cell = new HtmlCell();
            try {
                HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx);
                cell = new HtmlCellCssApplier().Apply(cell, tag, htmlPipelineContext, htmlPipelineContext);
            } catch (NoCustomContextException e1) {
                throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e1);
            }
		    IList<IElement> l = new List<IElement>(1);
            IList<IElement> chunks = new List<IElement>();
		    foreach (IElement e in currentContent) {
                if (e is Chunk || e is NoNewLineParagraph || e is LineSeparator) {
                    if (e == Chunk.NEWLINE) {
                        int index = currentContent.IndexOf(e);
                        if (index == currentContent.Count - 1) {
                            continue;
                        } else {
                            IElement nextElement = currentContent[index + 1];
                            if (nextElement is Paragraph) {
                                continue;
                            }
                            if (chunks.Count == 0) {
                                continue;
                            }

                        }
                    } else if (e is LineSeparator) {
                        chunks.Add(Chunk.NEWLINE);
                    }
                    chunks.Add(e);
                    continue;
                } else if (chunks.Count > 0) {
                    Paragraph p = new Paragraph();
                    p.MultipliedLeading = 1.2f;
                    p.AddAll(chunks);
                    p.Alignment = cell.HorizontalAlignment;
                    cell.AddElement(p);
                    chunks.Clear();
                }

                if (e is Paragraph) {
                    ((Paragraph)e).Alignment = cell.HorizontalAlignment;
                }

			    cell.AddElement(e);
		    }
            if ( chunks.Count > 0 ) {
                Paragraph p = new Paragraph();
                p.MultipliedLeading = 1.2f;
                p.AddAll(chunks);
                p.Alignment = cell.HorizontalAlignment;
                cell.AddElement(p);
            }
    	    l.Add(cell);
		    return l;
	    }
Example #3
0
 protected void ProcessChunkItems(IList<IElement> chunks, HtmlCell cell) {
     Paragraph p = new Paragraph();
     p.MultipliedLeading = 1.2f;
     p.AddAll(chunks);
     p.Alignment = cell.HorizontalAlignment;
     if (p.Trim()) {
         cell.AddElement(p);
     }
     chunks.Clear();    
 }
Example #4
0
	    /*
	     * (non-Javadoc)
	     * 
	     * @see
	     * com.itextpdf.tool.xml.TagProcessor#endElement(com.itextpdf.tool.xml.Tag,
	     * java.util.List, com.itextpdf.text.Document)
	     */
	    public override IList<IElement> End(IWorkerContext ctx, Tag tag, IList<IElement> currentContent) {
		    HtmlCell cell = new HtmlCell();
            try {
                HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx);
                cell = (HtmlCell) GetCssAppliers().Apply(cell, tag, htmlPipelineContext);
            } catch (NoCustomContextException e1) {
                throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e1);
            }
		    IList<IElement> l = new List<IElement>(1);
            IList<IElement> chunks = new List<IElement>();
            IList<ListItem> listItems = new List<ListItem>();
	        int index = -1;
		    foreach (IElement e in currentContent) {
		        index++;
                if (e is Chunk || e is NoNewLineParagraph || e is LineSeparator) {
                    if (listItems.Count > 0) {
                        ProcessListItems(ctx, tag, listItems, cell);
                    }
                    if (e is Chunk && Chunk.NEWLINE.Content.Equals(((Chunk)e).Content)) {
                        if (index == currentContent.Count - 1) {
                            continue;
                        } else {
                            IElement nextElement = currentContent[index + 1];
                            if (chunks.Count > 0 && !(nextElement is Chunk) && !(nextElement is NoNewLineParagraph)) {
                                continue;
                            }
                        }
                    } else if (e is LineSeparator) {
                        try {
                            HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx);
                            Chunk newLine = (Chunk)GetCssAppliers().Apply(new Chunk(Chunk.NEWLINE), tag, htmlPipelineContext);
                            chunks.Add(newLine);
                        } catch (NoCustomContextException exc) {
                            throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), exc);
                        }
                    }
                    chunks.Add(e);
                    continue;
                } else if (e is ListItem) {
                    if (chunks.Count >0 ) {
                        ProcessChunkItems(chunks, cell);
                    }
                    listItems.Add((ListItem)e);
                    continue;
                } else {
		            if (chunks.Count > 0) {
                       ProcessChunkItems(chunks, cell); 
                    }
                    if (listItems.Count > 0) {
                        ProcessListItems(ctx, tag, listItems, cell);
                    }
                }

                if (e is Paragraph) {
                    ((Paragraph)e).Alignment = cell.HorizontalAlignment;
                }

			    cell.AddElement(e);
		    }
            if ( chunks.Count > 0 ) {
                Paragraph p = new Paragraph();
                p.MultipliedLeading = 1.2f;
                p.AddAll(chunks);
                p.Alignment = cell.HorizontalAlignment;
                cell.AddElement(p);
            }
    	    l.Add(cell);
		    return l;
	    }