PageViewer class

A PDF page viewer widget that supports multiple zoom modes and search-match overlays.

PageViewer wraps PdfDocument rendering and a ViewerController to provide a zoom-aware, pannable single-page view. It listens to the controller and re-renders the page whenever the controller changes.

Zoom modes

Mode Behaviour
ZoomMode.fitWidth Renders at the full available logical width.
ZoomMode.fitPage Renders so the full page (both dimensions) fits within the available area with a 24 dp border.
ZoomMode.custom Renders at availableWidth * controller.zoomFactor.

In all modes the logical render width is multiplied by MediaQuery.devicePixelRatioOf before passing to the rendering engine to produce sharp output on high-DPI displays.

Search overlays

When ViewerController.activeSearchMatches contains matches on the current page, translucent dusk-tinted rectangles are painted over the matching text regions. Coordinates are transformed from PDF user-space (bottom-left origin) to Flutter/screen space (top-left origin) using:

flutterX = pdfRect.left / pageWidthPt * widgetWidth
flutterY = (pageHeightPt - pdfRect.top) / pageHeightPt * widgetHeight
rectWidth  = (pdfRect.right - pdfRect.left) / pageWidthPt * widgetWidth
rectHeight = (pdfRect.top - pdfRect.bottom) / pageHeightPt * widgetHeight

Example

PageViewer(
  document: doc,
  pageCount: pageCount,
  controller: controller,
  semanticLabel: 'Annual report, page 1',
)
Inheritance

Constructors

PageViewer({Key? key, required PdfDocument document, required int pageCount, required ViewerController controller, String? semanticLabel})
Creates a PageViewer.
const

Properties

controller ViewerController
The controller that drives page navigation, zoom mode, annotation rendering, and search overlays.
final
document PdfDocument
The PDF document to render.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
pageCount int
Total number of pages in document.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
semanticLabel String?
Accessibility label for the rendered page canvas.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<PageViewer>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited