Package com.openhtmltopdf.java2d.api
Class Java2DRendererBuilder
- java.lang.Object
-
- com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder<Java2DRendererBuilder,Java2DRendererBuilderState>
-
- com.openhtmltopdf.java2d.api.Java2DRendererBuilder
-
public class Java2DRendererBuilder extends com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder<Java2DRendererBuilder,Java2DRendererBuilderState>
Build a Java2D renderer for a given HTML. The renderer allows to get a BufferedImage of the HTML and to render it in components (using Graphics2D).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classJava2DRendererBuilder.Graphics2DPaintingReplacedElementThis class is internal to this library, please do not use or override it!-
Nested classes/interfaces inherited from class com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder
com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.BaseRendererBuilderState, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.PageSizeUnits, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.TextDirection
-
-
Constructor Summary
Constructors Constructor Description Java2DRendererBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Java2DRendererbuildJava2DRenderer()voidrunFirstPage()useLayoutGraphicsandtoPageProcessorMUST have been called.voidrunPaged()useLayoutGraphicsandtoPageProcessorMUST have been called.Java2DRendererBuildertoPageProcessor(FSPageProcessor pageProcessor)Output the document in paged format.Java2DRendererBuildertoSinglePage(FSPageProcessor pageProcessor)Render everything to a single page.Java2DRendererBuilderuseFont(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamily)Simpler overload foruseFont(FSSupplier, String, Integer, FontStyle)Java2DRendererBuilderuseFont(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamily, Integer fontWeight, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle fontStyle)Add a font programmatically.Java2DRendererBuilderuseInitialPageNumber(int pageNumberInitial)Used to set an initial page number for use with page counters, etc.Java2DRendererBuilderuseLayoutGraphics(Graphics2D g2d)Compulsory method.-
Methods inherited from class com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder
addDOMMutator, defaultTextDirection, testMode, useCache, useDefaultPageSize, useDocumentBuilderFactoryImplementationClass, useFastMode, useHttpStreamImplementation, useMathMLDrawer, useMultiThreadByteCache, useMultiThreadStringCache, useObjectDrawerFactory, useProtocolsStreamImplementation, useProtocolsStreamImplementation, useReplacementText, useSVGDrawer, useTransformerFactoryImplementationClass, useUnicodeBidiReorderer, useUnicodeBidiSplitter, useUnicodeCharacterBreaker, useUnicodeLineBreaker, useUnicodeToLowerTransformer, useUnicodeToTitleTransformer, useUnicodeToUpperTransformer, useUriResolver, withFile, withHtmlContent, withUri, withW3cDocument
-
-
-
-
Method Detail
-
useLayoutGraphics
public Java2DRendererBuilder useLayoutGraphics(Graphics2D g2d)
Compulsory method. The layout graphics are used to measure text and should be from an image or device with the same characteristics as the output graphicsw provided by the page processor.- Parameters:
g2d-- Returns:
- this for method chaining
-
useFont
public Java2DRendererBuilder useFont(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamily, Integer fontWeight, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.FontStyle fontStyle)
Add a font programmatically. The font will only be downloaded if needed. The InputStream returned by the supplier will be closed by the caller. FSSupplier is a lambda compatible interface. Fonts can also be added using a font-face at-rule in the CSS.- Parameters:
supplier-fontFamily-fontWeight-fontStyle-- Returns:
- this for method chaining
-
useFont
public Java2DRendererBuilder useFont(com.openhtmltopdf.extend.FSSupplier<InputStream> supplier, String fontFamily)
Simpler overload foruseFont(FSSupplier, String, Integer, FontStyle)- Parameters:
supplier-fontFamily-- Returns:
- this for method chaining
-
useInitialPageNumber
public Java2DRendererBuilder useInitialPageNumber(int pageNumberInitial)
Used to set an initial page number for use with page counters, etc.- Parameters:
pageNumberInitial-- Returns:
- this for method chaining
-
toSinglePage
public Java2DRendererBuilder toSinglePage(FSPageProcessor pageProcessor)
Render everything to a single page. I.e. only one big page is genereated, no pagebreak will be done. The page is only as height as needed.
-
toPageProcessor
public Java2DRendererBuilder toPageProcessor(FSPageProcessor pageProcessor)
Output the document in paged format. The user can use the DefaultPageProcessor or use its source as a reference to code their own page processor for advanced usage.- Parameters:
pageProcessor-- Returns:
- this for method chaining
-
runPaged
public void runPaged() throws ExceptionuseLayoutGraphicsandtoPageProcessorMUST have been called. Also a document MUST have been set with one of the with* methods. This will build the renderer and output each page of the document to the specified page processor.- Throws:
Exception
-
runFirstPage
public void runFirstPage() throws ExceptionuseLayoutGraphicsandtoPageProcessorMUST have been called. Also a document MUST have been set with one of the with* methods. This will build the renderer and output the first page of the document to the specified page processor.- Throws:
Exception
-
buildJava2DRenderer
public Java2DRenderer buildJava2DRenderer()
-
-