save method

Future<Uint8List> save({
  1. bool enableEventLoopBalancing = false,
  2. bool useIsolate = true,
})

Generates the PDF document as a memory buffer.

Runs in a background isolate when supported (e.g., on Dart VM), or on the main isolate when isolate support is unavailable (e.g., on the web).

If enableEventLoopBalancing is true, the method yields periodically during processing to keep the event loop responsive. This helps reduce blocking when the operation runs on the main isolate.

Returns a Uint8List containing the document data.

Implementation

Future<Uint8List> save({
  bool enableEventLoopBalancing = false,
  bool useIsolate = true,
}) async {
  final computation = () async {
    final os = PdfStream();
    if (prev != null) {
      os.putBytes(prev!.bytes);
    }
    await output(os, enableEventLoopBalancing: enableEventLoopBalancing);
    return os.output();
  };

  if (!useIsolate) {
    return computation();
  }

  return pdfCompute(computation);
}