Class 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.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 Detail

      • Java2DRendererBuilder

        public Java2DRendererBuilder()
    • 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
      • 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 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