Package com.itextpdf.tool.xml
Class XMLWorkerHelper
java.lang.Object
com.itextpdf.tool.xml.XMLWorkerHelper
A helper class for parsing XHTML/CSS or XML flow to PDF.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate CssFileprivate static XMLWorkerHelperprivate TagProcessorFactory -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CssFilegetCSS(InputStream in) getDefaultCssResolver(boolean addDefaultCss) Get a CSSResolver implementation.protected TagProcessorFactoryRetrieves the default factory for processing HTML tags fromTags.getHtmlTagProcessorFactory().static XMLWorkerHelperGet a Singleton XMLWorkerHelperstatic ElementListparseToElementList(String html, String css) Parses an HTML string and a string containing CSS into a list of Element objects.voidparseXHtml(PdfWriter writer, Document doc, InputStream in) voidparseXHtml(PdfWriter writer, Document doc, InputStream in, InputStream inCssFile) voidparseXHtml(PdfWriter writer, Document doc, InputStream in, InputStream inCssFile, FontProvider fontProvider) voidparseXHtml(PdfWriter writer, Document doc, InputStream in, InputStream inCssFile, Charset charset) voidparseXHtml(PdfWriter writer, Document doc, InputStream in, InputStream inCssFile, Charset charset, FontProvider fontProvider) voidparseXHtml(PdfWriter writer, Document doc, InputStream in, InputStream inCssFile, Charset charset, FontProvider fontProvider, String resourcesRootPath) voidparseXHtml(PdfWriter writer, Document doc, InputStream in, Charset charset) voidparseXHtml(PdfWriter writer, Document doc, InputStream in, Charset charset, FontProvider fontProvider) voidparseXHtml(PdfWriter writer, Document doc, Reader in) Parses the xml data.voidparseXHtml(ElementHandler d, InputStream in, Charset charset) voidparseXHtml(ElementHandler d, 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 Details
-
myself
-
tpf
-
defaultCssFile
-
-
Constructor Details
-
XMLWorkerHelper
private XMLWorkerHelper()
-
-
Method Details
-
getInstance
Get a Singleton XMLWorkerHelper- Returns:
- a singleton instance of XMLWorkerHelper
-
getCSS
- Returns:
- the default css file.
-
getDefaultCSS
-
parseXHtml
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:
IOException- thrown when something went wrong with the IO
-
parseXHtml
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:
IOException- thrown when something went wrong with the IO
-
parseXHtml
- Parameters:
writer- the writer to usedoc- the document to usein- theInputStreamof the XHTML source.- Throws:
IOException- if theInputStreamcould not be read.
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, InputStream in, Charset charset, FontProvider fontProvider) throws IOException - Throws:
IOException
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, InputStream in, Charset charset) throws IOException - Parameters:
writer- the writer to usedoc- the document to usein- theInputStreamof the XHTML source.charset- the charset to use- Throws:
IOException- if theInputStreamcould 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 usedoc- the document to usein- theInputStreamof the XHTML source.charset- the charset to usein- theCssFilesof the css files.- Throws:
IOException- if theInputStreamcould not be read.
-
parseXHtml
public void parseXHtml(PdfWriter writer, Document doc, InputStream in, InputStream inCssFile, Charset charset, FontProvider fontProvider, String resourcesRootPath) throws IOException - Parameters:
writer- the writer to usedoc- the document to usein- theInputStreamof the XHTML source.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)in- theCssFilesof the css files.- Throws:
IOException- if theInputStreamcould 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
- Parameters:
d- the ElementHandlerin- the InputStreamcharset- the charset to use- Throws:
IOException- if something went seriously wrong with IO.
-
getDefaultCssResolver
Get a CSSResolver implementation.- Parameters:
addDefaultCss- true if the defaultCss should already be added.- Returns:
- the default CSSResolver
-
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
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:
IOException
-