/* * (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 { Paragraph p = null; IList <IElement> l = new List <IElement>(1); foreach (IElement e in currentContent) { if (e is Paragraph) { if (p != null) { l.Add(CssAppliers.GetInstance().Apply(p, tag, GetHtmlPipelineContext(ctx))); p = null; } l.Add(e); } else { if (p == null) { p = new Paragraph(); } p.Add(e); } } if (p != null) { l.Add(CssAppliers.GetInstance().Apply(p, tag, GetHtmlPipelineContext(ctx))); } return(l); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } }
/* * (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) { String sanitized = HTMLUtils.Sanitize(content); IList <IElement> l = new List <IElement>(1); if (sanitized.Length > 0) { HtmlPipelineContext myctx; try { myctx = GetHtmlPipelineContext(ctx); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } if (tag.CSS.ContainsKey(CSS.Property.TAB_INTERVAL)) { TabbedChunk tabbedChunk = new TabbedChunk(sanitized); if (null != GetLastChild(tag) && GetLastChild(tag).CSS.ContainsKey(CSS.Property.XFA_TAB_COUNT)) { tabbedChunk.TabCount = int.Parse(GetLastChild(tag).CSS[CSS.Property.XFA_TAB_COUNT]); } l.Add(CssAppliers.GetInstance().Apply(tabbedChunk, tag, myctx)); } else if (null != GetLastChild(tag) && GetLastChild(tag).CSS.ContainsKey(CSS.Property.XFA_TAB_COUNT)) { TabbedChunk tabbedChunk = new TabbedChunk(sanitized); tabbedChunk.TabCount = int.Parse(GetLastChild(tag).CSS[CSS.Property.XFA_TAB_COUNT]); l.Add(CssAppliers.GetInstance().Apply(tabbedChunk, tag, myctx)); } else { l.Add(CssAppliers.GetInstance().Apply(new Chunk(sanitized), tag, myctx)); } } return(l); }
/* * (non-Javadoc) * * @see * com.itextpdf.tool.xml.ITagProcessor#endElement(com.itextpdf.tool.xml.Tag, * java.util.List) */ public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { IList <IElement> listElements = PopulateList(currentContent); int size = listElements.Count; IList <IElement> returnedList = new List <IElement>(); if (size > 0) { HtmlPipelineContext htmlPipelineContext = null; List list; try { htmlPipelineContext = GetHtmlPipelineContext(ctx); list = (List)CssAppliers.GetInstance().Apply(new List(), tag, htmlPipelineContext); } catch (NoCustomContextException) { list = (List)CssAppliers.GetInstance().Apply(new List(), tag, null); } int i = 0; foreach (IElement li in listElements) { if (li is ListItem) { Tag child = tag.Children[i]; if (size == 1) { child.CSS[CSS.Property.MARGIN_TOP] = CalculateTopOrBottomSpacing(true, false, tag, child, ctx).ToString(CultureInfo.InvariantCulture) + "pt"; float marginBottom = CalculateTopOrBottomSpacing(false, false, tag, child, ctx); child.CSS[CSS.Property.MARGIN_BOTTOM] = marginBottom.ToString(CultureInfo.InvariantCulture) + "pt"; } else { if (i == 0) { child.CSS[CSS.Property.MARGIN_TOP] = CalculateTopOrBottomSpacing(true, false, tag, child, ctx).ToString(CultureInfo.InvariantCulture) + "pt"; } if (i == size - 1) { float marginBottom = CalculateTopOrBottomSpacing(false, true, tag, child, ctx); child.CSS[CSS.Property.MARGIN_BOTTOM] = marginBottom.ToString(CultureInfo.InvariantCulture) + "pt"; } } try { list.Add(CssAppliers.GetInstance().Apply(li, child, GetHtmlPipelineContext(ctx))); } catch (NoCustomContextException e1) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e1); } } else { list.Add(li); } i++; } returnedList.Add(list); } return(returnedList); }
/* (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 { IList <IElement> list = new List <IElement>(); HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); LineSeparator lineSeparator = (LineSeparator)CssAppliers.GetInstance().Apply(new LineSeparator(), tag, htmlPipelineContext); Paragraph p = new Paragraph(); p.Add(lineSeparator); list.Add(CssAppliers.GetInstance().Apply(p, tag, htmlPipelineContext)); return(list); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } }
/* (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) { IList <IElement> l = new List <IElement>(1); if (null != content && content.Length > 0) { try { l.Add(CssAppliers.GetInstance().Apply(new Chunk(content), tag, GetHtmlPipelineContext(ctx))); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } } return(l); }
/* (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) { String sanitized = HTMLUtils.SanitizeInline(content); IList <IElement> l = new List <IElement>(1); if (sanitized.Length > 0) { try { l.Add(CssAppliers.GetInstance().Apply(new Chunk(sanitized), tag, GetHtmlPipelineContext(ctx))); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } } return(l); }
/* * (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) { String sanitized = HTMLUtils.Sanitize(content); IList <IElement> l = new List <IElement>(1); if (sanitized.Length > 0) { try { l.Add(CssAppliers.GetInstance().Apply(new NoNewLineParagraph(sanitized), tag, GetHtmlPipelineContext(ctx))); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } } return(l); }
/** * 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); } }
virtual public void SetCssAppliers(CssAppliers cssAppliers) { this.cssAppliers = cssAppliers; }
/** * Construct a new HtmlPipelineContext object */ public HtmlPipelineContext(CssAppliers cssAppliers) { this.queue = new LinkedList<StackKeeper>(); this.memory = new Dictionary<String, Object>(); this.cssAppliers = cssAppliers; if (this.cssAppliers == null) { this.cssAppliers = new CssAppliersImpl(new XMLWorkerFontProvider()); } }
/** * Construct a ParagraphCssApplier. * */ public ParagraphCssApplier(CssAppliers appliers) { this.appliers = appliers; }
/* * (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(CssAppliers.GetInstance().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); } }
/* * (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) { IDictionary <String, String> attributes = tag.Attributes; String src; attributes.TryGetValue(HTML.Attribute.SRC, out src); iTextSharp.text.Image img = null; IList <IElement> l = new List <IElement>(1); if (null != src && src.Length > 0) { // check if the image was already added once try { if (logger.IsLogging(Level.TRACE)) { logger.Trace(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.HTML_IMG_USE), src)); } try { img = new ImageRetrieve(GetHtmlPipelineContext(ctx).GetImageProvider()).RetrieveImage(src); } catch (NoImageProviderException) { img = new ImageRetrieve().RetrieveImage(src); } } catch (IOException e) { if (logger.IsLogging(Level.ERROR)) { logger.Error(String.Format(LocaleMessages.GetInstance().GetMessage(LocaleMessages.HTML_IMG_RETRIEVE_FAIL), src), e); } } catch (NoImageException e) { if (logger.IsLogging(Level.ERROR)) { logger.Error("", e); } } catch (NoCustomContextException e) { throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e); } if (null != img) { String width; attributes.TryGetValue(HTML.Attribute.WIDTH, out width); float widthInPoints = utils.ParsePxInCmMmPcToPt(width); String height; attributes.TryGetValue(HTML.Attribute.HEIGHT, out height); float heightInPoints = utils.ParsePxInCmMmPcToPt(height); if (widthInPoints > 0 && heightInPoints > 0) { img.ScaleAbsolute(widthInPoints, heightInPoints); } else if (widthInPoints > 0) { heightInPoints = img.Height * widthInPoints / img.Width; img.ScaleAbsolute(widthInPoints, heightInPoints); } else if (heightInPoints > 0) { widthInPoints = img.Width * heightInPoints / img.Height; img.ScaleAbsolute(widthInPoints, heightInPoints); } try { HtmlPipelineContext htmlPipelineContext = GetHtmlPipelineContext(ctx); l.Add(CssAppliers.GetInstance().Apply(new Chunk((iTextSharp.text.Image)CssAppliers.GetInstance().Apply(img, tag, htmlPipelineContext), 0, 0, true), tag, htmlPipelineContext)); } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } } } return(l); }
public CssAppliers GetCssAppliers() { return cssAppliers; } public void SetCssAppliers(CssAppliers cssAppliers) { this.cssAppliers = cssAppliers; } }