Class BaseRendererBuilder<TFinalClass extends BaseRendererBuilder,TBaseRendererBuilderState extends BaseRendererBuilder.BaseRendererBuilderState>
public abstract class BaseRendererBuilder<TFinalClass extends BaseRendererBuilder,TBaseRendererBuilderState extends BaseRendererBuilder.BaseRendererBuilderState> extends Object
-
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.FSFontUseCaseUse cases for fonts.static 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.protected CloseableapplyDiagnosticConsumer()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.TFinalClassuseFont(FSSupplier<InputStream> supplier, String fontFamily)Simpler overload foruseFont(FSSupplier, String, Integer, FontStyle, boolean)TFinalClassuseFont(FSSupplier<InputStream> supplier, String fontFamily, Integer fontWeight, BaseRendererBuilder.FontStyle fontStyle, boolean subset)Add a font programmatically.TFinalClassuseFont(File fontFile, String fontFamily)Simpler overload foruseFont(File, String, Integer, FontStyle, boolean)TFinalClassuseFont(File fontFile, String fontFamily, Integer fontWeight, BaseRendererBuilder.FontStyle fontStyle, boolean subset)Allows the user to provide a font file for use by the main document only (not SVGs).TFinalClassuseFont(File fontFile, String fontFamily, Integer fontWeight, BaseRendererBuilder.FontStyle fontStyle, boolean subset, Set<BaseRendererBuilder.FSFontUseCase> fontUsedFor)Allows the user to provide a font file for use any or all of the use cases listed inBaseRendererBuilder.FSFontUseCasesuch as main document, SVGs, etc.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.TFinalClasswithDiagnosticConsumer(Consumer<Diagnostic> diagnosticConsumer)TFinalClasswithFile(File file)Provides a file to convert to PDF.TFinalClasswithHtmlContent(String html, String baseDocumentUri)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 Details
-
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
-
state
protected final TBaseRendererBuilderState extends BaseRendererBuilder.BaseRendererBuilderState state
-
-
Constructor Details
-
BaseRendererBuilder
-
-
Method Details
-
addDOMMutator
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
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
The default text direction of the document. LTR by default.- Parameters:
textDirection-- Returns:
- this for method chaining
-
testMode
Whether to use test mode and output the PDF uncompressed. Turned off by default.- Parameters:
mode-- Returns:
- this for method chaining
-
useHttpStreamImplementation
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
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
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
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
Provides a string containing XHTML/XML to convert to PDF. Note that baseDocumentUri can be null if there are no relative resources, otherwise should be a uri to a (possibly fake) document that is used to resolve relative resources. Examples:file:///Users/user/my-dummy-doc.html,file:/C:/Users/me/Desktop/dummy.html- Parameters:
html- the HTML text to use.baseDocumentUri- the base document URI to resolve future relative resources (e.g. images)- Returns:
- this for method chaining
-
withW3cDocument
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
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
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
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
Use the specified MathML implementation.- Parameters:
mathMlImpl- the MathML implementation- Returns:
- this for method chaining
-
useReplacementText
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
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
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
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
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
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
Set a factory for <object> drawers- Parameters:
objectDrawerFactory- Object Drawer Factory- Returns:
- this for method chaining
-
useFastMode
Use the new (May 2018) fast renderer. 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. Note: As of version 1.0.5 the fast renderer will be the default and this method is not required. To temporarily use the slow renderer (now only available for PDFs) calluseSlowMode.- Returns:
- this for method chaining
-
useFont
public TFinalClass useFont(File fontFile, String fontFamily, Integer fontWeight, BaseRendererBuilder.FontStyle fontStyle, boolean subset)Allows the user to provide a font file for use by the main document only (not SVGs). See:
useFont(File, String, Integer, FontStyle, boolean, Set)For gotchas related to font handling please see: Wiki: Fonts
-
useFont
public TFinalClass useFont(File fontFile, String fontFamily, Integer fontWeight, BaseRendererBuilder.FontStyle fontStyle, boolean subset, Set<BaseRendererBuilder.FSFontUseCase> fontUsedFor)Allows the user to provide a font file for use any or all of the use cases listed in
BaseRendererBuilder.FSFontUseCasesuch as main document, SVGs, etc.For gotchas related to font handling please see: Wiki: Fonts
- Parameters:
fontFile- A file system font file in true-type format. Beware of using resources as they will not be separate files in the final jar.fontFamily- Font family name. If using a font in Java2D, SVG or MathML this should matchFont.createFont(Font.TRUETYPE_FONT, fontFile).getFamily().fontWeight- Font boldness, usually 400 for regular fonts and 700 for bold fonts.fontStyle- Normal, italic or oblique.subset- For PDF use whether the font is subset, usually true unless the font is being used by form controls.fontUsedFor- Which components use the font such as main document, SVG, etc. Example:EnumSet.of(FSFontUseCase.DOCUMENT, FSFontUseCase.SVG)- Returns:
- this for method chaining
-
useFont
Simpler overload foruseFont(File, String, Integer, FontStyle, boolean)- Returns:
- this for method chaining
-
useFont
public TFinalClass useFont(FSSupplier<InputStream> supplier, String fontFamily, Integer fontWeight, BaseRendererBuilder.FontStyle fontStyle, boolean subset)Add a font programmatically. If the font is NOT subset, it will be downloaded when the renderer is run, otherwise, assuming a font-metrics cache has been configured, the font will only be downloaded if required. Therefore, the user could add many fonts, confident that only those that are needed will be downloaded and processed.
The InputStream returned by the supplier will be closed by the caller. Fonts should generally be subset (Java2D renderer ignores this argument), except when used in form controls. FSSupplier is a lambda compatible interface.
Fonts can also be added using a font-face at-rule in the CSS (not recommended for Java2D usage).
IMPORTANT: This method will add fonts for use by the main document only. It is not recommended for use with Java2D. To add fonts for use by Java2D, SVG, etc see:
useFont(File, String, Integer, FontStyle, boolean, Set)For gotchas related to font handling please see: Wiki: Fonts
- Returns:
- this for method chaining
-
useFont
Simpler overload foruseFont(FSSupplier, String, Integer, FontStyle, boolean)- Returns:
- this for method chaining
-
withDiagnosticConsumer
-
applyDiagnosticConsumer
-