public abstract class BaseRendererBuilder<TFinalClass extends BaseRendererBuilder,TBaseRendererBuilderState extends BaseRendererBuilder.BaseRendererBuilderState> extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
BaseRendererBuilder.BaseRendererBuilderState
This class is an internal implementation detail.
This is internal, please don't use directly. |
static class |
BaseRendererBuilder.FontStyle |
static class |
BaseRendererBuilder.FSFontUseCase
Use cases for fonts.
|
static class |
BaseRendererBuilder.PageSizeUnits |
static class |
BaseRendererBuilder.TextDirection |
| Modifier and Type | Field and Description |
|---|---|
static float |
PAGE_SIZE_LETTER_HEIGHT |
static BaseRendererBuilder.PageSizeUnits |
PAGE_SIZE_LETTER_UNITS |
static float |
PAGE_SIZE_LETTER_WIDTH |
protected TBaseRendererBuilderState |
state |
| Modifier | Constructor and Description |
|---|---|
protected |
BaseRendererBuilder(TBaseRendererBuilderState state) |
| Modifier and Type | Method and Description |
|---|---|
TFinalClass |
addDOMMutator(FSDOMMutator domMutator)
Add a DOM mutator to this builder.
|
protected Closeable |
applyDiagnosticConsumer() |
TFinalClass |
defaultTextDirection(BaseRendererBuilder.TextDirection textDirection)
The default text direction of the document.
|
TFinalClass |
testMode(boolean mode)
Whether to use test mode and output the PDF uncompressed.
|
TFinalClass |
useDefaultPageSize(float pageWidth,
float pageHeight,
BaseRendererBuilder.PageSizeUnits units)
Specifies the default page size to use if none is specified in CSS.
|
TFinalClass |
useDocumentBuilderFactoryImplementationClass(String documentBuilderFactoryClass)
This method should be considered advanced and is not required for most
setups.
|
TFinalClass |
useExternalResourceAccessControl(BiPredicate<String,ExternalResourceType> allowExternalResource,
ExternalResourceControlPriority priority)
Allows to set one external access controller to run
before the uri resolver and one to run after the uri resolver.
|
TFinalClass |
useFastMode()
Use the new (May 2018) fast renderer.
|
TFinalClass |
useFont(File fontFile,
String fontFamily)
Simpler overload for
useFont(File, String, Integer, FontStyle, boolean) |
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).
|
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.FSFontUseCase such as main
document, SVGs, etc. |
TFinalClass |
useFont(FSSupplier<InputStream> supplier,
String fontFamily)
Simpler overload for
useFont(FSSupplier, String, Integer, FontStyle, boolean) |
TFinalClass |
useFont(FSSupplier<InputStream> supplier,
String fontFamily,
Integer fontWeight,
BaseRendererBuilder.FontStyle fontStyle,
boolean subset)
Add a font programmatically.
|
TFinalClass |
useFont(FSSupplier<InputStream> supplier,
String fontFamily,
Integer fontWeight,
BaseRendererBuilder.FontStyle fontStyle,
boolean subset,
Set<BaseRendererBuilder.FSFontUseCase> useFontFlags)
Add a font programmatically.
|
TFinalClass |
useHttpStreamImplementation(FSStreamFactory factory)
Provides an HttpStreamFactory implementation if the user desires to use an
external HTTP/HTTPS implementation.
|
TFinalClass |
useInitialPageNumber(int initialPageNumber)
Allows the setting of the initial page number to use with the
page and pages CSS counters. |
TFinalClass |
useMathMLDrawer(SVGDrawer mathMlImpl)
Use the specified MathML implementation.
|
TFinalClass |
useObjectDrawerFactory(FSObjectDrawerFactory objectDrawerFactory)
Set a factory for <object> drawers
|
TFinalClass |
useProtocolsStreamImplementation(FSStreamFactory factory,
Set<String> protocols)
Provides an
FSStreamFactory
implementation if the user desires to use an external
stream provider for a particular set of protocols. |
TFinalClass |
useProtocolsStreamImplementation(FSStreamFactory factory,
String... protocols)
Provides an
FSStreamFactory
implementation if the user desires to use an external
stream provider for a particular list of protocols. |
TFinalClass |
useReplacementText(String replacement)
The replacement text to use if a character is cannot be renderered by any of
the specified fonts.
|
TFinalClass |
useSVGDrawer(SVGDrawer svgImpl)
Uses the specified SVG drawer implementation.
|
TFinalClass |
useTransformerFactoryImplementationClass(String transformerFactoryClass)
This method should be considered advanced and is not required for most
setups.
|
TFinalClass |
useUnicodeBidiReorderer(BidiReorderer reorderer)
Provides a reorderer to properly reverse RTL text.
|
TFinalClass |
useUnicodeBidiSplitter(BidiSplitterFactory splitter)
Provides a text splitter to split text into directional runs.
|
TFinalClass |
useUnicodeCharacterBreaker(FSTextBreaker breaker)
Specify the character breaker.
|
TFinalClass |
useUnicodeLineBreaker(FSTextBreaker breaker)
Specify the line breaker.
|
TFinalClass |
useUnicodeToLowerTransformer(FSTextTransformer tr)
Specify a transformer to use to lower case strings.
|
TFinalClass |
useUnicodeToTitleTransformer(FSTextTransformer tr)
Specify a transformer to title case strings.
|
TFinalClass |
useUnicodeToUpperTransformer(FSTextTransformer tr)
Specify a transformer to use to upper case strings.
|
TFinalClass |
useUriResolver(FSUriResolver resolver)
Provides a uri resolver to resolve relative uris or private uri schemes.
|
TFinalClass |
withDiagnosticConsumer(Consumer<Diagnostic> diagnosticConsumer) |
TFinalClass |
withFile(File file)
Provides a file to convert to PDF.
|
TFinalClass |
withHtmlContent(String html,
String baseDocumentUri)
Provides a string containing XHTML/XML to convert to PDF.
|
TFinalClass |
withUri(String uri)
Provides a URI to convert to PDF.
|
TFinalClass |
withW3cDocument(Document doc,
String baseUri)
Provides a w3c DOM Document acquired from an external source.
|
public static final float PAGE_SIZE_LETTER_WIDTH
public static final float PAGE_SIZE_LETTER_HEIGHT
public static final BaseRendererBuilder.PageSizeUnits PAGE_SIZE_LETTER_UNITS
protected final TBaseRendererBuilderState extends BaseRendererBuilder.BaseRendererBuilderState state
protected BaseRendererBuilder(TBaseRendererBuilderState state)
public TFinalClass addDOMMutator(FSDOMMutator domMutator)
domMutator - the DOM Mutatorpublic final TFinalClass useTransformerFactoryImplementationClass(String transformerFactoryClass)
transformerFactoryClass - public final TFinalClass useDocumentBuilderFactoryImplementationClass(String documentBuilderFactoryClass)
documentBuilderFactoryClass - public final TFinalClass defaultTextDirection(BaseRendererBuilder.TextDirection textDirection)
textDirection - public final TFinalClass testMode(boolean mode)
mode - public final TFinalClass useHttpStreamImplementation(FSStreamFactory factory)
factory - the factory to use for HTTP/HTTPSuseProtocolsStreamImplementation(FSStreamFactory, String[])public final TFinalClass useProtocolsStreamImplementation(FSStreamFactory factory, Set<String> protocols)
FSStreamFactory
implementation 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.factory - the stream factory to useprotocols - the list of protocols the factory should be used foruseHttpStreamImplementation(FSStreamFactory),
useProtocolsStreamImplementation(FSStreamFactory, String[])public final TFinalClass useProtocolsStreamImplementation(FSStreamFactory factory, String... protocols)
FSStreamFactory
implementation 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.factory - the stream factory to useprotocols - the list of protocols the stream factory should be used foruseHttpStreamImplementation(FSStreamFactory),
useProtocolsStreamImplementation(FSStreamFactory, Set)public final TFinalClass useUriResolver(FSUriResolver resolver)
resolver - the URI resolver used to resolve any kind of private URIs/protocollspublic final TFinalClass useUnicodeBidiSplitter(BidiSplitterFactory splitter)
splitter - the unicode bidi splitter to use.public final TFinalClass useUnicodeBidiReorderer(BidiReorderer reorderer)
reorderer - the unicode bidi reorderer to use.public final TFinalClass withHtmlContent(String html, String baseDocumentUri)
file:///Users/user/my-dummy-doc.html,
file:/C:/Users/me/Desktop/dummy.htmlhtml - the HTML text to use.baseDocumentUri - the base document URI to resolve future relative resources (e.g. images)public final TFinalClass withW3cDocument(Document doc, String baseUri)
doc - the DOM of the HTML documentbaseUri - the base URI, it will be used to resolve future resources (images, etc.public final TFinalClass withUri(String uri)
uri - the URI of the HTML source to convert.public final TFinalClass withFile(File file)
file - the file with the HTML source to convertpublic final TFinalClass useSVGDrawer(SVGDrawer svgImpl)
img tag. Please be very careful if using an insecure
SVGDrawer that all SVG images are trusted.svgImpl - the SVG implementationpublic final TFinalClass useMathMLDrawer(SVGDrawer mathMlImpl)
mathMlImpl - the MathML implementationpublic final TFinalClass useReplacementText(String replacement)
replacement - the default replacement textpublic final TFinalClass useUnicodeLineBreaker(FSTextBreaker breaker)
breaker - the text breaker to usepublic final TFinalClass useUnicodeCharacterBreaker(FSTextBreaker breaker)
word-wrap: break-word is in effect.breaker - the character breaker to usepublic final TFinalClass useUnicodeToUpperTransformer(FSTextTransformer tr)
String::toUpperCase(Locale.US) is used.tr - the text transformer to usepublic final TFinalClass useUnicodeToLowerTransformer(FSTextTransformer tr)
String::toLowerCase(Locale.US) is used.tr - the text transformer to use.public final TFinalClass useUnicodeToTitleTransformer(FSTextTransformer tr)
tr - the text transformer to usepublic final TFinalClass useDefaultPageSize(float pageWidth, float pageHeight, BaseRendererBuilder.PageSizeUnits units)
pageWidth - the new default widthpageHeight - the new default heightunits - either mm or inches.PAGE_SIZE_LETTER_WIDTH,
PAGE_SIZE_LETTER_HEIGHT,
PAGE_SIZE_LETTER_UNITSpublic final TFinalClass useObjectDrawerFactory(FSObjectDrawerFactory objectDrawerFactory)
objectDrawerFactory - Object Drawer Factorypublic final TFinalClass useFastMode()
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
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.FSFontUseCase such as main
document, SVGs, etc.
For gotchas related to font handling please see: Wiki: Fonts
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 match
Font.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)public TFinalClass useFont(File fontFile, String fontFamily)
useFont(File, String, Integer, FontStyle, boolean)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
public TFinalClass useFont(FSSupplier<InputStream> supplier, String fontFamily, Integer fontWeight, BaseRendererBuilder.FontStyle fontStyle, boolean subset, Set<BaseRendererBuilder.FSFontUseCase> useFontFlags)
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 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
public TFinalClass useFont(FSSupplier<InputStream> supplier, String fontFamily)
useFont(FSSupplier, String, Integer, FontStyle, boolean)public TFinalClass withDiagnosticConsumer(Consumer<Diagnostic> diagnosticConsumer)
protected Closeable applyDiagnosticConsumer()
public TFinalClass useExternalResourceAccessControl(BiPredicate<String,ExternalResourceType> allowExternalResource, ExternalResourceControlPriority priority)
public TFinalClass useInitialPageNumber(int initialPageNumber)
page and pages CSS counters.
Useful when appending to an existing document.
Must be one or greater.Copyright © 2004–2025. All rights reserved.