getPageSize method
Gets the PdfImageRendererPageSize by the given pageIndex
.
If the size was already fetched before, it will be returned from memory.
Implementation
Future<PdfImageRendererPageSize> getPageSize({required int pageIndex}) async {
if (_id == null) throw StateError('Please open the PDF first!');
// Check page sizes cache.
if (_pageSizes.containsKey(pageIndex)) return _pageSizes[pageIndex]!;
// Check if the page at given index is already open.
// If not, auto-open and auto-close the page at given index.
final autoOpenClosePage = !_pages.contains(pageIndex);
// Open the page, if required.
if (autoOpenClosePage) await openPage(pageIndex: pageIndex);
_pageSizes[pageIndex] = await PdfImageRenderer.getPDFPageSize(pdf: _id!, page: pageIndex);
// Close the page, if required.
if (autoOpenClosePage) await closePage(pageIndex: pageIndex);
return _pageSizes[pageIndex]!;
}