Package io.keikai.axyra.sheets.io
Class Renderer
java.lang.Object
io.keikai.axyra.sheets.io.Renderer
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 Summary
Modifier and TypeMethodDescriptionstatic intThe number of printed pages a sheet paginates to.static byte[]toBmp(Workbook workbook, int sheetIndex, ImageOptions options) Renders one printed page of a sheet to BMP bytes.static byte[]toGif(Workbook workbook, int sheetIndex, ImageOptions options) Renders one printed page of a sheet to GIF bytes.static byte[]toImage(Workbook workbook, int sheetIndex, String format, ImageOptions options) Renders one printed page of a sheet (page 1, or the page set inoptions) toformat.static byte[]toImage(Workbook workbook, int sheetIndex, String rangeA1, String format, ImageOptions options) Renders an A1 range of a sheet toformat, with the format tokens oftoImage(io.keikai.axyra.sheets.Workbook, int, String, ImageOptions).static byte[]toJpeg(Workbook workbook, int sheetIndex, ImageOptions options) Renders one printed page of a sheet to JPEG bytes, composited over white.static byte[]toPdf(Workbook workbook, PdfOptions options) Renders the workbook to PDF bytes withoptions.static voidRenders every visible sheet to a PDF file, replacing an existing file.static voidtoPdf(Workbook workbook, Path file, PdfOptions options) Renders the workbook to a PDF file withoptions, replacing an existing file.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 inoptions.static byte[]toPng(Workbook workbook, int sheetIndex, String rangeA1, ImageOptions options) Renders an A1 range of a sheet to PNG bytes.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 withImageOptions.Builder.page(int).static byte[]toSvg(Workbook workbook, int sheetIndex, String rangeA1, ImageOptions options) Renders an A1 range of a sheet to SVG bytes (UTF-8).static byte[]toTiff(Workbook workbook, int sheetIndex, ImageOptions options) Renders one printed page of a sheet to TIFF bytes.
-
Method Details
-
toPdf
Renders every visible sheet to a PDF file, replacing an existing file. Same asworkbook.renderPdf(file).- Parameters:
workbook- the workbook to renderfile- the output file
-
toPdf
Renders the workbook to a PDF file withoptions, replacing an existing file. Same asworkbook.renderPdf(file, options).- Parameters:
workbook- the workbook to renderfile- the output fileoptions- the PDF options;nullmeans 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
Renders the workbook to PDF bytes withoptions. Same asworkbook.renderPdf(options).- Parameters:
workbook- the workbook to renderoptions- the PDF options;nullmeans 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
The number of printed pages a sheet paginates to. This is the valid range forImageOptions.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 workbooksheetIndex- 0-based sheet index- Returns:
- the page count, 0 for an empty sheet
-
toPng
Renders one printed page of a sheet to PNG bytes: page 1, or the page set inoptions.- Parameters:
workbook- the workbooksheetIndex- 0-based sheet indexoptions- the image options;nullmeans the defaults- Returns:
- the PNG file bytes
-
toPng
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 workbooksheetIndex- 0-based sheet indexrangeA1- the range, e.g."B2:F20"options- the image options;nullmeans the defaults- Returns:
- the PNG file bytes
-
toSvg
Renders one printed page of a sheet to SVG bytes (UTF-8): page 1, or the page set withImageOptions.Builder.page(int). The SVG is sized in points and draws text as glyph outlines.ImageOptions.scale()andImageOptions.targetWidthPx()do not apply.- Parameters:
workbook- the workbooksheetIndex- 0-based sheet indexoptions- the image options;nullmeans the defaults- Returns:
- the SVG document as UTF-8 bytes
-
toSvg
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 workbooksheetIndex- 0-based sheet indexrangeA1- the range, e.g."B2:F20"options- the image options;nullmeans 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 inoptions) toformat. 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 workbooksheetIndex- 0-based sheet indexformat- the format tokenoptions- the image options;nullmeans 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 toformat, with the format tokens oftoImage(io.keikai.axyra.sheets.Workbook, int, String, ImageOptions). The range replaces the sheet's print area for this call only.- Parameters:
workbook- the workbooksheetIndex- 0-based sheet indexrangeA1- the range, e.g."B2:F20"format- the format tokenoptions- the image options;nullmeans the defaults- Returns:
- the image file bytes
- Throws:
AxyraException- for an unknown format
-
toJpeg
Renders one printed page of a sheet to JPEG bytes, composited over white. Same astoImage(workbook, sheetIndex, "jpeg", options).- Parameters:
workbook- the workbooksheetIndex- 0-based sheet indexoptions- the image options;nullmeans the defaults- Returns:
- the JPEG file bytes
-
toGif
Renders one printed page of a sheet to GIF bytes. Same astoImage(workbook, sheetIndex, "gif", options).- Parameters:
workbook- the workbooksheetIndex- 0-based sheet indexoptions- the image options;nullmeans the defaults- Returns:
- the GIF file bytes
-
toBmp
Renders one printed page of a sheet to BMP bytes. Same astoImage(workbook, sheetIndex, "bmp", options).- Parameters:
workbook- the workbooksheetIndex- 0-based sheet indexoptions- the image options;nullmeans the defaults- Returns:
- the BMP file bytes
-
toTiff
Renders one printed page of a sheet to TIFF bytes. Same astoImage(workbook, sheetIndex, "tiff", options).- Parameters:
workbook- the workbooksheetIndex- 0-based sheet indexoptions- the image options;nullmeans the defaults- Returns:
- the TIFF file bytes
-