Skip to content

Options

Exporting via the block.export endpoint allows fine-grained control of the target format. CE.SDK currently supports exporting scenes, pages, groups, or individual blocks in the MP4, PNG, TGA, JPEG, WEBP, BINARY and PDF formats. To specify the desired type, just pass in the corresponding mimeType. Pass additional options in a mime-type specific object:

FormatMimeTypeOptions (Default)
PNGimage/pngpngCompressionLevel (5) - The compression level is a trade-off between file size and encoding/decoding speed, but doesn’t affect quality. Valid values are [0-9] ranging from no to maximum compression.
JPEGimage/jpegjpegQuality (0.9) - Directly influences the resulting files visual quality. Smaller = worse quality, but lower file size. Valid values are (0-1]
WEBPimage/webpwebpQuality (1.0) - Controls the desired output quality. 1.0 results in a special lossless encoding that usually produces smaller file sizes than PNG. Valid values are (0-1], higher means better quality.
BINARYapplication/octet-streamNo additional options. This type returns the raw image data in RGBA8888 order in a blob.
PDFapplication/pdfexportPdfWithHighCompatibility (true) - Increase compatibility with different PDF viewers. Images and effects will be rasterized with regard to the scene’s DPI value instead of simply being embedded.
PDFapplication/pdfexportPdfWithUnderlayer (false) - An underlayer is generated by adding a graphics block behind the existing elements of the shape of the elements on the page.
PDFapplication/pdfunderlayerSpotColorName ("") - The name of the spot color to be used for the underlayer’s fill.
PDFapplication/pdfunderlayerOffset (0.0) - The adjustment in size of the shape of the underlayer.

Certain formats allow additional configuration, e.g. options.jpegQuality controls the output quality level when exporting to JPEG. These format-specific options are ignored when exporting to other formats. You can choose which part of the scene to export by passing in the respective block as the first parameter.

For all formats, an optional targetWidth and targetHeight in pixels can be specified. If used, the block will be rendered large enough, that it fills the target size entirely while maintaining its aspect ratio. The supported export size limit can be queried with editor.getMaxExportSize(), the width and height should not exceed this value.

Export details:

  • Exporting automatically performs an internal update to resolve the final layout for all blocks.
  • Only blocks that belong to the scene hierarchy can be exported.
  • The export will include the block and all child elements in the block hierarchy.
  • If the exported block itself is rotated it will be exported without rotation.
  • If a margin is set on the block it will be included.
  • If an outside stroke is set on the block it will be included except for pages.
  • Exporting a scene with more than one page may result in transparent areas between the pages, it is recommended to export the individual pages instead.
  • Exporting as JPEG drops any transparency on the final image and may lead to unexpected results.

Export a Static Design

suspend fun export(
block: DesignBlock,
mimeType: MimeType,
options: ExportOptions? = null,
onPreExport: suspend Engine.() -> Unit = {},
): ByteBuffer

Exports a design block element as a file of the given mime type.

Performs an internal update to resolve the final layout for the blocks.

Note: The export happens in a background thread and the Engine instance in the onPreExport lambda is a separate instance and is alive until the suspending function resumes. Use this lambda to configure the background engine for export.

  • block: the design block element to export.

  • mimeType: the mime type of the output file.

  • options: the options for exporting the block type

  • onPreExport: the lambda to configure the engine before export. This lambda is called on a background thread, and the Engine parameter of this lambda is a separate engine instance running in that background thread.

  • Returns the exported data.

Export with a Color Mask

suspend fun exportWithColorMask(
block: DesignBlock,
mimeType: MimeType,
maskColor: RGBAColor,
options: ExportOptions? = null,
onPreExport: suspend Engine.() -> Unit = {},
): Pair<ByteBuffer, ByteBuffer>

Exports a design block element as a file of the given mime type.

Performs an internal update to resolve the final layout for the blocks.

Note: The export happens in a background thread and the Engine instance in the onPreExport lambda is a separate instance and is alive until the suspending function resumes. Use this lambda to configure the background engine for export.

  • block: the design block element to export.

  • mimeType: the mime type of the output file.

  • maskColor: the mask color.

  • options: the options for exporting the block type

  • onPreExport: the lambda to configure the engine before export. This lambda is called on a background thread, and the Engine parameter of this lambda is a separate engine instance running in that background thread.

  • Returns a pair where first is the exported image data and second is the mask data.

Export a Video

Export a page as a video file of the given mime type.

suspend fun exportVideo(
block: DesignBlock,
timeOffset: Double,
duration: Double,
mimeType: MimeType,
progressCallback: (ExportVideoProgress) -> Unit,
options: ExportVideoOptions? = null,
onPreExport: suspend Engine.() -> Unit = {},
): ByteBuffer

Exports a design block as a video file of the given mime type.

Note: The export will run across multiple iterations of the update loop. In each iteration a frame is scheduled for encoding.

Note: The export happens in a background thread and the Engine instance in the onPreExport lambda is a separate instance and is alive until the suspending function resumes. Use this lambda to configure the background engine for export.

  • block: the design block to export. Currently, only page blocks are supported.

  • timeOffset: the time offset in seconds of the page’s timeline from which the video will start.

  • duration: the duration in seconds of the final video.

  • mimeType: the mime type of the output video file.

  • progressCallback: a callback that reports on the progress of the export. It informs the receiver of the number of frames rendered by the engine, the number of encoded frames, and the total number of frames to encode.

  • options: the options used for the export of the block.

  • onPreExport: the lambda to configure the engine before export. This lambda is called on a background thread, and the Engine parameter of this lambda is a separate engine instance running in that background thread.

  • Returns the exported video as a file in filesDir. Note that you are responsible for deleting the file after it is used.

  • Returns the exported data.

Export Information

Before exporting, the maximum export size and available memory can be queried.

fun getMaxExportSize(): Int

Get the export size limit in pixels on the current device. An export is only possible when both the width and height of the output are below or equal this limit.

However, this is only an upper limit as the export might also not be possible due to other reasons, e.g., memory constraints.

  • Returns the upper export size limit in pixels or an unlimited size, i.e, the maximum signed 32-bit integer value, if the limit is unknown.
fun getAvailableMemory(): Long

Get the currently available memory in bytes.

  • Returns the currently available memory in bytes.