pdfEncodePageText function

Uint8List pdfEncodePageText(
  1. PdfPageText page
)

Serializes page into a compact binary blob for the on-disk text cache. The format is little-endian and self-describing enough to reject foreign/old bytes (pdfDecodePageText returns null on any mismatch). No external dependency - just dart:typed_data.

Implementation

Uint8List pdfEncodePageText(PdfPageText page) {
  final out = _Writer();
  out.u32(_textBlobMagic);
  out.i32(page.pageIndex);
  out.str(page.text);
  out.u32(page.runs.length);
  for (final run in page.runs) {
    out.str(run.text);
    out.i32(run.startIndex);
    out.u8(run.isRightToLeft ? 1 : 0);
    final t = run.transform;
    out
      ..f64(t.a)
      ..f64(t.b)
      ..f64(t.c)
      ..f64(t.d)
      ..f64(t.e)
      ..f64(t.f);
    out.f64(run.width);
    final b = run.bounds;
    out
      ..f64(b.left)
      ..f64(b.bottom)
      ..f64(b.right)
      ..f64(b.top);
  }
  return out.takeBytes();
}