Search code examples
c#itext7

GetElementResult() null iText 7


I am converting html to pdf and trying to get the tag coordinates to be able to locate the example text.

<html>

  <body>

     <p><font><strong>example text</strong></font></p>

  </body>

</html>
private class CustomSpanTagWorker : SpanTagWorker
{
    public CustoSpanTagWorker(IElementNode element, ProcessorContext context) : base(element, context)
    {
    }
    
    public override void ProcessEnd(IElementNode element, ProcessorContext context)
    {
        base.ProcessEnd(element, context);

        IPropertyContainer elementResult = GetElementResult();
        
    }

}
public class CustomTagWorker : DefaultTagWorkerFactory
{
    public override ITagWorker GetCustomTagWorker(IElementNode tag, ProcessorContext context)
    {     
      
            if (tag.Name().Equals(TagConstants.STRONG, StringComparison.OrdinalIgnoreCase))
            {
                
                return new CustoSpanTagWorker(tag, context);
                
            }
        
        return null;
    }
}

but I get a GetElementResult () null, when I iterate the element. Please help me to resolve the issue. Thanks in advance.


Solution

  • One <span> HTML element may be mapped to multiple layout elements, so you should use SpanTagWorker#getAllElements instead of SpanTagWorker#getElementResult