com.itextpdf.tool.xml
Class XMLWorkerHelper

java.lang.Object
  extended by com.itextpdf.tool.xml.XMLWorkerHelper

public class XMLWorkerHelper
extends Object

A helper class for parsing XHTML/CSS or XML flow to PDF.

Author:
redlab_b

Method Summary
static CssFile getCSS(InputStream in)
           
 CssFile getDefaultCSS()
           
 CSSResolver getDefaultCssResolver(boolean addDefaultCss)
          Get a CSSResolver implementation.
protected  TagProcessorFactory getDefaultTagProcessorFactory()
          Retrieves the default factory for processing HTML tags from Tags.getHtmlTagProcessorFactory().
static XMLWorkerHelper getInstance()
          Get a Singleton XMLWorkerHelper
static ElementList parseToElementList(String html, String css)
          Parses an HTML string and a string containing CSS into a list of Element objects.
 void parseXHtml(ElementHandler d, InputStream in, Charset charset)
           
 void parseXHtml(ElementHandler d, Reader in)
          Parses the xml data in the given reader and sends created Element s to the defined ElementHandler.
 void parseXHtml(PdfWriter writer, Document doc, InputStream in)
           
 void parseXHtml(PdfWriter writer, Document doc, InputStream in, Charset charset)
           
 void parseXHtml(PdfWriter writer, Document doc, InputStream in, InputStream inCssFile)
           
 void parseXHtml(PdfWriter writer, Document doc, InputStream in, InputStream inCssFile, Charset charset)
           
 void parseXHtml(PdfWriter writer, Document doc, InputStream in, InputStream inCssFile, Charset charset, FontProvider fontProvider)
           
 void parseXHtml(PdfWriter writer, Document doc, InputStream in, InputStream inCssFile, FontProvider fontProvider)
           
 void parseXHtml(PdfWriter writer, Document doc, Reader in)
          Parses the xml data.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static XMLWorkerHelper getInstance()
Get a Singleton XMLWorkerHelper

Returns:
a singleton instance of XMLWorkerHelper

getCSS

public static CssFile getCSS(InputStream in)
Returns:
the default css file.

getDefaultCSS

public CssFile getDefaultCSS()

parseXHtml

public void parseXHtml(ElementHandler d,
                       Reader in)
                throws IOException
Parses the xml data in the given reader and sends created Element s to the defined ElementHandler.
This method configures the XMLWorker and XMLParser to parse (X)HTML/CSS and accept unknown tags.

Parameters:
d - the handler
in - the reader
Throws:
IOException - thrown when something went wrong with the IO

parseXHtml

public void parseXHtml(PdfWriter writer,
                       Document doc,
                       Reader in)
                throws IOException
Parses the xml data. This method configures the XMLWorker to parse (X)HTML/CSS and accept unknown tags. Writes the output in the given PdfWriter with the given document.

Parameters:
writer - the PdfWriter
doc - the Document
in - the reader
Throws:
IOException - thrown when something went wrong with the IO

parseXHtml

public void parseXHtml(PdfWriter writer,
                       Document doc,
                       InputStream in)
                throws IOException
Parameters:
writer - the writer to use
doc - the document to use
in - the InputStream of the XHTML source.
Throws:
IOException - if the InputStream could not be read.

parseXHtml

public void parseXHtml(PdfWriter writer,
                       Document doc,
                       InputStream in,
                       Charset charset)
                throws IOException
Parameters:
writer - the writer to use
doc - the document to use
in - the InputStream of the XHTML source.
charset - the charset to use
Throws:
IOException - if the InputStream could not be read.

parseXHtml

public void parseXHtml(PdfWriter writer,
                       Document doc,
                       InputStream in,
                       InputStream inCssFile,
                       Charset charset,
                       FontProvider fontProvider)
                throws IOException
Parameters:
writer - the writer to use
doc - the document to use
in - the InputStream of the XHTML source.
in - the CssFiles of the css files.
charset - the charset to use
Throws:
IOException - if the InputStream could not be read.

parseXHtml

public void parseXHtml(PdfWriter writer,
                       Document doc,
                       InputStream in,
                       InputStream inCssFile)
                throws IOException
Throws:
IOException

parseXHtml

public void parseXHtml(PdfWriter writer,
                       Document doc,
                       InputStream in,
                       InputStream inCssFile,
                       FontProvider fontProvider)
                throws IOException
Throws:
IOException

parseXHtml

public void parseXHtml(PdfWriter writer,
                       Document doc,
                       InputStream in,
                       InputStream inCssFile,
                       Charset charset)
                throws IOException
Throws:
IOException

parseXHtml

public void parseXHtml(ElementHandler d,
                       InputStream in,
                       Charset charset)
                throws IOException
Parameters:
d - the ElementHandler
in - the InputStream
charset - the charset to use
Throws:
IOException - if something went seriously wrong with IO.

getDefaultCssResolver

public CSSResolver getDefaultCssResolver(boolean addDefaultCss)
Get a CSSResolver implementation.

Parameters:
addDefaultCss - true if the defaultCss should already be added.
Returns:
the default CSSResolver

getDefaultTagProcessorFactory

protected TagProcessorFactory getDefaultTagProcessorFactory()
Retrieves the default factory for processing HTML tags from Tags.getHtmlTagProcessorFactory(). On subsequent calls the same TagProcessorFactory is returned every time.

Returns:
a DefaultTagProcessorFactory that maps HTML tags to TagProcessors

parseToElementList

public static ElementList parseToElementList(String html,
                                             String css)
                                      throws IOException
Parses an HTML string and a string containing CSS into a list of Element objects. The FontProvider will be obtained from iText's FontFactory object.

Parameters:
html - a String containing an XHTML snippet
css - a String containing CSS
Returns:
an ElementList instance
Throws:
IOException


Copyright © 2015. All Rights Reserved.