Export design blocks to binary Data (aliased as Blob) for saving to disk, uploading to a server, or converting to platform images.
CE.SDK’s engine.block.export() method renders any design block — a page, scene, or individual graphic block — into a Blob. In Swift, Blob is a typealias for Data, so the result integrates directly with Foundation APIs like FileManager, URLSession, and UIImage(data:).
Export a Block to PNG#
Call engine.block.export(_:mimeType:) with a block ID and the desired format. The method returns a Blob containing the rendered output.
let pngBlob: Blob = try await engine.block.export(page, mimeType: .png)Supported image MIME types include .png, .jpeg, .webp, .tga, and .pdf.
Configure Export Options#
Pass an ExportOptions instance to control quality and dimensions. Options vary by format:
| Option | Formats | Default | Description |
|---|---|---|---|
pngCompressionLevel | PNG | 5 | 0-9, higher = smaller file, same quality |
jpegQuality | JPEG | 0.9 | 0-1, higher = better quality |
webpQuality | WebP | 1.0 | 0-1, higher = better quality |
targetWidth / targetHeight | All image | 0 | Scale to fill target size, keeping aspect ratio |
let options = ExportOptions( jpegQuality: 0.8, targetWidth: 1920, targetHeight: 1080,)let jpegBlob = try await engine.block.export(page, mimeType: .jpeg, options: options)When both targetWidth and targetHeight are set, the block scales to fill the target rectangle while preserving its aspect ratio.
Export Multiple Blocks#
To export several blocks efficiently, pass an array of IDs. The method returns an AsyncThrowingStream<Blob, Error> that yields one blob per block in order, reusing a single background engine for all exports.
let pages = try engine.scene.getPages()let stream = try await engine.block.export(pages, mimeType: .png)var blobs: [Blob] = []for try await blob in stream { blobs.append(blob)}This is more memory-efficient than calling export in a loop because instead of creating an internal worker engine instance for each export only a single instance is created once and reused across all blocks.
Save to Disk#
Since Blob is Data, write it directly to a file URL with Foundation’s write(to:).
let tempURL = FileManager.default.temporaryDirectory.appendingPathComponent("export.png")try pngBlob.write(to: tempURL)You can also pass the blob to URLSession for uploading, or initialize a UIImage(data:) / NSImage(data:) for display.
Next Steps#
- To PDF — Export scenes as single- or multi-page PDFs with print options.
- Conversion Overview — See all supported export formats.