open method
Implementation
Future<void> open({String? path, String? url, Uint8List? bytes, String? asset, Object? blob, Map<String, String>? headers, String password = ""}) async {
emit(value.copyWith(state: UDocState.opening, isBusy: true, clearError: true));
try {
final UPdfDocument document = await UPdfDocument.open(path: path, url: url, bytes: bytes, asset: asset, blob: blob, headers: headers, password: password);
_document = document;
_renderer = UPdfPageRenderer(document);
_index = await UDocTextIndex.open(document.fingerprint);
await _loadHiddenGroups(document);
final UDocMetadata metadata = await document.metadata();
final UPdfPage? first = await document.page(0);
if (first != null) {
_pages[0] = first;
_fallbackInfo = _infoFor(first);
_infos[0] = _fallbackInfo;
}
unawaited(_prefetchInfos());
unawaited(_loadOutline());
emit(
value.copyWith(
state: UDocState.ready,
kind: UDocKind.pdf,
pageCount: document.pageCount,
metadata: metadata,
permissions: document.permissions,
isBusy: false,
loadedPercent: 1,
clearError: true,
),
);
await UDocProgressStore.instance.load();
final UDocProgress? progress = UDocProgressStore.instance.get(document.fingerprint);
if (progress != null && progress.pageIndex > 0 && progress.pageIndex < document.pageCount) emit(value.copyWith(pageIndex: progress.pageIndex));
} on UDocError catch (error) {
failWith(error);
} on Object catch (error) {
failWith(UDocError(code: UDocErrorCode.corrupt, message: "Could not open the document", detail: "$error"));
}
}