Class BaseRendererBuilder<TFinalClass extends BaseRendererBuilder,TBaseRendererBuilderState extends BaseRendererBuilder.BaseRendererBuilderState>
- java.lang.Object
-
- com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder<TFinalClass,TBaseRendererBuilderState>
-
public abstract class BaseRendererBuilder<TFinalClass extends BaseRendererBuilder,TBaseRendererBuilderState extends BaseRendererBuilder.BaseRendererBuilderState> extends Object
Baseclass for all RendererBuilders (PDF and Java2D), has all common settings
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBaseRendererBuilder.BaseRendererBuilderStateThis class is an internal implementation detail.
This is internal, please don't use directly.static classBaseRendererBuilder.FontStylestatic classBaseRendererBuilder.PageSizeUnitsstatic classBaseRendererBuilder.TextDirection
-
Field Summary
Fields Modifier and Type Field Description static floatPAGE_SIZE_LETTER_HEIGHTstatic BaseRendererBuilder.PageSizeUnitsPAGE_SIZE_LETTER_UNITSstatic floatPAGE_SIZE_LETTER_WIDTHprotected TBaseRendererBuilderStatestate
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseRendererBuilder(TBaseRendererBuilderState state)
-
Method Summary
Modifier and Type Method Description TFinalClassaddDOMMutator(FSDOMMutator domMutator)Add a DOM mutator to this builder.TFinalClassdefaultTextDirection(BaseRendererBuilder.TextDirection textDirection)The default text direction of the document.TFinalClasstestMode(boolean mode)Whether to use test mode and output the PDF uncompressed.TFinalClassuseDefaultPageSize(float pageWidth, float pageHeight, BaseRendererBuilder.PageSizeUnits units)Specifies the default page size to use if none is specified in CSS.TFinalClassuseDocumentBuilderFactoryImplementationClass(String documentBuilderFactoryClass)This method should be considered advanced and is not required for most setups.TFinalClassuseFastMode()Use the new (May 2018) fast renderer if possible (only PDF at this point).TFinalClassuseHttpStreamImplementation(FSStreamFactory factory)Provides an HttpStreamFactory implementation if the user desires to use an external HTTP/HTTPS implementation.TFinalClassuseMathMLDrawer(SVGDrawer mathMlImpl)Use the specified MathML implementation.TFinalClassuseObjectDrawerFactory(FSObjectDrawerFactory objectDrawerFactory)Set a factory for <object> drawersTFinalClassuseProtocolsStreamImplementation(FSStreamFactory factory, String... protocols)Provides anFSStreamFactoryimplementation if the user desires to use an external stream provider for a particular list of protocols.TFinalClassuseProtocolsStreamImplementation(FSStreamFactory factory, Set<String> protocols)Provides anFSStreamFactoryimplementation if the user desires to use an external stream provider for a particular set of protocols.TFinalClassuseReplacementText(String replacement)The replacement text to use if a character is cannot be renderered by any of the specified fonts.TFinalClassuseSVGDrawer(SVGDrawer svgImpl)Uses the specified SVG drawer implementation.TFinalClassuseTransformerFactoryImplementationClass(String transformerFactoryClass)This method should be considered advanced and is not required for most setups.TFinalClassuseUnicodeBidiReorderer(BidiReorderer reorderer)Provides a reorderer to properly reverse RTL text.TFinalClassuseUnicodeBidiSplitter(BidiSplitterFactory splitter)Provides a text splitter to split text into directional runs.TFinalClassuseUnicodeCharacterBreaker(FSTextBreaker breaker)Specify the character breaker.TFinalClassuseUnicodeLineBreaker(FSTextBreaker breaker)Specify the line breaker.TFinalClassuseUnicodeToLowerTransformer(FSTextTransformer tr)Specify a transformer to use to lower case strings.TFinalClassuseUnicodeToTitleTransformer(FSTextTransformer tr)Specify a transformer to title case strings.TFinalClassuseUnicodeToUpperTransformer(FSTextTransformer tr)Specify a transformer to use to upper case strings.TFinalClassuseUriResolver(FSUriResolver resolver)Provides a uri resolver to resolve relative uris or private uri schemes.TFinalClasswithFile(File file)Provides a file to convert to PDF.TFinalClasswithHtmlContent(String html, String baseUri)Provides a string containing XHTML/XML to convert to PDF.TFinalClasswithUri(String uri)Provides a URI to convert to PDF.TFinalClasswithW3cDocument(Document doc, String baseUri)Provides a w3c DOM Document acquired from an external source.
-
-
-
Field Detail
-
PAGE_SIZE_LETTER_WIDTH
public static final float PAGE_SIZE_LETTER_WIDTH
- See Also:
- Constant Field Values
-
PAGE_SIZE_LETTER_HEIGHT
public static final float PAGE_SIZE_LETTER_HEIGHT
- See Also:
- Constant Field Values
-
PAGE_SIZE_LETTER_UNITS
public static final BaseRendererBuilder.PageSizeUnits PAGE_SIZE_LETTER_UNITS
-
state
protected final TBaseRendererBuilderState extends BaseRendererBuilder.BaseRendererBuilderState state
-
-
Constructor Detail
-
BaseRendererBuilder
protected BaseRendererBuilder(TBaseRendererBuilderState state)
-
-
Method Detail
-
addDOMMutator
public TFinalClass addDOMMutator(FSDOMMutator domMutator)
Add a DOM mutator to this builder. DOM mutators allow to modify the DOM before it is rendered. e.g. LaTeXDOMMutator can be used to translate latex text within a <latex> node to HTMl and MathML.- Parameters:
domMutator- the DOM Mutator- Returns:
- this for method chaining
-
useTransformerFactoryImplementationClass
public final TFinalClass useTransformerFactoryImplementationClass(String transformerFactoryClass)
This method should be considered advanced and is not required for most setups. Set a preferred implementation class for use as javax.xml.transform.TransformerFactory. Use null to let a default implementation class be used. The default is "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl". This seems to work with most systems but not JBoss Wildfly and related setups. In this case you can use null to let the container use whatever TransformerFactory it has available.- Parameters:
transformerFactoryClass-- Returns:
- this for method chaining
-
useDocumentBuilderFactoryImplementationClass
public final TFinalClass useDocumentBuilderFactoryImplementationClass(String documentBuilderFactoryClass)
This method should be considered advanced and is not required for most setups. Set a preferred implementation class for use as javax.xml.parsers.DocumentBuilderFactory. Use null to let a default implementation class be used. The default is "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl". If the default does not work you can use null to let the container use whatever DocumentBuilderFactory it has available.- Parameters:
documentBuilderFactoryClass-- Returns:
- this for method chaining
-
defaultTextDirection
public final TFinalClass defaultTextDirection(BaseRendererBuilder.TextDirection textDirection)
The default text direction of the document. LTR by default.- Parameters:
textDirection-- Returns:
- this for method chaining
-
testMode
public final TFinalClass testMode(boolean mode)
Whether to use test mode and output the PDF uncompressed. Turned off by default.- Parameters:
mode-- Returns:
- this for method chaining
-
useHttpStreamImplementation
public final TFinalClass useHttpStreamImplementation(FSStreamFactory factory)
Provides an HttpStreamFactory implementation if the user desires to use an external HTTP/HTTPS implementation. Uses URL::openStream by default.- Parameters:
factory- the factory to use for HTTP/HTTPS- Returns:
- this for method chaining
- See Also:
useProtocolsStreamImplementation(FSStreamFactory, String[])
-
useProtocolsStreamImplementation
public final TFinalClass useProtocolsStreamImplementation(FSStreamFactory factory, Set<String> protocols)
Provides anFSStreamFactoryimplementation if the user desires to use an external stream provider for a particular set of protocols. Protocols should always be in lower case. NOTE: HttpStreamFactory, despite its historical name, can be used for any protocol including private made-up protocols.- Parameters:
factory- the stream factory to useprotocols- the list of protocols the factory should be used for- Returns:
- this for method chaining
- See Also:
useHttpStreamImplementation(FSStreamFactory),useProtocolsStreamImplementation(FSStreamFactory, String[])
-
useProtocolsStreamImplementation
public final TFinalClass useProtocolsStreamImplementation(FSStreamFactory factory, String... protocols)
Provides anFSStreamFactoryimplementation if the user desires to use an external stream provider for a particular list of protocols. Protocols should always be in lower case. NOTE: HttpStreamFactory, despite its historical name, can be used for any protocol including private made-up protocols.- Parameters:
factory- the stream factory to useprotocols- the list of protocols the stream factory should be used for- Returns:
- this for method chaining
- See Also:
useHttpStreamImplementation(FSStreamFactory),useProtocolsStreamImplementation(FSStreamFactory, Set)
-
useUriResolver
public final TFinalClass useUriResolver(FSUriResolver resolver)
Provides a uri resolver to resolve relative uris or private uri schemes.- Parameters:
resolver- the URI resolver used to resolve any kind of private URIs/protocolls- Returns:
- this for method chaining
-
useUnicodeBidiSplitter
public final TFinalClass useUnicodeBidiSplitter(BidiSplitterFactory splitter)
Provides a text splitter to split text into directional runs. Does nothing by default.- Parameters:
splitter- the unicode bidi splitter to use.- Returns:
- this for method chaining
-
useUnicodeBidiReorderer
public final TFinalClass useUnicodeBidiReorderer(BidiReorderer reorderer)
Provides a reorderer to properly reverse RTL text. No-op by default.- Parameters:
reorderer- the unicode bidi reorderer to use.- Returns:
- this for method chaining
-
withHtmlContent
public final TFinalClass withHtmlContent(String html, String baseUri)
Provides a string containing XHTML/XML to convert to PDF.- Parameters:
html- the HTML file to use.baseUri- the base URI to resolve future resources (e.g. images)- Returns:
- this for method chaining
-
withW3cDocument
public final TFinalClass withW3cDocument(Document doc, String baseUri)
Provides a w3c DOM Document acquired from an external source.- Parameters:
doc- the DOM of the HTML documentbaseUri- the base URI, it will be used to resolve future resources (images, etc.- Returns:
- this for method chaining
-
withUri
public final TFinalClass withUri(String uri)
Provides a URI to convert to PDF. The URI MUST point to a strict XHTML/XML document.- Parameters:
uri- the URI of the HTML source to convert.- Returns:
- this for method chaining
-
withFile
public final TFinalClass withFile(File file)
Provides a file to convert to PDF. The file MUST contain XHTML/XML in UTF-8 encoding.- Parameters:
file- the file with the HTML source to convert- Returns:
- this for method chaining
-
useSVGDrawer
public final TFinalClass useSVGDrawer(SVGDrawer svgImpl)
Uses the specified SVG drawer implementation. NOTE: This implementation is used for both inline SVG markup and SVG markup in external files included via theimgtag. Please be very careful if using an insecureSVGDrawerthat all SVG images are trusted.- Parameters:
svgImpl- the SVG implementation- Returns:
- this for method chaining
-
useMathMLDrawer
public final TFinalClass useMathMLDrawer(SVGDrawer mathMlImpl)
Use the specified MathML implementation.- Parameters:
mathMlImpl- the MathML implementation- Returns:
- this for method chaining
-
useReplacementText
public final TFinalClass useReplacementText(String replacement)
The replacement text to use if a character is cannot be renderered by any of the specified fonts. This is not broken across lines so should be one or zero characters for best results. Also, make sure it can be rendered by at least one of your specified fonts! The default is the # character.- Parameters:
replacement- the default replacement text- Returns:
- this for method chaining
-
useUnicodeLineBreaker
public final TFinalClass useUnicodeLineBreaker(FSTextBreaker breaker)
Specify the line breaker. By default a Java default BreakIterator line instance is used with US locale. Additionally, this is wrapped with UrlAwareLineBreakIterator to also break before the forward slash (/) character so that long URIs can be broken on to multiple lines. You may want to use a BreakIterator with a different locale (wrapped by UrlAwareLineBreakIterator or not) or a more advanced BreakIterator from icu4j (see the rtl-support module for an example).- Parameters:
breaker- the text breaker to use- Returns:
- this for method chaining
-
useUnicodeCharacterBreaker
public final TFinalClass useUnicodeCharacterBreaker(FSTextBreaker breaker)
Specify the character breaker. By default a break iterator character instance is used with US locale. Currently this is used whenword-wrap: break-wordis in effect.- Parameters:
breaker- the character breaker to use- Returns:
- this for method chaining
-
useUnicodeToUpperTransformer
public final TFinalClass useUnicodeToUpperTransformer(FSTextTransformer tr)
Specify a transformer to use to upper case strings. By defaultString::toUpperCase(Locale.US)is used.- Parameters:
tr- the text transformer to use- Returns:
- this for method chaining
-
useUnicodeToLowerTransformer
public final TFinalClass useUnicodeToLowerTransformer(FSTextTransformer tr)
Specify a transformer to use to lower case strings. By defaultString::toLowerCase(Locale.US)is used.- Parameters:
tr- the text transformer to use.- Returns:
- this for method chaining
-
useUnicodeToTitleTransformer
public final TFinalClass useUnicodeToTitleTransformer(FSTextTransformer tr)
Specify a transformer to title case strings. By default a best effort implementation (non locale aware) is used.- Parameters:
tr- the text transformer to use- Returns:
- this for method chaining
-
useDefaultPageSize
public final TFinalClass useDefaultPageSize(float pageWidth, float pageHeight, BaseRendererBuilder.PageSizeUnits units)
Specifies the default page size to use if none is specified in CSS.- Parameters:
pageWidth- the new default widthpageHeight- the new default heightunits- either mm or inches.- Returns:
- this for method chaining
- See Also:
PAGE_SIZE_LETTER_WIDTH,PAGE_SIZE_LETTER_HEIGHT,PAGE_SIZE_LETTER_UNITS
-
useObjectDrawerFactory
public final TFinalClass useObjectDrawerFactory(FSObjectDrawerFactory objectDrawerFactory)
Set a factory for <object> drawers- Parameters:
objectDrawerFactory- Object Drawer Factory- Returns:
- this for method chaining
-
useFastMode
public final TFinalClass useFastMode()
Use the new (May 2018) fast renderer if possible (only PDF at this point). This renderer can be 100s of times faster for very large documents. Please note that the fast renderer will be the only renderer at some future release so please at least test your code using the fast mode.- Returns:
- this for method chaining
-
-