saveAsBytes method
Asynchronously saves the document and return the saved bytes as Uint8List.
//Create a PDF document instance.
PdfDocument document = PdfDocument();
//Get the page and draw text.
document.pages.add().graphics.drawString(
'Hello World!', PdfStandardFont(PdfFontFamily.helvetica, 12),
brush: PdfBrushes.black, bounds: Rect.fromLTWH(0, 0, 0, 0));
//Save and dispose document.
Uint8List bytes = await document.saveAsBytes();
document.dispose();
Implementation
Future<Uint8List> saveAsBytes() async {
final PdfBytesBuilder buffer = PdfBytesBuilder();
final PdfWriter writer = PdfWriter(null, buffer);
await _saveDocumentAsync(writer);
final Uint8List bytes = buffer.takeBytes();
buffer.clear();
return bytes;
}