SfPdfViewer class

A widget to view PDF documents.

SfPdfViewer lets you display the PDF document seamlessly and efficiently. It is built in the way that a large PDF document can be opened in minimal time and all their pages can be accessed spontaneously.

SfPdfViewer provides option to navigate to the desired pages and bookmarks within the document. Also it allows zooming and customization of features being displayed, such as scroll head, page scroll status and navigation dialog.

This example demonstrates how to load the PDF document from AssetBundle.

class MyAppState extends State<MyApp>{
@override
void initState() {
  super.initState();
}

@override
Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: SfPdfViewer.asset(
          'assets/flutter-succinctly.pdf',
        ),
      ),
    );
  }
}
Inheritance
Annotations

Constructors

SfPdfViewer.asset(String name, {Key? key, AssetBundle? bundle, bool canShowScrollHead = true, double pageSpacing = 4, PdfViewerController? controller, UndoHistoryController? undoController, PdfZoomLevelChangedCallback? onZoomLevelChanged, bool canShowPageLoadingIndicator = true, bool canShowScrollStatus = true, PdfPageChangedCallback? onPageChanged, PdfDocumentLoadedCallback? onDocumentLoaded, bool enableDoubleTapZooming = true, bool enableTextSelection = true, PdfTextSelectionChangedCallback? onTextSelectionChanged, PdfHyperlinkClickedCallback? onHyperlinkClicked, PdfDocumentLoadFailedCallback? onDocumentLoadFailed, PdfGestureTapCallback? onTap, PdfFormFieldValueChangedCallback? onFormFieldValueChanged, PdfFormFieldFocusChangeCallback? onFormFieldFocusChange, PdfAnnotationCallback? onAnnotationAdded, PdfAnnotationCallback? onAnnotationSelected, PdfAnnotationCallback? onAnnotationDeselected, PdfAnnotationCallback? onAnnotationEdited, PdfAnnotationCallback? onAnnotationRemoved, bool enableDocumentLinkAnnotation = true, bool canShowPaginationDialog = true, bool canShowSignaturePadDialog = true, Offset initialScrollOffset = Offset.zero, double initialZoomLevel = 1, int initialPageNumber = 1, double maxZoomLevel = 3, PdfInteractionMode interactionMode = PdfInteractionMode.selection, PdfScrollDirection? scrollDirection, PdfPageLayoutMode pageLayoutMode = PdfPageLayoutMode.continuous, Color currentSearchTextHighlightColor = const Color.fromARGB(80, 249, 125, 0), Color otherSearchTextHighlightColor = const Color.fromARGB(50, 255, 255, 1), String? password, bool canShowPasswordDialog = true, bool canShowHyperlinkDialog = true, bool enableHyperlinkNavigation = true, bool canShowTextSelectionMenu = true})
Creates a widget that displays the PDF document obtained from an asset bundle.
SfPdfViewer.file(File file, {Key? key, bool canShowScrollHead = true, double pageSpacing = 4, PdfViewerController? controller, UndoHistoryController? undoController, PdfZoomLevelChangedCallback? onZoomLevelChanged, bool canShowPageLoadingIndicator = true, bool canShowScrollStatus = true, PdfPageChangedCallback? onPageChanged, bool enableDoubleTapZooming = true, bool enableTextSelection = true, PdfTextSelectionChangedCallback? onTextSelectionChanged, PdfHyperlinkClickedCallback? onHyperlinkClicked, PdfDocumentLoadedCallback? onDocumentLoaded, PdfDocumentLoadFailedCallback? onDocumentLoadFailed, PdfGestureTapCallback? onTap, PdfFormFieldValueChangedCallback? onFormFieldValueChanged, PdfFormFieldFocusChangeCallback? onFormFieldFocusChange, PdfAnnotationCallback? onAnnotationAdded, PdfAnnotationCallback? onAnnotationSelected, PdfAnnotationCallback? onAnnotationDeselected, PdfAnnotationCallback? onAnnotationEdited, PdfAnnotationCallback? onAnnotationRemoved, bool enableDocumentLinkAnnotation = true, bool canShowPaginationDialog = true, bool canShowSignaturePadDialog = true, Offset initialScrollOffset = Offset.zero, double initialZoomLevel = 1, int initialPageNumber = 1, double maxZoomLevel = 3, PdfInteractionMode interactionMode = PdfInteractionMode.selection, PdfScrollDirection? scrollDirection, PdfPageLayoutMode pageLayoutMode = PdfPageLayoutMode.continuous, Color currentSearchTextHighlightColor = const Color.fromARGB(80, 249, 125, 0), Color otherSearchTextHighlightColor = const Color.fromARGB(50, 255, 255, 1), String? password, bool canShowPasswordDialog = true, bool canShowHyperlinkDialog = true, bool enableHyperlinkNavigation = true, bool canShowTextSelectionMenu = true})
Creates a widget that displays the PDF document obtained from File.
SfPdfViewer.memory(Uint8List bytes, {Key? key, bool canShowScrollHead = true, double pageSpacing = 4, PdfViewerController? controller, UndoHistoryController? undoController, PdfZoomLevelChangedCallback? onZoomLevelChanged, bool canShowPageLoadingIndicator = true, bool canShowScrollStatus = true, PdfPageChangedCallback? onPageChanged, bool enableDoubleTapZooming = true, bool enableTextSelection = true, PdfTextSelectionChangedCallback? onTextSelectionChanged, PdfHyperlinkClickedCallback? onHyperlinkClicked, PdfDocumentLoadedCallback? onDocumentLoaded, PdfDocumentLoadFailedCallback? onDocumentLoadFailed, PdfGestureTapCallback? onTap, PdfFormFieldValueChangedCallback? onFormFieldValueChanged, PdfFormFieldFocusChangeCallback? onFormFieldFocusChange, PdfAnnotationCallback? onAnnotationAdded, PdfAnnotationCallback? onAnnotationSelected, PdfAnnotationCallback? onAnnotationDeselected, PdfAnnotationCallback? onAnnotationEdited, PdfAnnotationCallback? onAnnotationRemoved, bool enableDocumentLinkAnnotation = true, bool canShowPaginationDialog = true, bool canShowSignaturePadDialog = true, Offset initialScrollOffset = Offset.zero, double initialZoomLevel = 1, int initialPageNumber = 1, double maxZoomLevel = 3, PdfInteractionMode interactionMode = PdfInteractionMode.selection, PdfScrollDirection? scrollDirection, PdfPageLayoutMode pageLayoutMode = PdfPageLayoutMode.continuous, Color currentSearchTextHighlightColor = const Color.fromARGB(80, 249, 125, 0), Color otherSearchTextHighlightColor = const Color.fromARGB(50, 255, 255, 1), String? password, bool canShowPasswordDialog = true, bool canShowHyperlinkDialog = true, bool enableHyperlinkNavigation = true, bool canShowTextSelectionMenu = true})
Creates a widget that displays the PDF document obtained from Uint8List.
SfPdfViewer.network(String src, {Key? key, Map<String, String>? headers, bool canShowScrollHead = true, double pageSpacing = 4, PdfViewerController? controller, UndoHistoryController? undoController, PdfZoomLevelChangedCallback? onZoomLevelChanged, bool canShowPageLoadingIndicator = true, bool canShowScrollStatus = true, PdfPageChangedCallback? onPageChanged, bool enableDoubleTapZooming = true, bool enableTextSelection = true, PdfTextSelectionChangedCallback? onTextSelectionChanged, PdfHyperlinkClickedCallback? onHyperlinkClicked, PdfDocumentLoadedCallback? onDocumentLoaded, PdfDocumentLoadFailedCallback? onDocumentLoadFailed, PdfGestureTapCallback? onTap, PdfFormFieldValueChangedCallback? onFormFieldValueChanged, PdfFormFieldFocusChangeCallback? onFormFieldFocusChange, PdfAnnotationCallback? onAnnotationAdded, PdfAnnotationCallback? onAnnotationSelected, PdfAnnotationCallback? onAnnotationDeselected, PdfAnnotationCallback? onAnnotationEdited, PdfAnnotationCallback? onAnnotationRemoved, bool enableDocumentLinkAnnotation = true, bool canShowPaginationDialog = true, bool canShowSignaturePadDialog = true, Offset initialScrollOffset = Offset.zero, double initialZoomLevel = 1, int initialPageNumber = 1, double maxZoomLevel = 3, PdfInteractionMode interactionMode = PdfInteractionMode.selection, PdfScrollDirection? scrollDirection, PdfPageLayoutMode pageLayoutMode = PdfPageLayoutMode.continuous, Color currentSearchTextHighlightColor = const Color.fromARGB(80, 249, 125, 0), Color otherSearchTextHighlightColor = const Color.fromARGB(50, 255, 255, 1), String? password, bool canShowPasswordDialog = true, bool canShowHyperlinkDialog = true, bool enableHyperlinkNavigation = true, bool canShowTextSelectionMenu = true})
Creates a widget that displays the PDF document obtained from the network.

