openCosDocumentFromSourceWithStatus function

Future<CosSourceOpenResult> openCosDocumentFromSourceWithStatus(
  1. PdfByteSource source, {
  2. String password = '',
  3. PdfSourceLoadOptions options = const PdfSourceLoadOptions(),
})

Opens source like openCosDocumentFromSource and reports whether the returned document is an intentionally limited first-paint buffer.

Implementation

Future<CosSourceOpenResult> openCosDocumentFromSourceWithStatus(
  PdfByteSource source, {
  String password = '',
  PdfSourceLoadOptions options = const PdfSourceLoadOptions(),
}) async {
  late final Uint8List buffer;
  var isFirstPaintBuffer = false;
  final t0 = PdfPerf.begin();
  try {
    final loaded = await _ProgressiveLoader(source, options).load();
    buffer = loaded.bytes;
    isFirstPaintBuffer = loaded.isFirstPaintBuffer;
  } on _FallbackToFullDownload {
    PdfPerf.add(PdfPerfCount.fullDownloadFallback);
    PdfPerf.event(PdfPerfEvent.rangedSourceFellBack);
    buffer = await _downloadFully(source, options);
  }
  PdfPerf.end(PdfPerfPhase.sourceFetch, t0);
  return CosSourceOpenResult(
    CosDocument.open(buffer, password: password),
    isFirstPaintBuffer: isFirstPaintBuffer,
  );
}