Package com.itextpdf.tool.xml
Class XMLWorkerHelper
- java.lang.Object
-
- com.itextpdf.tool.xml.XMLWorkerHelper
-
public class XMLWorkerHelper extends java.lang.ObjectA helper class for parsing XHTML/CSS or XML flow to PDF.
-
-
Field Summary
Fields Modifier and Type Field Description private CssFiledefaultCssFileprivate static XMLWorkerHelpermyselfprivate TagProcessorFactorytpf
-
Constructor Summary
Constructors Modifier Constructor Description privateXMLWorkerHelper()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CssFilegetCSS(java.io.InputStream in)CssFilegetDefaultCSS()CSSResolvergetDefaultCssResolver(boolean addDefaultCss)Get a CSSResolver implementation.protected TagProcessorFactorygetDefaultTagProcessorFactory()Retrieves the default factory for processing HTML tags fromTags.getHtmlTagProcessorFactory().static XMLWorkerHelpergetInstance()Get a Singleton XMLWorkerHelperstatic ElementListparseToElementList(java.lang.String html, java.lang.String css)Parses an HTML string and a string containing CSS into a list of Element objects.voidparseXHtml(PdfWriter writer, Document doc, java.io.InputStream in)voidparseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.io.InputStream inCssFile)voidparseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.io.InputStream inCssFile, FontProvider fontProvider)voidparseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.io.InputStream inCssFile, java.nio.charset.Charset charset)voidparseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.io.InputStream inCssFile, java.nio.charset.Charset charset, FontProvider fontProvider)voidparseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.io.InputStream inCssFile, java.nio.charset.Charset charset, FontProvider fontProvider, java.lang.String resourcesRootPath)voidparseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.nio.charset.Charset charset)voidparseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.nio.charset.Charset charset, FontProvider fontProvider)voidparseXHtml(PdfWriter writer, Document doc, java.io.Reader in)Parses the xml data.voidparseXHtml(ElementHandler d, java.io.InputStream in, java.nio.charset.Charset charset)voidparseXHtml(ElementHandler d, java.io.Reader in)Parses the xml data in the given reader and sends createdElements to the defined ElementHandler.
This method configures the XMLWorker and XMLParser to parse (X)HTML/CSS and accept unknown tags.
-
-
-
Field Detail
-
myself
private static XMLWorkerHelper myself
-
tpf
private TagProcessorFactory tpf
-
defaultCssFile
private CssFile defaultCssFile
-
-
Method Detail
-
getInstance
public static XMLWorkerHelper getInstance()
Get a Singleton XMLWorkerHelper- Returns:
- a singleton instance of XMLWorkerHelper
-
getCSS
public static CssFile getCSS(java.io.InputStream in)
- Returns:
- the default css file.
-
getDefaultCSS
public CssFile getDefaultCSS()
-
parseXHtml
public void parseXHtml(ElementHandler d, java.io.Reader in) throws java.io.IOException
Parses the xml data in the given reader and sends createdElements to the defined ElementHandler.
This method configures the XMLWorker and XMLParser to parse (X)HTML/CSS and accept unknown tags.- Parameters:
d- the handlerin- the reader- Throws:
java.io.IOException- thrown when something went wrong with the IO
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, java.io.Reader in) throws java.io.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 PdfWriterdoc- the Documentin- the reader- Throws:
java.io.IOException- thrown when something went wrong with the IO
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, java.io.InputStream in) throws java.io.IOException
- Parameters:
writer- the writer to usedoc- the document to usein- theInputStreamof the XHTML source.- Throws:
java.io.IOException- if theInputStreamcould not be read.
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.nio.charset.Charset charset, FontProvider fontProvider) throws java.io.IOException
- Throws:
java.io.IOException
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.nio.charset.Charset charset) throws java.io.IOException
- Parameters:
writer- the writer to usedoc- the document to usein- theInputStreamof the XHTML source.charset- the charset to use- Throws:
java.io.IOException- if theInputStreamcould not be read.
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.io.InputStream inCssFile, java.nio.charset.Charset charset, FontProvider fontProvider) throws java.io.IOException
- Parameters:
writer- the writer to usedoc- the document to usein- theInputStreamof the XHTML source.in- theCssFilesof the css files.charset- the charset to use- Throws:
java.io.IOException- if theInputStreamcould not be read.
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.io.InputStream inCssFile, java.nio.charset.Charset charset, FontProvider fontProvider, java.lang.String resourcesRootPath) throws java.io.IOException
- Parameters:
writer- the writer to usedoc- the document to usein- theInputStreamof the XHTML source.in- theCssFilesof the css files.charset- the charset to useresourcesRootPath- defines the root path to find resources in case they are defined in html with relative paths (e.g. images)- Throws:
java.io.IOException- if theInputStreamcould not be read.
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.io.InputStream inCssFile) throws java.io.IOException
- Throws:
java.io.IOException
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.io.InputStream inCssFile, FontProvider fontProvider) throws java.io.IOException
- Throws:
java.io.IOException
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, java.io.InputStream in, java.io.InputStream inCssFile, java.nio.charset.Charset charset) throws java.io.IOException
- Throws:
java.io.IOException
-
parseXHtml
public void parseXHtml(ElementHandler d, java.io.InputStream in, java.nio.charset.Charset charset) throws java.io.IOException
- Parameters:
d- the ElementHandlerin- the InputStreamcharset- the charset to use- Throws:
java.io.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 fromTags.getHtmlTagProcessorFactory(). On subsequent calls the sameTagProcessorFactoryis returned every time.- Returns:
- a
DefaultTagProcessorFactorythat maps HTML tags toTagProcessors
-
parseToElementList
public static ElementList parseToElementList(java.lang.String html, java.lang.String css) throws java.io.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 snippetcss- a String containing CSS- Returns:
- an ElementList instance
- Throws:
java.io.IOException
-
-