/* * (non-Javadoc) * * @see com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, java.util.List, * com.itextpdf.text.Document, java.lang.String) */ public override IList<IElement> Content(IWorkerContext ctx, Tag tag, String content) { List<Chunk> sanitizedChunks = HTMLUtils.Sanitize(content, false); List<IElement> l = new List<IElement>(1); NoNewLineParagraph sanitizedNoNewLineParagraph = new NoNewLineParagraph(); foreach (Chunk sanitized in sanitizedChunks) { Chunk c = GetCssAppliers().ChunkCssAplier.Apply(sanitized, tag); sanitizedNoNewLineParagraph.Add(c); } if (sanitizedNoNewLineParagraph.Count > 0) { try { l.Add(GetCssAppliers().Apply(sanitizedNoNewLineParagraph, tag, GetHtmlPipelineContext(ctx))); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } } return l; }
/* (non-Javadoc) * @see com.itextpdf.tool.xml.ITagProcessor#content(com.itextpdf.tool.xml.Tag, java.lang.String) */ public override IList<IElement> Content(IWorkerContext ctx, Tag tag, String content) { List<Chunk> sanitizedChunks = HTMLUtils.Sanitize(content, false); List<IElement> l = new List<IElement>(1); NoNewLineParagraph sanitizedNoNewLineParagraph = new NoNewLineParagraph(); try { HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); foreach (Chunk sanitized in sanitizedChunks) { sanitizedNoNewLineParagraph.Add(GetCssAppliers().Apply(sanitized, tag, htmlPipelineContext)); } if (sanitizedNoNewLineParagraph.Count > 0) { l.Add(GetCssAppliers().Apply(sanitizedNoNewLineParagraph, tag, htmlPipelineContext)); } } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } return l; }
virtual 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); }
/** * Adds currentContent list to a paragraph element. If addNewLines is true a * Paragraph object is returned, else a NoNewLineParagraph object is * returned. * * @param currentContent IList<IElement> of the current elements to be added. * @param addNewLines bool to declare which paragraph element should be * returned, true if new line should be added or not. * @param applyCSS true if CSS should be applied on the paragraph * @param tag the relevant tag * @return a List with paragraphs */ public virtual IList<IElement> CurrentContentToParagraph(IList<IElement> currentContent, bool addNewLines, bool applyCSS, Tag tag, IWorkerContext ctx) { try { IList<IElement> list = new List<IElement>(); if (currentContent.Count > 0) { if (addNewLines) { Paragraph p = CreateParagraph(); p.MultipliedLeading = 1.2f; foreach (IElement e in currentContent) { if (e is LineSeparator) { try { HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); Chunk newLine = (Chunk)GetCssAppliers().Apply(new Chunk(Chunk.NEWLINE), tag, htmlPipelineContext); p.Add(newLine); } catch (NoCustomContextException exc) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), exc); } } p.Add(e); } if (p.Trim()) { if (applyCSS) { p = (Paragraph) GetCssAppliers().Apply(p, tag, GetHtmlPipelineContext(ctx)); } list.Add(p); } } else { NoNewLineParagraph p = new NoNewLineParagraph(float.NaN); p.MultipliedLeading = 1.2f; foreach (IElement e in currentContent) { p.Add(e); } p = (NoNewLineParagraph) GetCssAppliers().Apply(p, tag, GetHtmlPipelineContext(ctx)); list.Add(p); } } return list; } catch (NoCustomContextException e) { throw new RuntimeWorkerException( LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } }
/* * (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) { try { String name; tag.Attributes.TryGetValue(HTML.Attribute.NAME, out name); IList<IElement> elems = new List<IElement>(0); if (currentContent.Count > 0) { NoNewLineParagraph p = new NoNewLineParagraph(); String url; tag.Attributes.TryGetValue(HTML.Attribute.HREF, out url); foreach (IElement e in currentContent) { if (e is Chunk) { if (null != url) { if (url.StartsWith("#")) { if (LOGGER.IsLogging(Level.TRACE)) { LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.A_LOCALGOTO), url)); } ((Chunk) e).SetLocalGoto(url.Substring(1)); } else { // TODO check url validity? if (null != GetHtmlPipelineContext(ctx).GetLinkProvider() && !url.StartsWith("http")) { String root = GetHtmlPipelineContext(ctx).GetLinkProvider().GetLinkRoot(); if (root.EndsWith("/") && url.StartsWith("/")) { root = root.Substring(0, root.Length - 1); } url = root + url; } if (LOGGER.IsLogging(Level.TRACE)) { LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.A_EXTERNAL), url)); } ((Chunk) e).SetAnchor(url); } } else if (null != name) { ((Chunk) e).SetLocalDestination(name); if (LOGGER.IsLogging(Level.TRACE)) { LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.A_SETLOCALGOTO), name)); } } } p.Add(e); } elems.Add(GetCssAppliers().Apply(p, tag, GetHtmlPipelineContext(ctx))); } else // !currentContent > 0 ; An empty "a" tag has been encountered. // we're using an anchor space hack here. without the space, reader // does // not jump to destination if (null != name) { if (LOGGER.IsLogging(Level.TRACE)) { LOGGER.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.SPACEHACK), name)); } elems.Add(new WriteP(name)); /* * PdfWriter writer = configuration.GetWriter(); ColumnText c = * new ColumnText(writer.GetDirectContent()); * c.SetSimpleColumn(new Phrase(dest), 1, * writer.GetVerticalPosition(false), 1, * writer.GetVerticalPosition(false), 5, Element.ALIGN_LEFT); * try { c.Go(); } catch (DocumentException e) { throw new * RuntimeWorkerException(e); } */ } return elems; } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } }
/** * Adds currentContent list to a paragraph element. If addNewLines is true a * Paragraph object is returned, else a NoNewLineParagraph object is * returned. * * @param currentContent IList<IElement> of the current elements to be added. * @param addNewLines bool to declare which paragraph element should be * returned, true if new line should be added or not. * @param applyCSS true if CSS should be applied on the paragraph * @param tag the relevant tag * @return a List with paragraphs */ public virtual IList<IElement> CurrentContentToParagraph(IList<IElement> currentContent, bool addNewLines, bool applyCSS, Tag tag, IWorkerContext ctx) { try { IList<IElement> list = new List<IElement>(); if (currentContent.Count > 0) { if (addNewLines) { Paragraph p = new Paragraph(float.NaN); foreach (IElement e in currentContent) { p.Add(e); } if (applyCSS) { p = (Paragraph) CssAppliers.GetInstance().Apply(p, tag, GetHtmlPipelineContext(ctx)); } list.Add(p); } else { NoNewLineParagraph p = new NoNewLineParagraph(float.NaN); foreach (IElement e in currentContent) { p.Add(e); } p = (NoNewLineParagraph) CssAppliers.GetInstance().Apply(p, tag, GetHtmlPipelineContext(ctx)); list.Add(p); } } return list; } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } }