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 class  Java2DRendererBuilder.Graphics2DPaintingReplacedElement
    This 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.FSFontUseCase, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.PageSizeUnits, com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder.TextDirection
  • Field Summary

    Fields inherited from class com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder

    PAGE_SIZE_LETTER_HEIGHT, PAGE_SIZE_LETTER_UNITS, PAGE_SIZE_LETTER_WIDTH, state
  • Constructor Summary

    Constructors
    Constructor Description
    Java2DRendererBuilder()  
  • Method Summary

    Modifier and Type Method Description
    Java2DRenderer buildJava2DRenderer()  
    Java2DRenderer buildJava2DRenderer​(Closeable diagnosticConsumer)  
    void runFirstPage()
    useLayoutGraphics and toPageProcessor MUST have been called.
    void runPaged()
    useLayoutGraphics and toPageProcessor MUST have been called.
    Java2DRendererBuilder toPageProcessor​(FSPageProcessor pageProcessor)
    Output the document in paged format.
    Java2DRendererBuilder toSinglePage​(FSPageProcessor pageProcessor)
    Render everything to a single page.
    Java2DRendererBuilder useEnvironmentFonts​(boolean useEnvironmentFonts)
    Whether to use fonts available in the environment.
    Java2DRendererBuilder useInitialPageNumber​(int pageNumberInitial)
    Used to set an initial page number for use with page counters, etc.
    Java2DRendererBuilder useLayoutGraphics​(Graphics2D g2d)
    Compulsory method.

    Methods inherited from class com.openhtmltopdf.outputdevice.helper.BaseRendererBuilder

    addDOMMutator, applyDiagnosticConsumer, defaultTextDirection, testMode, useDefaultPageSize, useDocumentBuilderFactoryImplementationClass, useFastMode, useFont, useFont, useFont, useFont, useFont, useHttpStreamImplementation, useMathMLDrawer, useObjectDrawerFactory, useProtocolsStreamImplementation, useProtocolsStreamImplementation, useReplacementText, useSVGDrawer, useTransformerFactoryImplementationClass, useUnicodeBidiReorderer, useUnicodeBidiSplitter, useUnicodeCharacterBreaker, useUnicodeLineBreaker, useUnicodeToLowerTransformer, useUnicodeToTitleTransformer, useUnicodeToUpperTransformer, useUriResolver, withDiagnosticConsumer, withFile, withHtmlContent, withUri, withW3cDocument

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Java2DRendererBuilder

      public Java2DRendererBuilder()
  • Method Details

    • 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
    • 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
    • useEnvironmentFonts

      public Java2DRendererBuilder useEnvironmentFonts​(boolean useEnvironmentFonts)
      Whether to use fonts available in the environment. Enabling environment fonts may mean different text rendering behavior across different environments. The default is not to use environment fonts.
    • 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 Exception
      useLayoutGraphics and toPageProcessor MUST 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 Exception
      useLayoutGraphics and toPageProcessor MUST 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()
    • buildJava2DRenderer

      public Java2DRenderer buildJava2DRenderer​(Closeable diagnosticConsumer)