exportToPdf method
Implementation
Future<Uint8List> exportToPdf() async {
final fontFamilies = _collectFontFamilies(document.content.nodes);
// Initialize TTF fonts (with document-specific families) and pre-fetch images in parallel
await Future.wait([
_fontProvider.init(fontFamilies),
_prefetchImages(),
]);
final pdf = pw.Document();
final root = document.content;
final usedAnnotYs = <dynamic, List<double>>{};
pdf.addPage(
pw.MultiPage(
pageFormat: PdfPageFormat.a4,
build: (context) => _buildPdfNodes(root.nodes, 0, usedAnnotYs: usedAnnotYs),
),
);
// Sticky-note annotations are added dynamically during paint by
// _CommentAnnotWidget placed inline at the start of each commented range.
return await pdf.save();
}