Class HtmlPipelineContext

java.lang.Object
com.itextpdf.tool.xml.pipeline.html.HtmlPipelineContext
All Implemented Interfaces:
MarginMemory, PageSizeContainable, CustomContext, CssAppliersAware, Cloneable

public class HtmlPipelineContext extends Object implements CustomContext, Cloneable, MarginMemory, PageSizeContainable, CssAppliersAware
The CustomContext object for the HtmlPipeline.
Use this to configure your HtmlPipeline.
  • Field Details

  • Constructor Details

    • HtmlPipelineContext

      public HtmlPipelineContext(CssAppliers cssAppliers)
      Construct a new HtmlPipelineContext object
  • Method Details

    • resolveProcessor

      protected TagProcessor resolveProcessor(String tag, String nameSpace)
      Parameters:
      tag - the tag to find a TagProcessor for
      nameSpace - the namespace.
      Returns:
      a TagProcessor
    • addFirst

      protected void addFirst(StackKeeper stackKeeper)
      Add a StackKeeper to the top of the stack list.
      Parameters:
      stackKeeper - the StackKeeper
    • peek

      protected StackKeeper peek()
      Retrieves, but does not remove, the head (first element) of this list.
      Returns:
      a StackKeeper or null if there are no elements on the stack
    • currentContent

      protected List<Element> currentContent()
      Returns:
      the current content of elements.
    • acceptUnknown

      public boolean acceptUnknown()
      Returns:
      if this pipelines tag processing accept unknown tags: true. False otherwise
    • isEmpty

      protected boolean isEmpty()
      Returns:
      returns true if the stack is empty
    • poll

      protected StackKeeper poll() throws NoStackException
      Retrieves and removes the top of the stack.
      Returns:
      a StackKeeper
      Throws:
      NoStackException - if there are no elements on the stack
    • autoBookmark

      public boolean autoBookmark()
      Returns:
      true if auto-bookmarks should be enabled. False otherwise.
    • getMemory

      public Map<String,Object> getMemory()
      Returns:
      the memory
    • getImageProvider

      public ImageProvider getImageProvider()
      Returns:
      the image provider or null if there is no ImageProvider.
    • charSet

      @Experimental public HtmlPipelineContext charSet(Charset cSet)
      Set a Charset to use.
      Parameters:
      cSet - the charset.
      Returns:
      this HtmlPipelineContext
    • charSet

      public Charset charSet()
      Returns:
      the Charset to use, or null if none configured.
    • getPageSize

      public Rectangle getPageSize()
      Returns a Rectangle
      Specified by:
      getPageSize in interface PageSizeContainable
      Returns:
      the pagesize.
    • getRootTags

      public List<String> getRootTags()
      Specified by:
      getRootTags in interface MarginMemory
      Returns:
      a list of tags to be taken as root-tags. This matters for margins. By default the root-tags are <body> and <div>
    • getLinkProvider

      public LinkProvider getLinkProvider()
      Returns the LinkProvider, used to prepend e.g. http://www.example.org/ to found <a> tags that have no absolute url.
      Returns:
      the LinkProvider if any.
    • setPageSize

      public HtmlPipelineContext setPageSize(Rectangle pageSize)
      If no pageSize is set, the default value A4 is used.
      Parameters:
      pageSize - the pageSize to set
      Returns:
      this HtmlPipelineContext
    • clone

      Create a clone of this HtmlPipelineContext, the clone only contains the initial values, not the internal values. Beware, the state of the current Context is not copied to the clone. Only the configurational important stuff like the LinkProvider (same object), ImageProvider (new AbstractImageProvider with same ImageRootPath) , TagProcessorFactory (same object), acceptUnknown (primitive), charset (Charset.forName to get a new charset), autobookmark (primitive) are copied.
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • setAcceptUnknown

      public HtmlPipelineContext setAcceptUnknown(boolean acceptUnknown)
      Set to true to allow the HtmlPipeline to accept tags it does not find in the given TagProcessorFactory
      Parameters:
      acceptUnknown - true or false
      Returns:
      this HtmlPipelineContext
    • setTagFactory

      public HtmlPipelineContext setTagFactory(TagProcessorFactory tagFactory)
      Parameters:
      tagFactory - the TagProcessorFactory that should be used
      Returns:
      this HtmlPipelineContext
    • autoBookmark

      public HtmlPipelineContext autoBookmark(boolean autoBookmark)
      Set to true to enable the automatic creation of bookmarks on <h1> to <h6> tags. Works in conjunction with Header.
      Parameters:
      autoBookmark - true or false
      Returns:
      this HtmlPipelineContext
    • setRootTags

      public HtmlPipelineContext setRootTags(List<String> roottags)
      Set the root-tags, this matters for margins. By default these are set to <body> and <div>.
      Parameters:
      roottags - the root tags
      Returns:
      this HtmlPipelineContext
    • setImageProvider

      public HtmlPipelineContext setImageProvider(ImageProvider imageProvider)
      An ImageProvider can be provided and works in conjunction with Image and ListStyleTypeCssApplier for List Images.
      Parameters:
      imageProvider - the ImageProvider to use.
      Returns:
      this HtmlPipelineContext
    • setLinkProvider

      public HtmlPipelineContext setLinkProvider(LinkProvider linkprovider)
      Set the LinkProvider to use if any.
      Parameters:
      linkprovider - the LinkProvider (@see getLinkProvider()
      Returns:
      this HtmlPipelineContext
    • getLastMarginBottom

      public Float getLastMarginBottom() throws NoDataException
      Specified by:
      getLastMarginBottom in interface MarginMemory
      Returns:
      a Float
      Throws:
      NoDataException - if there is no LastMarginBottom set
    • setLastMarginBottom

      public void setLastMarginBottom(Float lmb)
      Description copied from interface: MarginMemory
      Set the last margin bottom.
      Specified by:
      setLastMarginBottom in interface MarginMemory
      Parameters:
      lmb - set the float for lmb
    • setCssAppliers

      public void setCssAppliers(CssAppliers cssAppliers)
      Specified by:
      setCssAppliers in interface CssAppliersAware
      Parameters:
      cssAppliers - the CssAppliers
    • getCssAppliers

      public CssAppliers getCssAppliers()
      Specified by:
      getCssAppliers in interface CssAppliersAware
      Returns:
      the CssAppliers
    • setCssApplier

      public HtmlPipelineContext setCssApplier(CssAppliers cssAppliers)
      Fluent variant of setCssAppliers(CssAppliers)
      Parameters:
      cssAppliers - the cssAppliers
      Returns:
      this
    • getResourcesRootPath

      public String getResourcesRootPath()
    • setResourcesRootPath

      public void setResourcesRootPath(String resourcesRootPath)