Class SfPdfViewer
Represents a control that displays a PDF document.
Implements
Inherited Members
Namespace: Syncfusion.Maui.PdfViewer
Assembly: Syncfusion.Maui.PdfViewer.dll
Syntax
public class SfPdfViewer : SfView, IDrawableLayout, IDrawable, IAbsoluteLayout, ILayout, IView, IElement, ITransform, IContainer, IList<IView>, ICollection<IView>, IEnumerable<IView>, IEnumerable, ISafeAreaView, IPadding, IVisualTreeElement, ITouchListener
Constructors
SfPdfViewer()
Initializes a new instance of the SfPdfViewer class.
Declaration
public SfPdfViewer()
Fields
AnnotationModeProperty
Backing store for the AnnotationMode property.
Declaration
public static readonly BindableProperty AnnotationModeProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
DocumentSourceProperty
Backing store for the DocumentSource property.
Declaration
public static readonly BindableProperty DocumentSourceProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
EnableDocumentLinkNavigationProperty
Backing store for EnableDocumentLinkNavigation property.
Declaration
public static readonly BindableProperty EnableDocumentLinkNavigationProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
EnableHyperlinkNavigationProperty
Backing store for EnableHyperlinkNavigation property.
Declaration
public static readonly BindableProperty EnableHyperlinkNavigationProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
EnableTextSelectionProperty
Backing store for EnableTextSelection property
Declaration
public static readonly BindableProperty EnableTextSelectionProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
HorizontalOffsetProperty
Backing store for HorizontalOffset property.
Declaration
public static readonly BindableProperty HorizontalOffsetProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
IsOutlineViewVisibleProperty
Backing store for the IsOutlineViewVisible property.
Declaration
public static readonly BindableProperty IsOutlineViewVisibleProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
MaxZoomFactorProperty
Backing store for the MaxZoomFactor property.
Declaration
public static readonly BindableProperty MaxZoomFactorProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
MinZoomFactorProperty
Backing store for the MinZoomFactor property.
Declaration
public static readonly BindableProperty MinZoomFactorProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
PageCountProperty
Backing store for the PageCount property.
Declaration
public static readonly BindableProperty PageCountProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
PageNumberProperty
Backing store for the PageNumber property.
Declaration
public static readonly BindableProperty PageNumberProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
ShowScrollHeadProperty
Backing store for ShowScrollHead property.
Declaration
public static readonly BindableProperty ShowScrollHeadProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
TextSearchSettingsProperty
Backing store for TextSearchSettings property.
Declaration
public static readonly BindableProperty TextSearchSettingsProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
TextSelectionSettingsProperty
Backing store for TextSelectionSettings property
Declaration
public static readonly BindableProperty TextSelectionSettingsProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
VerticalOffsetProperty
Backing store for VerticalOffset property.
Declaration
public static readonly BindableProperty VerticalOffsetProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
ZoomFactorProperty
Backing store for the ZoomFactorProperty property.
Declaration
public static readonly BindableProperty ZoomFactorProperty
Field Value
| Type | Description |
|---|---|
| Microsoft.Maui.Controls.BindableProperty |
Properties
AnnotationMode
Gets or sets a value indicating the type of annotation that should be drawn using UI interaction on the PDF pages.
Declaration
public AnnotationMode AnnotationMode { get; set; }
Property Value
| Type | Description |
|---|---|
| AnnotationMode |
Annotations
Gets the list of annotations in the PDF.
Declaration
public ReadOnlyObservableCollection<Annotation> Annotations { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.ObjectModel.ReadOnlyObservableCollection<Annotation> |
AnnotationSettings
Gets or sets the default annotation settings.
Declaration
public AnnotationSettings AnnotationSettings { get; }
Property Value
| Type | Description |
|---|---|
| AnnotationSettings |
DocumentOutline
Gets the oultline for the document.
Declaration
public IReadOnlyList<OutlineElement> DocumentOutline { get; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.IReadOnlyList<OutlineElement> | The outlines in the document. |
DocumentSource
Gets or sets the PDF document source as System.IO.Stream or byte array.
Declaration
public object DocumentSource { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Object |
EnableDocumentLinkNavigation
Gets or sets a value that indicates whether document link annotations (TOC) in the PDF can be interacted with.
Declaration
public bool EnableDocumentLinkNavigation { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
EnableHyperlinkNavigation
Gets or sets the value that indicates whether the hyperlink navigation can be performed or not.
Declaration
public bool EnableHyperlinkNavigation { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean | The default value is true. |
EnableTextSelection
Gets or sets a value that indicates whether the text selection is enabled or not. The default value is true.
Declaration
public bool EnableTextSelection { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
GoToFirstPageCommand
Gets the value that represents the go to first page command.
Declaration
public ICommand GoToFirstPageCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
GoToLastPageCommand
Gets the value that represents the go to last page command.
Declaration
public ICommand GoToLastPageCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
GoToNextPageCommand
Gets the value that represents the go to next page command.
Declaration
public ICommand GoToNextPageCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
GoToPageCommand
Gets the value that represents the go to specific page command.
Declaration
public ICommand GoToPageCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
GoToPreviousPageCommand
Gets the value that represents the go to previous page command.
Declaration
public ICommand GoToPreviousPageCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
HorizontalOffset
Returns the current horizontal scrolled position of the SfPdfViewer.
Declaration
public Nullable<double> HorizontalOffset { get; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.Double> |
IsOutlineViewVisible
Gets or sets a value indicating whether the outline view is visible.
Declaration
public bool IsOutlineViewVisible { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
LoadDocumentCommand
Gets the command that loads a PDF document when executed.
Declaration
public ICommand LoadDocumentCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
MaxZoomFactor
Get or sets the maximum allowed zoom factor.
Declaration
public double MaxZoomFactor { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double | The default value is 4. The value should not be lower than MinZoomFactor. |
MinZoomFactor
Get or sets the minimum allowed zoom factor.
Declaration
public double MinZoomFactor { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double | The default value is 0.25 and 1 for desktop and mobile platforms respectively. The value should not exceed the MaxZoomFactor. |
PageCount
Returns the total number of pages in a document.
Declaration
public int PageCount { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
PageNumber
Returns the current page number.
Declaration
public int PageNumber { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
RedoCommand
Gets the command that performs the redo operation.
Declaration
public ICommand RedoCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
RemoveAllAnnotationsCommand
Gets the command that removes all annotations from the PDF document.
Declaration
public ICommand RemoveAllAnnotationsCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
SaveDocumentCommand
Gets the command that saves the PDF document.
Declaration
public ICommand SaveDocumentCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
ScrollToOffsetCommand
Gets the value that represents the scroll to specific offset command.
Declaration
public ICommand ScrollToOffsetCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
SearchTextCommand
Gets the command to search a text in the PDF document asynchronously.
Declaration
public ICommand SearchTextCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
ShowScrollHead
Gets or sets the value indicates whether or not the scroll head can be shown.
Declaration
public bool ShowScrollHead { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean | The default value is true. |
Remarks
This property is applicable only for the mobile platforms.
TextSearchSettings
Represents and allows for modification of the text search settings.
Declaration
public TextSearchSettings TextSearchSettings { get; }
Property Value
| Type | Description |
|---|---|
| TextSearchSettings |
TextSelectionSettings
Gets or sets the text selection settings
Declaration
public TextSelectionSettings TextSelectionSettings { get; set; }
Property Value
| Type | Description |
|---|---|
| TextSelectionSettings |
UndoCommand
Gets the command that performs the undo opertation.
Declaration
public ICommand UndoCommand { get; }
Property Value
| Type | Description |
|---|---|
| System.Windows.Input.ICommand |
VerticalOffset
Returns the current vertical scrolled position of the SfPdfViewer.
Declaration
public Nullable<double> VerticalOffset { get; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.Double> |
ZoomFactor
Gets or sets the zoom factor for the document loaded in the SfPdfViewer.
Declaration
public double ZoomFactor { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Double | The default value is 1. The value can be set between MinZoomFactor and MaxZoomFactor. If anything set beyond the limit, the value will be clamped. |
Methods
AddAnnotation(Annotation)
Adds the given annotation to the page represented by the annotation’s PageNumber property.
Declaration
public void AddAnnotation(Annotation annotation)
Parameters
| Type | Name | Description |
|---|---|---|
| Annotation | annotation | The annotation to be added. |
DeselectAnnotation(Annotation)
Deselects the given annotation.
Declaration
public void DeselectAnnotation(Annotation annotation)
Parameters
| Type | Name | Description |
|---|---|---|
| Annotation | annotation | Deselects the given annotation. |
ExportAnnotations(Stream, AnnotationDataFormat, List<Annotation>)
Exports the annotations in the PDF document to the specified format and writes the exported data to the given output stream.
Declaration
public void ExportAnnotations(Stream stream, AnnotationDataFormat dataFormat, List<Annotation> annotations = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | stream | The stream that contains the exported annotation data. |
| AnnotationDataFormat | dataFormat | The data format in which the annotations should be exported. |
| System.Collections.Generic.List<Annotation> | annotations | The annotations to be exported. |
Remarks
If the annotations parameter is not null, only the annotations specified in the collection will be exported and other annotations will be ignored.
ExportAnnotationsAsync(Stream, AnnotationDataFormat, List<Annotation>, CancellationToken)
Exports the annotations in the PDF document to the specified format and writes the exported data to the given output stream.
Declaration
public Task ExportAnnotationsAsync(Stream stream, AnnotationDataFormat dataFormat, List<Annotation> annotations = null, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | stream | The stream that contains the exported annotation data. |
| AnnotationDataFormat | dataFormat | The data format in which the annotations should be exported. |
| System.Collections.Generic.List<Annotation> | annotations | The annotations to be exported. |
| System.Threading.CancellationToken | cancellationToken | The token to receive notice of the cancellation. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task |
Remarks
If the annotations parameter is not null, only the annotations specified in the collection will be exported and other annotations will be ignored.
GoToFirstPage()
Jumps to the first page of a document.
Declaration
public void GoToFirstPage()
GoToLastPage()
Jumps to the last page of a document.
Declaration
public void GoToLastPage()
GoToNextPage()
Jumps to the next page of a document.
Declaration
public void GoToNextPage()
GoToOutlineElement(OutlineElement)
Navigates to the location of the given outline element.
Declaration
public void GoToOutlineElement(OutlineElement outlineElement)
Parameters
| Type | Name | Description |
|---|---|---|
| OutlineElement | outlineElement |
GoToPage(Int32)
Jumps to the specified page in a document.
Declaration
public void GoToPage(int pageNumber)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | pageNumber | The number of the page to which the control should go. |
GoToPreviousPage()
Jumps to the previous page of a document.
Declaration
public void GoToPreviousPage()
ImportAnnotations(Stream, AnnotationDataFormat)
Imports annotation data into the PDF document.
Declaration
public void ImportAnnotations(Stream stream, AnnotationDataFormat annotationDataFormat)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | stream | The stream that contains the annotation data to be imported. |
| AnnotationDataFormat | annotationDataFormat | The data format of the input stream. |
ImportAnnotationsAsync(Stream, AnnotationDataFormat, CancellationToken)
Imports annotation data into the PDF document.
Declaration
public Task ImportAnnotationsAsync(Stream annotationDataStream, AnnotationDataFormat annotationDataFormat, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | annotationDataStream | The stream to which the PDF document is saved. |
| AnnotationDataFormat | annotationDataFormat | The data format of the input stream. |
| System.Threading.CancellationToken | cancellationToken | The token to receive notice of the cancellation. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task |
LoadDocument(Byte[], String, Nullable<FlattenOptions>)
Loads the PDF document from the specified bytes.
Declaration
public void LoadDocument(byte[] documentBytes, string password = null, Nullable<FlattenOptions> flattenOptions)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | documentBytes | The document as byte array |
| System.String | password | Password for the document. It is required to open a password protected document. |
| System.Nullable<FlattenOptions> | flattenOptions | The option that represents whether annotations or form fields should be flattened. |
LoadDocument(Stream, String, Nullable<FlattenOptions>)
Loads the PDF document from the specified stream.
Declaration
public void LoadDocument(Stream documentStream, string password = null, Nullable<FlattenOptions> flattenOptions)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | documentStream | The document stream. |
| System.String | password | Password for the document. It is required to open a password protected document. |
| System.Nullable<FlattenOptions> | flattenOptions | The option that represents whether annotations or form fields should be flattened. |
LoadDocumentAsync(Byte[], String, Nullable<FlattenOptions>, CancellationTokenSource)
Loads the PDF document asynchronously from the specified bytes.
Declaration
public Task LoadDocumentAsync(byte[] documentBytes, string password = null, Nullable<FlattenOptions> flattenOptions, CancellationTokenSource cancellationTokenSource = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Byte[] | documentBytes | The document as byte array. |
| System.String | password | Password for the document. It is required to open a password protected document. |
| System.Nullable<FlattenOptions> | flattenOptions | The option that represents whether annotations or form fields should be flattened. |
| System.Threading.CancellationTokenSource | cancellationTokenSource | The cancellation token source for cancelling the task. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | Returns the task |
LoadDocumentAsync(Stream, String, Nullable<FlattenOptions>, CancellationTokenSource)
Loads the PDF document asynchronously from the specified stream.
Declaration
public Task LoadDocumentAsync(Stream documentStream, string password = null, Nullable<FlattenOptions> flattenOptions, CancellationTokenSource cancellationTokenSource = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | documentStream | The document stream. |
| System.String | password | Password for the document. It is required to open a password protected document. |
| System.Nullable<FlattenOptions> | flattenOptions | The option that represents whether annotations or form fields should be flattened. |
| System.Threading.CancellationTokenSource | cancellationTokenSource | The cancellation token source for cancelling the task. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | Returns the task |
OnSizeAllocated(Double, Double)
Called when the control size is allocated
Declaration
protected override void OnSizeAllocated(double width, double height)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | width | Control's new width |
| System.Double | height | Control's new height |
RemoveAllAnnotations()
Removes all annotations from the PDF document.
Declaration
public void RemoveAllAnnotations()
RemoveAnnotation(Annotation)
Removes the given annotation from the page.
Declaration
public void RemoveAnnotation(Annotation annotation)
Parameters
| Type | Name | Description |
|---|---|---|
| Annotation | annotation | The annotation to be removed. |
SaveDocument(Stream)
Saves the PDF document and writes the final document into the given output stream.
Declaration
public void SaveDocument(Stream outputStream)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | outputStream | The stream to which the PDF document is saved. |
SaveDocumentAsync(Stream, CancellationToken)
Saves the PDF document and writes the final document into the given output stream.
Declaration
public Task SaveDocumentAsync(Stream outputStream, CancellationToken cancellationToken = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.IO.Stream | outputStream | The stream to which the PDF document is saved. |
| System.Threading.CancellationToken | cancellationToken | The token to receive notice of the cancellation. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task |
ScrollToOffset(Double, Double)
Scrolls the content to the specified offset.
Declaration
public void ScrollToOffset(double horizontalOffset, double verticalOffset)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Double | horizontalOffset | The value to which the control scrolls horizontally. The value is measured in device-independent units. |
| System.Double | verticalOffset | The value to which the control scrolls vertically. The value is measured in device-independent units. |
SearchTextAsync(String, TextSearchOptions, CancellationTokenSource)
Finds and highlights all occurrences of the given text in the PDF document asynchronously.
Declaration
public Task<TextSearchResult> SearchTextAsync(string text, TextSearchOptions searchOption, CancellationTokenSource cancellationTokenSource = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | text | The text or keyword to be searched. |
| TextSearchOptions | searchOption | The constant to specify the text search options. |
| System.Threading.CancellationTokenSource | cancellationTokenSource | The cancellation token to cancel the current search progress. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task<TextSearchResult> | Provides the search result obtained from searching a given text. |
SelectAnnotation(Annotation)
Selects the given annotation.
Declaration
public void SelectAnnotation(Annotation annotation)
Parameters
| Type | Name | Description |
|---|---|---|
| Annotation | annotation | The annotation to be selected. |
UnloadDocument()
Unloads the current PDF document.
Declaration
public void UnloadDocument()
UnloadDocumentAsync()
Unloads the current PDF document asynchronously.
Declaration
public Task UnloadDocumentAsync()
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task |
Events
AnnotationAdded
Occurs when an annotation is added to a page.
Declaration
public event EventHandler<AnnotationEventArgs> AnnotationAdded
Event Type
| Type | Description |
|---|---|
| System.EventHandler<AnnotationEventArgs> |
AnnotationDeselected
Occurs when a selected annotation gets deselected.
Declaration
public event EventHandler<AnnotationEventArgs> AnnotationDeselected
Event Type
| Type | Description |
|---|---|
| System.EventHandler<AnnotationEventArgs> |
AnnotationEdited
Occurs when annotation is modified.
Declaration
public event EventHandler<AnnotationEventArgs> AnnotationEdited
Event Type
| Type | Description |
|---|---|
| System.EventHandler<AnnotationEventArgs> |
AnnotationRemoved
Occurs when an annotation is removed from the page.
Declaration
public event EventHandler<AnnotationEventArgs> AnnotationRemoved
Event Type
| Type | Description |
|---|---|
| System.EventHandler<AnnotationEventArgs> |
AnnotationSelected
Occurs when an annotation is selected.
Declaration
public event EventHandler<AnnotationEventArgs> AnnotationSelected
Event Type
| Type | Description |
|---|---|
| System.EventHandler<AnnotationEventArgs> |
DocumentLoaded
Occurs when a PDF document is loaded.
Declaration
public event EventHandler<EventArgs> DocumentLoaded
Event Type
| Type | Description |
|---|---|
| System.EventHandler<System.EventArgs> |
DocumentLoadFailed
Occurs when the PDF Viewer fails to load a PDF document.
Declaration
public event EventHandler<DocumentLoadFailedEventArgs> DocumentLoadFailed
Event Type
| Type | Description |
|---|---|
| System.EventHandler<DocumentLoadFailedEventArgs> |
DocumentUnloaded
Occurs when a PDF document is unloaded.
Declaration
public event EventHandler<EventArgs> DocumentUnloaded
Event Type
| Type | Description |
|---|---|
| System.EventHandler<System.EventArgs> |
HyperlinkClicked
Occurs when hyperlink is clicked or tapped.
Declaration
public event EventHandler<HyperlinkClickedEventArgs> HyperlinkClicked
Event Type
| Type | Description |
|---|---|
| System.EventHandler<HyperlinkClickedEventArgs> |
PasswordRequested
Occurs when a security password is required to open a PDF document.
Declaration
public event EventHandler<PasswordRequestedEventArgs> PasswordRequested
Event Type
| Type | Description |
|---|---|
| System.EventHandler<PasswordRequestedEventArgs> |
Tapped
Occurs when the SfPdfViewer is tapped.
Declaration
public event EventHandler<GestureEventArgs> Tapped
Event Type
| Type | Description |
|---|---|
| System.EventHandler<GestureEventArgs> |
TextSearchProgress
Occurs when the text search is in progress.
Declaration
public event EventHandler<TextSearchProgressEventArgs> TextSearchProgress
Event Type
| Type | Description |
|---|---|
| System.EventHandler<TextSearchProgressEventArgs> |
TextSelectionChanged
Occurs when the text is selected or when the selected text is changed.
Declaration
public event EventHandler<TextSelectionChangedEventArgs> TextSelectionChanged
Event Type
| Type | Description |
|---|---|
| System.EventHandler<TextSelectionChangedEventArgs> |