SfPdfViewer constructor
SfPdfViewer({
- required PDFSource source,
- Key? key,
- 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 canShowTextSelectionMenu = true,
Creates a widget that displays a PDF document from various sources.
The source
parameter is required and can be one of the following:
- AssetPDFSource: For PDFs stored in the app's assets
- URLPDFSource: For PDFs accessed via a network URL
- FilePDFSource: For PDFs stored as files on the device
- BytePDFSource: For PDFs stored in memory as bytes Example usage:
// From an asset
SfPdfViewer(source: AssetPDFSource('assets/document.pdf'))
// From a network URL
SfPdfViewer(source: URLPDFSource('https://example.com/document.pdf'))
// From a file
SfPdfViewer(source: FilePDFSource(File('/path/to/document.pdf')))
// From memory
SfPdfViewer(source: BytePDFSource(Uint8List(...)))
Implementation
/// Example usage:
/// ```dart
/// // From an asset
/// SfPdfViewer(source: AssetPDFSource('assets/document.pdf'))
/// // From a network URL
/// SfPdfViewer(source: URLPDFSource('https://example.com/document.pdf'))
/// // From a file
/// SfPdfViewer(source: FilePDFSource(File('/path/to/document.pdf')))
/// // From memory
/// SfPdfViewer(source: BytePDFSource(Uint8List(...)))
/// ```
SfPdfViewer({
/// The source of the PDF document to be displayed.
required PDFSource source,
Key? key,
this.canShowScrollHead = true,
this.pageSpacing = 4,
this.controller,
this.undoController,
this.onZoomLevelChanged,
this.canShowPageLoadingIndicator = true,
this.canShowScrollStatus = true,
this.onPageChanged,
this.onDocumentLoaded,
this.enableDoubleTapZooming = true,
this.enableTextSelection = true,
this.onTextSelectionChanged,
this.onHyperlinkClicked,
this.onDocumentLoadFailed,
this.onTap,
this.onFormFieldValueChanged,
this.onFormFieldFocusChange,
this.onAnnotationAdded,
this.onAnnotationSelected,
this.onAnnotationDeselected,
this.onAnnotationEdited,
this.onAnnotationRemoved,
this.enableDocumentLinkAnnotation = true,
this.canShowPaginationDialog = true,
this.canShowSignaturePadDialog = true,
this.initialScrollOffset = Offset.zero,
this.initialZoomLevel = 1,
this.initialPageNumber = 1,
this.maxZoomLevel = 3,
this.interactionMode = PdfInteractionMode.selection,
this.scrollDirection,
this.pageLayoutMode = PdfPageLayoutMode.continuous,
this.currentSearchTextHighlightColor = const Color.fromARGB(
80,
249,
125,
0,
),
this.otherSearchTextHighlightColor = const Color.fromARGB(50, 255, 255, 1),
this.password,
this.canShowPasswordDialog = true,
this.canShowHyperlinkDialog = true,
this.enableHyperlinkNavigation = true,
this.canShowTextSelectionMenu = true,
}) : _source = source,
assert(pageSpacing >= 0),
assert(!maxZoomLevel.isNaN),
assert(maxZoomLevel >= 1),
super(key: key);