virtual public void SetUp() { LoggerFactory.GetInstance().SetLogger(new SysoLogger(3)); tag.Parent = new Tag("defaultRoot"); basicPara.Add(basic); extraPara.Add(extra); cell1Row1.AddElement(basicPara); cell2Row1.AddElement(extraPara); cell3Row1.AddElement(basicPara); cell4Row1.AddElement(extraPara); cell4Row1.Rowspan = 2; cells1.Add(cell1Row1); cells1.Add(cell2Row1); cells1.Add(cell3Row1); cells1.Add(cell4Row1); row1 = new TableRowElement(cells1, TableRowElement.Place.BODY); cell1Row2.AddElement(extraPara); cell2Row2.AddElement(basicPara); // Tag t = new Tag(null, new HashMap<String, String>()); // t.getAttributes().put("col-span", "2"); cell2Row2.Colspan = 2; cell3Row2.AddElement(extraPara); cells2.Add(cell1Row2); cells2.Add(cell2Row2); //cells2.Add(cell3Row2); row2 = new TableRowElement(cells2, TableRowElement.Place.BODY); rows.Add(row1); rows.Add(row2); }
private 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(); }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.ITagProcessor#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(); IList <IElement> l = new List <IElement>(1); foreach (IElement e in currentContent) { cell.AddElement(e); } try { l.Add(new HtmlCellCssApplier(GetHtmlPipelineContext(ctx)).Apply(cell, tag)); } catch (NoCustomContextException e1) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e1); } return(l); }
public void SetUp() { cells = new List <Element>(); tag = new Tag("td", new Dictionary <String, String>()); basicPara = new NoNewLineParagraph(); basic = new Chunk("content"); cell = new HtmlCell(); applier = new HtmlCellCssApplier(); LoggerFactory.GetInstance().SetLogger(new SysoLogger(3)); Tag parent = new Tag("tr"); parent.Parent = new Tag("table"); tag.Parent = parent; basicPara.Add(basic); cell.AddElement(basicPara); cells.Add(cell); config = new HtmlPipelineContext(null); }
private void ProcessListItems(IWorkerContext ctx, Tag tag, IList <ListItem> listItems, HtmlCell cell) { try { List list = new List(); list.Autoindent = false; list = (List)GetCssAppliers().Apply(list, tag, GetHtmlPipelineContext(ctx)); list.IndentationLeft = 0; foreach (ListItem li in listItems) { ListItem listItem = (ListItem)GetCssAppliers().Apply(li, tag, GetHtmlPipelineContext(ctx)); listItem.SpacingAfter = 0; listItem.SpacingBefore = 0; listItem.MultipliedLeading = 1.2f; list.Add(listItem); } cell.AddElement(list); listItems.Clear(); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } }
/* * (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) { ProcessChunkItems(chunks, cell); } l.Add(cell); return(l); }
/* * (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(); int direction = GetRunDirection(tag); if (direction != PdfWriter.RUN_DIRECTION_DEFAULT) { cell.RunDirection = direction; } if (HTML.Tag.TH.Equals(tag.Name, StringComparison.OrdinalIgnoreCase)) { cell.Role = PdfName.TH; } 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) { if (((Paragraph)e).Alignment == Element.ALIGN_UNDEFINED) { ((Paragraph)e).Alignment = cell.HorizontalAlignment; } } cell.AddElement(e); } if (chunks.Count > 0) { ProcessChunkItems(chunks, cell); } l.Add(cell); return(l); }