findContentsRange static method

_ContentsRange findContentsRange(
  1. Uint8List pdfBytes, {
  2. bool strict = true,
})

Finds the /Contents hex string range in pdfBytes.

Implementation

static _ContentsRange findContentsRange(
  Uint8List pdfBytes, {
  bool strict = true,
}) {
  if (useInternalContentsParser) {
    return _findContentsRangeInternal(pdfBytes);
  }

  if (useFastContentsParser) {
    try {
      final range = _findContentsRangeFast(pdfBytes);
      if ((strict && _isValidContentsRange(pdfBytes, range)) ||
          (!strict && _isPlausibleRange(pdfBytes, range))) {
        return range;
      }
    } catch (e) {
      if (e is StateError && e.message == 'ByteRange not found') {
        throw e;
      }
    }
  }

  try {
    final range = _findContentsRangeStringSearch(pdfBytes);
    if ((strict && _isValidContentsRange(pdfBytes, range)) ||
        (!strict && _isPlausibleRange(pdfBytes, range))) {
      return range;
    }
  } catch (_) {
    // fall through
  }

  final range = _findContentsRangeInternal(pdfBytes);
  if ((strict && !_isValidContentsRange(pdfBytes, range)) ||
      (!strict && !_isPlausibleRange(pdfBytes, range))) {
    throw StateError('Contents encontrado mas inconsistente.');
  }
  return range;
}