PdfController class
Opens a PDF for PdfView: the document (asking passwordProvider for the password of an encrypted one), the page on screen, the layout (viewMode), zoom and search.
The position is {page_number, page_count, view_mode}, reported on
every page change and layout switch.
- Inheritance
-
- Object
- ChangeNotifier
- DocumentController
- PdfController
Constructors
-
PdfController({ReadingPosition? initialPosition, ValueChanged<
ReadingPosition> ? onPositionChanged, PdfPasswordProvider? passwordProvider, TextRecognizer? textRecognizer}) -
Reopens on the page and in the layout saved in
initialPosition, if any.
Properties
- canRecognize → bool
-
Whether OCR can run: a textRecognizer was given and it is available
on this device.
no setter
- canZoomIn → bool
-
Whether zoomIn would zoom in.
no setterinherited
- canZoomOut → bool
-
Whether zoomOut would zoom out.
no setterinherited
- currentPage → int
-
The page on screen, from 1.
no setter
- document → PdfiumDocument?
-
The open document; null until loaded. For rendering or extracting
text yourself.
no setter
- error → DocumentLoadError?
-
Why the document couldn't be loaded; null unless status is
DocumentStatus.failed.
no setterinherited
- errorDetail → Object?
-
What went wrong opening the document, in the engine's terms (a
PdfOpenException or PdfEngineException); null unless loading
failed. error says the same in DocumentLoadError terms.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
-
hasSelection
→ ValueListenable<
bool> -
Whether the reader has text selected, for enabling a Copy button
without rebuilding on every other change.
no setterinherited
- hasTextLayer → bool?
-
Null until a zero-match search has looked at every page; then whether
any page had text (false: a scanned PDF).
no setter
-
highlights
→ List<
PdfHighlight> -
The highlights being shown.
no setter
- initialPageNumber → int
-
The page the viewer opens on.
no setter
- isDisposed → bool
-
Whether dispose has been called. A load that finishes afterwards
discards its result.
no setterinherited
- isLoaded → bool
-
True once loading has finished, successfully or not.
no setterinherited
-
location
→ ValueListenable<
DocumentLocation> -
Where the reader is, updated as they move: listen to it for a "page 3
of 12" display without rebuilding on every other change.
no setterinherited
- maxFileBytes → int
-
The largest file loadFile reads. Bigger files fail with
DocumentLoadError.tooLarge before anything is read.
no setterinherited
- maxZoom → double
-
The largest zoom.
no setteroverride
- minZoom → double
-
The smallest zoom.
no setteroverride
-
onPositionChanged
→ ValueChanged<
ReadingPosition> ? -
Called as the reader moves through the document, with the position
to save. Debouncing and storage are up to the app.
finalinherited
- pageCount → int
-
How many pages the document has; 0 until loaded.
no setter
- passwordProvider → PdfPasswordProvider?
-
Asked for the password of an encrypted PDF, once per attempt, until
it returns null (give up) or the password works. Without one, an
encrypted PDF fails with DocumentLoadError.passwordRequired.
final
- position → ReadingPosition
-
The place to save, as JSON-safe values: pass it back as
initialPositionto reopen there.no setteroverride - rotation → int
-
How far the pages have been turned since this document opened, in quarter turns clockwise (0-3).
Not saved, and the file is not changed.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
searchState
→ ValueListenable<
DocumentSearchState> -
The current search, updated as it runs and as the reader steps
through its matches.
no setterinherited
- status → DocumentStatus
-
Whether the document is loading, ready or failed.
no setterinherited
- textRecognizer → TextRecognizer?
-
Reads text from pictures: used for pages that have no text layer
(scans), when asked (recognizePage). Null: no OCR. The package has no
recognizer of its own; see TextRecognizer.
final
- viewMode → PdfViewMode
-
Pages one under the other, or side by side.
no setter
- viewModeSettled → bool
-
Whether the layout came from a saved position or the user; an app's
default layout should only apply while this is false.
no setter
- zoom → double
-
The zoom on screen: 1 is page width. Pinching and double-tapping
change it too.
no setteroverride
- zoomStep → double
-
How much zoomIn and zoomOut change zoom by.
no setterinherited
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
allText(
) → Future< String> -
The document's whole text, for "copy all". Empty for a format with no
text to give (a scanned PDF, until it has been recognised).
override
-
applyDefaultViewMode(
PdfViewMode mode) → void - A default layout (e.g. from app settings) for a document with none saved; ignored once the layout is settled.
-
applyPending(
) → void - For a format's view, once it has laid the document out: carries out what was asked for before (a goTo, and a format's own requests).
-
cancelOcr(
int page) → void -
Gives up on the OCR running for
page: its result is discarded when it arrives (a recognizer can't always be interrupted). -
clearSearch(
) → void -
Ends the search and removes its highlights.
inherited
-
clearSelection(
) → void -
Clears the selection. Does nothing until a view is showing the
document.
override
-
copyAllText(
) → Future< bool> -
Puts allText on the clipboard; false when the document has no text
or the clipboard refused it.
inherited
-
copySelection(
) → Future< bool> -
Puts selectedText on the clipboard. Returns false when nothing is
selected or the clipboard refused it, so the app can say so.
override
-
copyToClipboard(
String text) → Future< bool> -
Writes
textto the clipboard; false when it isn't available.inherited -
debugSetPages(
{required int pageCount, required int currentPage}) → void - Stands in for an open document where no PDF engine runs (unit tests).
-
deferGoTo(
int number) → void -
For a format's controller: goTo can't move yet (the document isn't
loaded, or no view has laid it out), so
numberis kept untilapplyPending.inherited -
dispose(
) → void -
Discards any resources used by the object.
override
-
fitWidth(
) → void - Back to page width (zoom 1).
-
goTo(
int number) → void -
Shows page
number(from 1).override -
goToOutlineEntry(
OutlineEntry entry) → void -
Moves to
entry, which this controller gave from outline.inherited -
jumpToPage(
int page) → Future< void> -
Shows
page(from 1), clamped to the document. -
loadBytes(
Uint8List bytes) → Future< void> -
Opens a PDF held in memory.
override
-
loadFile(
String path) → Future< void> -
Opens the PDF at
path; PDFium reads the file itself.override -
markFailed(
DocumentLoadError error) → void -
For a format's controller, or an app whose own read of the file
failed: the document can't be shown, because of
error.inherited -
markLoading(
) → void -
For a format's controller: loading has started.
inherited
-
markReady(
) → void -
For a format's controller: the document is loaded.
inherited
-
nextMatch(
) → void -
Shows the next match, wrapping round after the last.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
ocrErrorOf(
int page) → Object? -
Why OCR failed on
page, when ocrStatusOf says PdfOcrStatus.failed. -
ocrStatusOf(
int page) → PdfOcrStatus -
Where OCR is for
page(from 0). -
outline(
) → Future< List< OutlineEntry> > -
The PDF's bookmarks; each entry's target is a page number (from 1).
override
-
pageNeedsOcr(
int page) → Future< bool> -
Whether
page(from 0) is worth offering OCR for: it has no text of its own (a scan, or a picture), nothing was read from it yet, and a recognizer is available. -
previousMatch(
) → void -
Shows the previous match, wrapping round before the first.
override
-
recognizePage(
int page, {List< String> languageHints = const []}) → Future<bool> -
Reads the text on page
page(from 0) with the textRecognizer, so that it can be selected and copied like any page's text. A page that has text and pictures keeps its own text; only lines PDFium did not read are added. Returns whether any text was found; false too when there is no recognizer, the read failed (ocrErrorOf says why) or it was cancelled. Asking again while it runs joins the run. -
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
reportPosition(
) → void -
Reports position to onPositionChanged.
inherited
-
restore(
ReadingPosition position) → void - Applies a saved position: the page to open on and, when saved, the layout.
-
rotate(
int quarterTurns) → Future< void> -
Turns every page by
quarterTurnsquarter turns clockwise (negative: anticlockwise). Selection and OCR results are dropped, as they no longer sit on the page; an active search is run again. -
rotateClockwise(
) → Future< void> - Turns every page a quarter turn clockwise.
-
rotateCounterclockwise(
) → Future< void> - Turns every page a quarter turn anticlockwise.
-
search(
String query) → void -
Searches every page for
query(ignoring case; a phrase may wrap lines), jumping to the first match as soon as it's found. Pages are searched in the background: searchState reports the matches as they arrive.override -
selectAll(
) → void -
Selects everything the view has laid out: all of a spreadsheet's used
range, but only the pages or lines built so far in a long text
document; use allText to copy a whole document.
override
-
selectedRanges(
) → Future< List< PdfTextRange> > - The selection as ranges, a range per page it covers; empty when nothing is selected. An app turns these into highlights it keeps.
-
selectedText(
) → String? -
What the reader has selected, as the text to paste; null when nothing
is selected. PDF, Word, plain text, Markdown and slides give the
selected words; a spreadsheet gives its cells as tab-separated rows.
override
-
setHasSelection(
bool value) → void -
For a format that works out its selected text on demand (selectedText
being costly): there is, or isn't, a selection.
inherited
-
setHighlights(
List< PdfHighlight> highlights) → void -
Draws
highlightsover the text (replacing any shown before). The package keeps nothing: save the PdfTextRanges from selectedRanges yourself and pass them back when the document is opened again. -
setZoom(
double zoom) → void -
Sets
zoom, clamped to minZoom..maxZoom.override -
toggleViewMode(
) → void - Switches between pages one under the other and side by side.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateLocation(
DocumentLocation location) → void -
For a format's controller: the reader is now at
location.inherited -
updateSearch(
DocumentSearchState state) → void -
For a format's controller: the search is now
state.inherited -
zoomIn(
) → void -
Zooms in to the next of zoomSteps.
override
-
zoomOut(
) → void -
Zooms out to the previous of zoomSteps.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited