Class Renderer

java.lang.Object
io.keikai.axyra.sheets.io.Renderer

public final class Renderer extends Object
Renders workbooks to fixed-layout output: PDF documents, and sheet or range images in PNG, JPEG, GIF, BMP, TIFF or SVG. Each method is a static shortcut for the matching Workbook.render* method and throws what that method throws.

PDF export honors each sheet's page setup. PdfOptions adds a page range, a sheet subset, a fit-to-page override, encryption, a watermark, bookmarks, PDF/A and extra font directories.

Image export renders one printed page of a sheet: page 1, or the page chosen with ImageOptions.Builder.page(int). pageCount(io.keikai.axyra.sheets.Workbook, int) gives the number of pages. ImageOptions also sets the raster scale and the gridlines. The range overloads replace the sheet's print area with an A1 rectangle such as "B2:F20". Every method takes a 0-based sheet index.


 byte[] png = Renderer.toPng(workbook, 0,
         ImageOptions.builder().scale(2.0).build());
 Renderer.toPdf(workbook, Path.of("out.pdf"),
         PdfOptions.builder().sheets(0, 2).fitTo(PdfOptions.Fit.WIDTH).build());
 
  • Method Details

    • toPdf

      public static void toPdf(Workbook workbook, Path file)
      Renders every visible sheet to a PDF file, replacing an existing file. Same as workbook.renderPdf(file).
      Parameters:
      workbook - the workbook to render
      file - the output file
    • toPdf

      public static void toPdf(Workbook workbook, Path file, PdfOptions options)
      Renders the workbook to a PDF file with options, replacing an existing file. Same as workbook.renderPdf(file, options).
      Parameters:
      workbook - the workbook to render
      file - the output file
      options - the PDF options; null means the defaults
      Throws:
      AxyraException - if an option is invalid, e.g. a malformed page range, an unknown sheet, or PDF/A combined with a password
    • toPdf

      public static byte[] toPdf(Workbook workbook, PdfOptions options)
      Renders the workbook to PDF bytes with options. Same as workbook.renderPdf(options).
      Parameters:
      workbook - the workbook to render
      options - the PDF options; null means the defaults
      Returns:
      a new array holding the whole PDF
      Throws:
      AxyraException - if an option is invalid, e.g. a malformed page range, an unknown sheet, or PDF/A combined with a password
    • pageCount

      public static int pageCount(Workbook workbook, int sheetIndex)
      The number of printed pages a sheet paginates to. This is the valid range for ImageOptions.Builder.page(int) and matches the page numbering of the PDF export. An empty sheet reports 0, yet its image export still returns one blank page.
      Parameters:
      workbook - the workbook
      sheetIndex - 0-based sheet index
      Returns:
      the page count, 0 for an empty sheet
    • toPng

      public static byte[] toPng(Workbook workbook, int sheetIndex, ImageOptions options)
      Renders one printed page of a sheet to PNG bytes: page 1, or the page set in options.
      Parameters:
      workbook - the workbook
      sheetIndex - 0-based sheet index
      options - the image options; null means the defaults
      Returns:
      the PNG file bytes
    • toPng

      public static byte[] toPng(Workbook workbook, int sheetIndex, String rangeA1, ImageOptions options)
      Renders an A1 range of a sheet to PNG bytes. The range replaces the sheet's print area for this call only.
      Parameters:
      workbook - the workbook
      sheetIndex - 0-based sheet index
      rangeA1 - the range, e.g. "B2:F20"
      options - the image options; null means the defaults
      Returns:
      the PNG file bytes
    • toSvg

      public static byte[] toSvg(Workbook workbook, int sheetIndex, ImageOptions options)
      Renders one printed page of a sheet to SVG bytes (UTF-8): page 1, or the page set with ImageOptions.Builder.page(int). The SVG is sized in points and draws text as glyph outlines. ImageOptions.scale() and ImageOptions.targetWidthPx() do not apply.
      Parameters:
      workbook - the workbook
      sheetIndex - 0-based sheet index
      options - the image options; null means the defaults
      Returns:
      the SVG document as UTF-8 bytes
    • toSvg

      public static byte[] toSvg(Workbook workbook, int sheetIndex, String rangeA1, ImageOptions options)
      Renders an A1 range of a sheet to SVG bytes (UTF-8). The range replaces the sheet's print area for this call only. The scale and target width do not apply.
      Parameters:
      workbook - the workbook
      sheetIndex - 0-based sheet index
      rangeA1 - the range, e.g. "B2:F20"
      options - the image options; null means the defaults
      Returns:
      the SVG document as UTF-8 bytes
    • toImage

      public static byte[] toImage(Workbook workbook, int sheetIndex, String format, ImageOptions options)
      Renders one printed page of a sheet (page 1, or the page set in options) to format. Raster formats are "png", "jpeg" or "jpg", "gif", "bmp", and "tiff" or "tif", in any case. "svg" must be lower case. JPEG is opaque, so the page is composited over white.
      Parameters:
      workbook - the workbook
      sheetIndex - 0-based sheet index
      format - the format token
      options - the image options; null means the defaults
      Returns:
      the image file bytes
      Throws:
      AxyraException - for any other format
    • toImage

      public static byte[] toImage(Workbook workbook, int sheetIndex, String rangeA1, String format, ImageOptions options)
      Renders an A1 range of a sheet to format, with the format tokens of toImage(io.keikai.axyra.sheets.Workbook, int, String, ImageOptions). The range replaces the sheet's print area for this call only.
      Parameters:
      workbook - the workbook
      sheetIndex - 0-based sheet index
      rangeA1 - the range, e.g. "B2:F20"
      format - the format token
      options - the image options; null means the defaults
      Returns:
      the image file bytes
      Throws:
      AxyraException - for an unknown format
    • toJpeg

      public static byte[] toJpeg(Workbook workbook, int sheetIndex, ImageOptions options)
      Renders one printed page of a sheet to JPEG bytes, composited over white. Same as toImage(workbook, sheetIndex, "jpeg", options).
      Parameters:
      workbook - the workbook
      sheetIndex - 0-based sheet index
      options - the image options; null means the defaults
      Returns:
      the JPEG file bytes
    • toGif

      public static byte[] toGif(Workbook workbook, int sheetIndex, ImageOptions options)
      Renders one printed page of a sheet to GIF bytes. Same as toImage(workbook, sheetIndex, "gif", options).
      Parameters:
      workbook - the workbook
      sheetIndex - 0-based sheet index
      options - the image options; null means the defaults
      Returns:
      the GIF file bytes
    • toBmp

      public static byte[] toBmp(Workbook workbook, int sheetIndex, ImageOptions options)
      Renders one printed page of a sheet to BMP bytes. Same as toImage(workbook, sheetIndex, "bmp", options).
      Parameters:
      workbook - the workbook
      sheetIndex - 0-based sheet index
      options - the image options; null means the defaults
      Returns:
      the BMP file bytes
    • toTiff

      public static byte[] toTiff(Workbook workbook, int sheetIndex, ImageOptions options)
      Renders one printed page of a sheet to TIFF bytes. Same as toImage(workbook, sheetIndex, "tiff", options).
      Parameters:
      workbook - the workbook
      sheetIndex - 0-based sheet index
      options - the image options; null means the defaults
      Returns:
      the TIFF file bytes