Migrate from Xamarin.Forms SfPdfViewer to .NET MAUI SfPdfViewer

16 Dec 20246 minutes to read

To make migration from Xamarin SfPdfViewer to .NET MAUI SfPdfViewer easier, we kept most of the APIs from Xamarin SfPdfViewer in MAUI SfPdfViewer. However, to maintain the consistency of API naming in MAUI SfPdfViewer, we renamed some of the APIs. The APIs that have been changed in MAUI SfPdfViewer from Xamarin SfPdfViewer are detailed as follows.

Namespaces

Xamarin SfPdfViewer .NET MAUI SfPdfViewer
Syncfusion.SfPdfViewer.XForms Syncfusion.Maui.PdfViewer

Properties

Xamarin SfPdfViewer .NET MAUI SfPdfViewer Description

InputFileStream

DocumentSource

Represents the source object to load PDF files from the stream or byte array. This property helps to load a PDF document during control initialization and switch the documents dynamically.

ZoomPercentage

ZoomFactor

Returns and sets the zoom factor. The default value is 1, which represents 100% zoom. This value can be between 1 and 4.

MinimumZoomPercentage

MinZoomFactor

Returns and sets the minimum zoom factor. The default value is 0.25. This value should not exceed `MaxZoomFactor`.

MaximumZoomPercentage

MaxZoomFactor

Returns and sets the maximum zoom factor. The default value is 4. This value should not be lower than `MinZoomFactor`.

EnableScrollHead

ShowScrollHead

Returns and sets the value indicating whether the scroll head can be shown or not.

BookmarkPaneVisible

IsOutlineViewVisible

Gets or sets a value indicating whether the outline view is visible.

EnableDocumentLinkAnnotation

EnableDocumentLinkNavigation

Gets or sets a value that indicates whether document link annotations (TOC) in the PDF can be interacted with.

AllowHyperlinkNavigation

EnableHyperlinkNavigation

Gets or sets a value that indicates whether document link annotations (TOC) in the PDF can be interacted with.

Bookmarks

DocumentOutline

Gets the outline for the document.

IsTextSelectionEnabled

EnableTextSelection

Gets or sets a value that indicates whether the text selection is enabled or not. The default value is true.

TextSelectionColor

HighlightColor

Gets or sets the color to highlight the selected text. The default value is Color.FromRgba(0, 0, 205, 80).

CurrentInstanceColor

CurrentMatchHighlightColor

Gets or sets the color for highlighting the current match of the searched text. The default value is Color.FromRgba(249, 125, 0, 80).

OtherInstanceColor

OtherMatchesHighlightColor

Gets or sets the color for highlighting the other matches of the searched text. The default value is Color.FromRgba(255, 255, 0, 50).

AnnotationMode

AnnotationMode

Gets or sets a value indicating the type of annotation that should be drawn using UI interaction on the PDF pages.

Annotations

Annotations

Gets the list of annotations in the PDF.

AnnotationSettings

AnnotationSettings

Gets or sets the default annotation settings.

ClearAllAnnotationsCommand

RemoveAllAnnotationsCommand

The command that removes all annotations from the PDF document.

PerformUndoCommand

UndoCommand

The command that performs the undo operation.

PerformRedoCommand

RedoCommand

The command that performs the redo operation.

InkPointsCollection

PointsCollection

Gets or sets the series of coordinates that represent the ink points of an ink annotation.

InkAnnotationSettings.Thickness

InkAnnotationSettings.BorderWidth

Gets or sets the border thickness of an ink annotation.

ShapeAnnotationSettings.Thickness

ShapeAnnotationSettings.BorderWidth

Gets or sets the border thickness of shape annotation.

InkAnnotationSettings.EnableSeparateAttributesForEachStroke

InkAnnotationSettings.AggregateInkStrokes

Gets or sets a value indicating whether each ink strokes should be treated as separate ink annotations.

ShapeAnnotationSettings.StrokeColor

ShapeAnnotationSettings.Color

Gets or sets the default stroke color of shape annotation.

SelectorSettings.StrokeColor

AnnotationSelectorSettings.Color

Gets or sets the default color of annotation selector.

LockedStrokeColor

LockedColor

Gets or sets the default color of annotation selector when the selected annotation is locked.

LinePoints

LineAnnotation.Points

Gets or sets the series of coordinates that represent the starting point and ending point of a line annotation.

Rectangle

ShapeAnnotationSettings.Square

Gets or sets the default settings for square annotations.

Circle

AnnotationSettings.Circle

Gets or sets the default settings for circle annotations.

Line

AnnotationSettings.Line

Gets or sets the default settings for line annotations.

Arrow

AnnotationSettings.Arrow

Gets or sets the default settings for arrow annotations.

Ink

AnnotationSettings.Ink

Gets or sets the default settings for ink annotations.

Stamp

AnnotationSettings.Stamp

Gets or sets the default settings for stamp annotations.

Selector

AnnotationSettings.Selector

Gets or sets the default settings for the annotation selector.

FormField.CanEdit

FormField.ReadOnly

Gets or sets a value that indicates whether the form field can be edited or not.

SignatureFormField.HandwrittenSignature

SignatureFormField.Signature

Gets or sets the ink annotation signature in the signature field.

PageViewMode

PageLayoutMode

Gets or sets the layout mode in which the pages will be displayed.

InkAnnotationSettings.TouchMode

InkAnnotationSettings.TouchScreenInputMode

Gets or sets a value that indicates the input mode in which the ink strokes should be allowed to be drawn.

TouchMode.Direct

TouchScreenInputMode.FingerAndStylus

Allows drawing ink using both finger and stylus.

IsToolbarVisible

ShowToolbars

Backing store for the ShowToolbars property.

Events

Xamarin SfPdfViewer .NET MAUI SfPdfViewer Description

UnhandledConditionOccurred

DocumentLoadFailed

Occurs when the PDF Viewer fails to load a PDF document. That is, when any corrupted document is loaded, when any password-protected document is loaded with an invalid or empty password, or when any non-PDF document is loaded.

SearchInitiated

,

SearchCompleted

TextSearchProgress

Occurs when the text search is in progress.

TextSelectionCompleted

TextSelectionChanged

Occurs when the text is selected or when the selected text is changed.

AnnotationAdded

Occurs when an annotation is added to a page.

AnnotationDeselected

Occurs when a selected annotation gets deselected.

AnnotationEdited

Occurs when annotation is modified.

AnnotationRemoved

Occurs when an annotation is removed from the page.

AnnotationSelected

Occurs when an annotation is selected.

PropertyChanged

Occurs when a property in the PDF Viewer is modified. It allows you to detect page changes occurred in the PDF Viewer. The example below demonstrates how to implement this:
  • C#
  • // Create an instance of the SfPdfViewer control
    SfPdfViewer pdfViewer = new SfPdfViewer();
    // Subscribe to the PropertyChanged event
    pdfViewer.PropertyChanged += PdfViewer_PropertyChanged;
    
    // Event handler for the PropertyChanged event
    private void PdfViewer_PropertyChanged(object? sender, PropertyChangedEventArgs e)
    {
       // Typecast the sender to SfPdfViewer
       if (sender is SfPdfViewer pdfViewer)
       {
          // Check if the changed property is PageNumber
          if (e.PropertyName == nameof(SfPdfViewer.PageNumber))
          {
             // Get the current page number
             int currentPageNumber = pdfViewer.PageNumber;
          }
       }
    }

    Methods

    Xamarin SfPdfViewer .NET MAUI SfPdfViewer Description

    Unload

    UnloadDocument

    Unload the current PDF document.

    GoToBookmark

    GoToOutlineElement

    Navigates to the location of the given outline element.

    SearchText

    SearchTextAsync

    Finds and highlights all occurrences of the given text in the PDF document asynchronously.

    CancelSearch

    Clear

    Clears the highlighted searched text in the PDF document and the search information from the results. Also, it cancels the progress while the text search is running.

    SearchNext

    GoToNextMatch

    Navigates to the next match of the searched text.

    SearchPrevious

    GoToPreviousMatch

    Navigates to the previous match of the searched text.

    ClearAllAnnotations

    RemoveAllAnnotations

    Removes all annotations from the PDF document.

    AddAnnotation

    Adds the given annotation to the page represented by the annotation’s PageNumber property.

    DeselectAnnotation

    DeselectAnnotation

    Deselects the given annotation.

    ExportAnnotations

    ExportAnnotations

    Exports the annotations in the PDF document to the specified format and writes the exported data to the given output stream.

    ExportAnnotationsAsync

    ExportAnnotationsAsync

    Exports the annotations in the PDF document to the specified format and writes the exported data to the given output stream.

    ImportAnnotations

    ImportAnnotations

    Imports annotation data into the PDF document.

    RemoveAnnotation

    RemoveAnnotation

    Removes the given annotation from the page.

    SaveDocument

    SaveDocument

    Saves the PDF document and writes the final document into the given output stream.

    SaveDocumentAsync

    SaveDocumentAsync

    Saves the PDF document and writes the final document into the given output stream.

    SelectAnnotation

    SelectAnnotation

    Selects the given annotation.

    Print

    PrintDocument

    Prints the PDF document.

    SaveDocument(bool flattenForm)

    FormField.FlattenOnSave

    Specifies whether the form fields should be flattened or not on saving

    Classes

    Xamarin SfPdfViewer .NET MAUI SfPdfViewer Description

    CustomBookmark

    Bookmark

    Represents a custom bookmark with a name and associated page number.

    TouchMode

    TouchScreenInputMode

    Enumerates the values that specify the input mode in which the ink strokes should be allowed to be drawn.

    TextSelectionCompletedEventArgs

    TextSelectionChangedEventArgs

    Provides data for TextSelectionChanged event.

    UnhandledConditionEventArgs

    DocumentLoadFailedEventArgs

    Provides data for the

    DocumentLoadFailed

    event.

    TextMarkupAnnotation

    Represents the text markup annotation on the text contents in the page.

    ShapeAnnotation

    Represents an annotation that displays a shape on the page.

    PopupAnnotation

    StickyNoteAnnotation

    Represents the sticky note annotation on the text contents in the page.

    AnnotationEventArgs

    Provides data for the

    AnnotationAdded

    ,

    AnnotationSelected

    ,

    AnnotationDeselected

    ,

    AnnotationEdited

    ,

    AnnotationRemoved

    events.