Properties

canShowHyperlinkDialog bool
Indicates whether the hyperlink dialog in SfPdfViewer can be displayed or not.
final
canShowPageLoadingIndicator bool
Indicates whether the page loading busy indicator can be displayed or not.
final
canShowPaginationDialog bool
Indicates whether the page navigation dialog can be shown when the scroll head is tapped.
final
canShowPasswordDialog bool
Indicates whether the password dialog can be shown when loading password protected document.
final
canShowScrollHead bool
Indicates whether the scroll head in SfPdfViewer can be displayed or not.
final
canShowScrollStatus bool
Indicates whether the page scroll status in SfPdfViewer can be displayed or not.
final
canShowSignaturePadDialog bool
Indicates whether the built-in signature pad dialog should be displayed or not. The default value is true.
final
canShowTextSelectionMenu bool
Indicates whether the text selection menu can be displayed after the text is selected.
final
controller PdfViewerController?
An object that is used to control the navigation and zooming operations in the SfPdfViewer.
final
currentSearchTextHighlightColor Color
Current instance search text highlight color.
final
enableDocumentLinkAnnotation bool
Indicates whether the document link annotation navigation can be performed or not.
final
enableDoubleTapZooming bool
Indicates whether the double tap zooming in SfPdfViewer can be allowed or not.
final
enableHyperlinkNavigation bool
Indicates whether the hyperlink navigation can be performed or not .
final
enableTextSelection bool
Indicates whether the text selection can be performed or not.
final
hashCode int
The hash code for this object.
no setterinherited
initialPageNumber int
Represents the initial page to be displayed when the SfPdfViewer widget is loaded.
final
initialScrollOffset Offset
Represents the initial scroll offset position to be displayed when the SfPdfViewer widget is loaded.
final
initialZoomLevel double
Represents the initial zoom level to be applied when the SfPdfViewer widget is loaded.
final
interactionMode PdfInteractionMode
Indicates the interaction modes of SfPdfViewer in a desktop browser.
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
maxZoomLevel double
Represents the maximum allowed zoom level.
final
onAnnotationAdded PdfAnnotationCallback?
Occurs when an annotation is added to a page.
final
onAnnotationDeselected PdfAnnotationCallback?
Occurs when a selected annotation gets deselected.
final
onAnnotationEdited PdfAnnotationCallback?
Occurs when annotation is modified.
final
onAnnotationRemoved PdfAnnotationCallback?
Occurs when annotation is removed.
final
onAnnotationSelected PdfAnnotationCallback?
Occurs when an annotation is selected.
final
onDocumentLoaded PdfDocumentLoadedCallback?
Called after the document is loaded in SfPdfViewer.
final
onDocumentLoadFailed PdfDocumentLoadFailedCallback?
Called when the document loading fails in SfPdfViewer.
final
onFormFieldFocusChange PdfFormFieldFocusChangeCallback?
Called when the form field focus changes in SfPdfViewer.
final
onFormFieldValueChanged PdfFormFieldValueChangedCallback?
Called when the form field value changed in SfPdfViewer.
final
onHyperlinkClicked PdfHyperlinkClickedCallback?
Called when the hyperlink is tapped in SfPdfViewer.
final
onPageChanged PdfPageChangedCallback?
Called when the page changes in SfPdfViewer.
final
onTap PdfGestureTapCallback?
Called when tapped on the SfPdfViewer.
final
onTextSelectionChanged PdfTextSelectionChangedCallback?
Called when the text is selected or deselected in SfPdfViewer.
final
onZoomLevelChanged PdfZoomLevelChangedCallback?
Called when the zoom level changes in SfPdfViewer.
final
otherSearchTextHighlightColor Color
Other instance search text highlight color.
final
pageLayoutMode PdfPageLayoutMode
The layout mode in which the PDF page will be rendered.
final
pageSpacing double
Represents the spacing (in pixels) between the PDF pages.
final
password String?
The password to open the PDF document in SfPdfViewer.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scrollDirection PdfScrollDirection?
The direction in which the PDF page scrolls.
final
undoController UndoHistoryController?
Controls the annotation undo state.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() SfPdfViewerState
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}) 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