extractPlainText method
- int? pageIndex,
- PdfTextExtractorConfig config = const PdfTextExtractorConfig(),
Extracts plain text from one or all pages of the document.
When pageIndex is null, the stream yields all pages in index order.
When pageIndex is specified, the stream yields exactly one PdfPageText.
Throws RangeError if pageIndex is out of range.
Throws StateError if the document has been closed before or during
extraction.
Cancelling the stream subscription immediately stops further processing. Page-level PDFium handles are released after each round-trip, so there are no handle leaks on cancellation.
close terminates any active stream: the stream stops emitting events and the subscription is silently cancelled.
Example — extract all pages and print each one:
await for (final page in doc.extractPlainText()) {
if (page.hasTextLayer) {
print('Page ${page.pageIndex}: ${page.text}');
} else {
print('Page ${page.pageIndex}: no text layer (scanned page)');
}
}
Implementation
Stream<PdfPageText> extractPlainText({
int? pageIndex,
PdfTextExtractorConfig config = const PdfTextExtractorConfig(),
}) => _impl.extractPlainText(pageIndex: pageIndex, config: config);