Export design blocks to binary ByteBuffer data for saving to disk, uploading to a server, sharing, or converting to platform images.
CE.SDK’s engine.block.export() method renders a page, scene, or individual design block into binary data. Android returns a ByteBuffer, so your app can write the result to app-controlled storage, upload it, share it, or decode image exports with Android platform APIs.
Export a Block to Binary Data#
Call engine.block.export(...) with the block ID and target MIME type. This example exports an existing page to PNG and checks that the returned ByteBuffer contains data.
suspend fun exportBlockToBinaryData( engine: Engine, page: DesignBlock,): ByteBuffer { val pngData = engine.block.export( block = page, mimeType = MimeType.PNG, )
check(pngData.hasRemaining()) { "PNG export is empty" } return pngData}Supported export MIME type constants include MimeType.PNG, MimeType.JPEG, MimeType.TGA, MimeType.SVG, MimeType.PDF, and MimeType.BINARY. Use engine.block.exportVideo(...) for MP4 video output.
Configure Export Options#
Pass ExportOptions when you need to control format-specific quality or output dimensions. This JPEG example uses jpegQuality = 0.8F and scales the rendered output to 1920 x 1080.
suspend fun exportWithOptions( engine: Engine, page: DesignBlock,): ByteBuffer { val options = ExportOptions( jpegQuality = 0.8F, targetWidth = 1920F, targetHeight = 1080F, ) val jpegData = engine.block.export( block = page, mimeType = MimeType.JPEG, options = options, )
check(jpegData.hasRemaining()) { "JPEG export is empty" } return jpegData}Format-specific options are ignored by other formats. For example, jpegQuality only affects JPEG exports, while targetWidth and targetHeight resize image output when both dimensions are set.
Export Multiple Blocks#
Use the batch overload when you need one binary export per page or block. The returned list follows the input order and the export reuses one worker engine for the batch.
suspend fun exportMultipleBlocks(engine: Engine): List<ByteBuffer> { val pages = engine.scene.getPages() val pngBuffers = engine.block.export( blocks = pages, mimeType = MimeType.PNG, )
check(pngBuffers.size == pages.size) pngBuffers.forEachIndexed { index, pngData -> check(pngData.hasRemaining()) { "PNG export ${index + 1} is empty" } } return pngBuffers}Save to Disk#
Use a duplicate or read-only view before writing a ByteBuffer if the same buffer is also needed for later validation, upload, or decoding.
suspend fun saveByteBufferToFile( buffer: ByteBuffer, outputFile: File,): File = withContext(Dispatchers.IO) { outputFile.parentFile?.mkdirs() val readableBuffer = buffer.asReadOnlyBuffer()
FileOutputStream(outputFile).channel.use { channel -> while (readableBuffer.hasRemaining()) { channel.write(readableBuffer) } }
check(outputFile.length() > 0L) { "Saved export is empty" } outputFile}The sample writes into an app-controlled File. Use the same binary data with your own upload or share pipeline when the exported file should leave local storage.
API Reference#
| API | Purpose |
|---|---|
engine.block.export(block=_, mimeType=_, options=_) | Export one block as a ByteBuffer |
engine.block.export(blocks=_, mimeType=_, options=_) | Export several blocks as a List<ByteBuffer> |
ExportOptions(jpegQuality=_, targetWidth=_, targetHeight=_) | Configure output quality and dimensions |
engine.scene.getPages() | Get pages for batch export examples |
Next Steps#
- Conversion Overview - See all supported export formats.