PdfViewer Class
Definition
Keyboard nudging of the selected annotation and deselection from presses outside the pages.
public class PdfViewer
Constructors
| Name | Description |
|---|---|
| PdfViewer | No summary available. |
PdfViewer Constructor
public PdfViewer()
Methods
| Name | Description |
|---|---|
| AddBookmark | Adds a bookmark for the given 1-based page. No-op when the page is out of range or already bookmarked. Returns if a bookmark was added. |
| AddHandler (2 overloads) | Adds a handler for the specified routed event. Inherited from Interactive. |
| AddStampAsync | No summary available. |
| AddStickyNoteAsync | No summary available. |
| ApplyStyling | Applies styling to the control if the control is initialized and styling is not already applied. Inherited from StyledElement. |
| ApplyTemplate | Creates the visual children of the control, if necessary Inherited from TemplatedControl. |
| Arrange | Arranges the control and its children. Inherited from Layoutable. |
| BeginInit | Inherited from StyledElement. |
| Bind (8 overloads) | Binds a Avalonia.AvaloniaProperty to an Avalonia.Data.BindingBase. Inherited from AvaloniaObject. |
| CheckAccess | Returns a value indicating whether the current thread is the UI thread. Inherited from AvaloniaObject. |
| ClearError | Clears Avalonia.Controls.PdfViewer.ErrorMessage. An open document stays open; after a failed load the viewer returns to its empty state. The template's dismiss buttons call this. |
| ClearSearch | Clears the current search query, results, and highlights. |
| ClearSelection | Clears the current text selection. |
| ClearValue (4 overloads) | Clears a Avalonia.AvaloniaProperty's local value. Inherited from AvaloniaObject. |
| CloseDocument | Closes the current document. |
| CoerceValue | Coerces the specified Avalonia.AvaloniaProperty. Inherited from AvaloniaObject. |
| CopySelectionToClipboard | Copies the current selection to the clipboard. |
| DefaultStampColorFor | The colour a stamp is drawn in when Avalonia.Controls.PdfViewer.StampColor is not set. |
| EndInit | Inherited from StyledElement. |
| Equals | Compares two objects using reference equality. Inherited from AvaloniaObject. |
| FindNext | Advances to the next search match (wraps around). |
| FindPrevious | Moves to the previous search match (wraps around). |
| FitHeight | Fits the current page height to the view. |
| FitPage | Fits the entire page to the view. |
| FitWidth | Fits the page width to the view. |
| Focus | Focuses the control. Inherited from InputElement. |
| FocusViewer | Focuses the PDF viewer control for keyboard navigation. Call this after external interactions (like opening a file) to enable keyboard navigation. |
| FormatStampDate | Formats date the way a stamp's date line is drawn. |
| GetAnnotationsAsync | Gets the annotations on a page (0-based index). Returns an empty list when no document is loaded or the index is out of range. |
| GetBaseValue | Inherited from AvaloniaObject. |
| GetFlowDirection | Gets the value of the attached Avalonia.Visual.FlowDirectionProperty on a control. Inherited from Visual. |
| GetHashCode | Gets the hash code for the object. Inherited from AvaloniaObject. |
| GetIsHoldingEnabled | Inherited from InputElement. |
| GetIsHoldWithMouseEnabled | Inherited from InputElement. |
| GetIsTemplateFocusTarget | Gets the value of the IsTemplateFocusTargetProperty attached property on a control. Inherited from TemplatedControl. |
| GetOutline | Gets the document outline (bookmarks). |
| GetPageLabel | The page's label from the document's /PageLabels ("iv", "A-2"), or null when the document defines none. pageNumber is 1-based. |
| GetPageTextAsync | Extracts the plain text of a single page (0-based index). Returns an empty string when no document is loaded or the index is out of range. |
| GetSelectedText | Gets the currently selected text. |
| GetTextAsync | Extracts the plain text of the whole document, one page per element. |
| GetValue (3 overloads) | Gets a Avalonia.AvaloniaProperty value. Inherited from AvaloniaObject. |
| GoToBookmark | Navigates to a bookmark's target: its full destination (page plus position) when it has one, else its page. Returns true if the bookmark has a page target. |
| GoToPage | Navigates to a specific page. |
| HighlightSelectionAsync | No summary available. |
| InvalidateArrange | Invalidates the arrangement of the control and queues a new layout pass. Inherited from Layoutable. |
| InvalidateMeasure | Invalidates the measurement of the control and queues a new layout pass. Inherited from Layoutable. |
| InvalidateVisual | Invalidates the visual and queues a repaint. Inherited from Visual. |
| IsAnimating | Checks whether a Avalonia.AvaloniaProperty is animating. Inherited from AvaloniaObject. |
| IsPageBookmarked | Returns whether the given 1-based page currently has a bookmark. |
| IsSet | Checks whether a Avalonia.AvaloniaProperty is set on this object. Inherited from AvaloniaObject. |
| LoadDocumentAsync (3 overloads) | Loads a PDF document from a stream. The stream is read once, from its current position (a seekable stream left at its end is read from the start), and is never disposed or kept: the viewer holds its own copy of the bytes, so the caller may dispose the stream as soon as this call returns. The document has no path; save with Avalonia.Controls.PdfViewer.SaveDocumentAsync(string) or Save As. |
| Measure | Carries out a measure of the control. Inherited from Layoutable. |
| NavigateTo | Navigates to a link destination: the page, and in the continuous view modes the position on it (an /XYZ or /FitH target lands with its top edge at the top of the viewport, not the page top); an /XYZ zoom that is set is applied first. Returns true if it was an in-document page destination that could be resolved. |
| NextPage | Navigates to the next page (or next spread in two-page mode). |
| Open | Opens a document via the file picker (fire-and-forget). See Avalonia.Controls.PdfViewer.OpenAsync(System.Threading.CancellationToken). |
| OpenAsync | Asks the user for a PDF and loads it. Raises Avalonia.Controls.PdfViewer.OpenRequested first; when the host does not handle it, the platform file picker of the owning Avalonia.Controls.TopLevel is used. A file with a local path is opened by path (so Avalonia.Controls.PdfViewer.Source is set and in-place saving works); otherwise it is read through a stream. |
| OpenMoreOptions | Opens the More Options flyout programmatically. |
| PreviousPage | Navigates to the previous page (or previous spread in two-page mode). |
| Prints the current document (fire-and-forget). Errors surface via Avalonia.Controls.PdfViewer.ErrorMessage. | |
| PrintAsync | Prints the current document. Raises Avalonia.Controls.PdfViewer.PrintRequested first; if the handler marks it handled nothing else happens, otherwise the Avalonia.Controls.PdfViewer.PrintService shows the system print dialog. No-op when no document is loaded. |
| RaiseEvent | Raises a routed event. Inherited from Interactive. |
| RedactSelectionAsync | No summary available. |
| Redo | Re-applies the most recently undone edit, if any. |
| RedoAsync | Re-applies the most recently undone edit and completes when the document has been updated. |
| RemoveBookmark | Removes the bookmark for the given 1-based page. Returns if a bookmark was removed. |
| RemoveHandler (2 overloads) | Removes a handler for the specified routed event. Inherited from Interactive. |
| Render | Renders the visual to a Avalonia.Media.DrawingContext. Inherited from Visual. |
| RenderPageToImageAsync | Renders a page (0-based index) to a bitmap at the given scale (1.0 == 100%). Returns null when no document is loaded or the index is out of range. The caller owns the returned bitmap and should dispose it. |
| ResetZoom | Resets zoom to 100%. |
| Save | Saves the document in place (fire-and-forget); a failure, including a stream-backed document with no path, is reported through Avalonia.Controls.PdfViewer.ErrorMessage. See Avalonia.Controls.PdfViewer.SaveAsync. |
| SaveAs | Saves via the save picker (fire-and-forget). See Avalonia.Controls.PdfViewer.SaveAsAsync(System.Threading.CancellationToken). |
| SaveAsAsync | Writes the document, with its annotation edits, to a file chosen by the user. Raises Avalonia.Controls.PdfViewer.SaveAsRequested first; when the host does not handle it, the platform save picker of the owning Avalonia.Controls.TopLevel is used. Choosing the open file saves in place (see Avalonia.Controls.PdfViewer.SaveAsync); choosing another local path writes it and the viewer switches to that file, keeping the current page. |
| SaveAsync | Saves the document in place to its original Avalonia.Controls.PdfViewer.Source path, including any annotation edits. No-op when Avalonia.Controls.PdfViewer.AllowDocumentSaving is false or when no document is loaded. A document loaded from a stream or byte array has no path to save to: use Avalonia.Controls.PdfViewer.SaveDocumentAsync(System.IO.Stream) or Avalonia.Controls.PdfViewer.SaveAsAsync(System.Threading.CancellationToken) for those. |
| SaveDocumentAsync (2 overloads) | Saves the document (with all annotations) to a stream. |
| SearchAsync (2 overloads) | Searches for text in the document and publishes the results (Avalonia.Controls.PdfViewer.SearchResults, find next/previous, Avalonia.Controls.PdfViewer.SearchCompleted). A failure is reported through Avalonia.Controls.PdfViewer.ErrorMessage and returns an empty list. |
| SelectAll | Selects all text on the current page. |
| SetCurrentValue (2 overloads) | Sets the value of a dependency property without changing its value source. Inherited from AvaloniaObject. |
| SetFlowDirection | Sets the value of the attached Avalonia.Visual.FlowDirectionProperty on a control. Inherited from Visual. |
| SetIsHoldingEnabled | Inherited from InputElement. |
| SetIsHoldWithMouseEnabled | Inherited from InputElement. |
| SetIsTemplateFocusTarget | Sets the value of the IsTemplateFocusTargetProperty attached property on a control. Inherited from TemplatedControl. |
| SetValue (3 overloads) | Sets a Avalonia.AvaloniaProperty value. Inherited from AvaloniaObject. |
| Share | Shares the current document (fire-and-forget). Errors surface via Avalonia.Controls.PdfViewer.ErrorMessage. |
| ShareAsync | Shares the current document. Raises Avalonia.Controls.PdfViewer.ShareRequested first; if the handler marks it handled nothing else happens, otherwise the Avalonia.Controls.PdfViewer.ShareService shows the system share sheet. No-op when no document is loaded. |
| SquigglySelectionAsync | No summary available. |
| StampNameForLabel | Stamp name for a label: the label without spaces, so standard labels map to standard names. |
| StampStyleDisplayName | The English name of a style as shown in the Stamp dropdown (see Avalonia.Controls.PdfViewer.Strings for other languages). |
| StrikeoutSelectionAsync | No summary available. |
| ToggleBookmark | Toggles the bookmark for the given 1-based page. Returns the new state ( when the page is now bookmarked). |
| ToggleBookmarkCurrentPage | Toggles the bookmark for the current page (the ⌘D / Ctrl+D action). |
| TryGetResource | Inherited from StyledElement. |
| UnderlineSelectionAsync | No summary available. |
| Undo | Reverts the most recent edit, if any. |
| UndoAsync | Reverts the most recent edit and completes when the document has been updated. |
| UpdateLayout | Executes a layout pass. Inherited from Layoutable. |
| UpdateStickyNoteAsync | No summary available. |
| VerifyAccess | Checks that the current thread is the UI thread and throws if not. Inherited from AvaloniaObject. |
| ZoomIn | Zooms in to the next preset level. |
| ZoomOut | Zooms out to the previous preset level. |
AddBookmark Method
Adds a bookmark for the given 1-based page. No-op when the page is out of range or already bookmarked. Returns if a bookmark was added.
public bool AddBookmark(int pageNumber)
Parameters
pageNumber int
Returns
bool
AddStampAsync Method
public System.Threading.Tasks.Task<int> AddStampAsync(int pageIndex, string label, double pdfX, double pdfY, Nullable<Avalonia.Controls.Pdf.Core.PdfAnnotationColor> color, Nullable<Avalonia.Controls.PdfStampStyle> style, Nullable<bool> includeDate)
Parameters
pageIndex int
label string
pdfX double
pdfY double
color Nullable<Avalonia.Controls.Pdf.Core.PdfAnnotationColor>
style Nullable<Avalonia.Controls.PdfStampStyle>
includeDate Nullable<bool>
Returns
System.Threading.Tasks.Task<int>
AddStickyNoteAsync Method
public System.Threading.Tasks.Task<int> AddStickyNoteAsync(int pageIndex, double pdfX, double pdfY, string text, Nullable<Avalonia.Controls.Pdf.Core.PdfAnnotationColor> color)
Parameters
pageIndex int
pdfX double
pdfY double
text string
color Nullable<Avalonia.Controls.Pdf.Core.PdfAnnotationColor>
Returns
System.Threading.Tasks.Task<int>
ClearError Method
Clears Avalonia.Controls.PdfViewer.ErrorMessage. An open document stays open; after a failed load the viewer returns to its empty state. The template's dismiss buttons call this.
public void ClearError()
ClearSearch Method
Clears the current search query, results, and highlights.
public void ClearSearch()
ClearSelection Method
Clears the current text selection.
public void ClearSelection()
CloseDocument Method
Closes the current document.
public void CloseDocument()
CopySelectionToClipboard Method
Copies the current selection to the clipboard.
public System.Threading.Tasks.Task CopySelectionToClipboard()
Returns
System.Threading.Tasks.Task
DefaultStampColorFor Method
The colour a stamp is drawn in when Avalonia.Controls.PdfViewer.StampColor is not set.
public Avalonia.Controls.Pdf.Core.PdfAnnotationColor DefaultStampColorFor(string label)
Parameters
label string
Returns
FindNext Method
Advances to the next search match (wraps around).
public void FindNext()
FindPrevious Method
Moves to the previous search match (wraps around).
public void FindPrevious()
FitHeight Method
Fits the current page height to the view.
public void FitHeight()
FitPage Method
Fits the entire page to the view.
public void FitPage()
FitWidth Method
Fits the page width to the view.
public void FitWidth()
FocusViewer Method
Focuses the PDF viewer control for keyboard navigation. Call this after external interactions (like opening a file) to enable keyboard navigation.
public void FocusViewer()
FormatStampDate Method
Formats date the way a stamp's date line is drawn.
public string FormatStampDate(DateTime date)
Parameters
date DateTime
Returns
string
GetAnnotationsAsync Method
Gets the annotations on a page (0-based index). Returns an empty list when no document is loaded or the index is out of range.
public System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Avalonia.Controls.Pdf.Core.PdfAnnotationInfo>> GetAnnotationsAsync(int pageIndex, System.Threading.CancellationToken cancellationToken)
Parameters
pageIndex int
cancellationToken System.Threading.CancellationToken
Returns
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<Avalonia.Controls.Pdf.Core.PdfAnnotationInfo>>
GetOutline Method
Gets the document outline (bookmarks).
public System.Collections.Generic.IReadOnlyList<Avalonia.Controls.Pdf.Core.PdfBookmark> GetOutline()
Returns
System.Collections.Generic.IReadOnlyList<Avalonia.Controls.Pdf.Core.PdfBookmark>
GetPageLabel Method
The page's label from the document's /PageLabels ("iv", "A-2"), or null when the document
defines none. pageNumber is 1-based.
public string GetPageLabel(int pageNumber)
Parameters
pageNumber int
Returns
string
GetPageTextAsync Method
Extracts the plain text of a single page (0-based index). Returns an empty string when no document is loaded or the index is out of range.
public System.Threading.Tasks.Task<string> GetPageTextAsync(int pageIndex, System.Threading.CancellationToken cancellationToken)
Parameters
pageIndex int
cancellationToken System.Threading.CancellationToken
Returns
System.Threading.Tasks.Task<string>
GetSelectedText Method
Gets the currently selected text.
public string GetSelectedText()
Returns
string
The selected text, or null if no selection.
GetTextAsync Method
Extracts the plain text of the whole document, one page per element.
public System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<string>> GetTextAsync(System.Threading.CancellationToken cancellationToken)
Parameters
cancellationToken System.Threading.CancellationToken
Returns
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyList<string>>
GoToBookmark Method
Navigates to a bookmark's target: its full destination (page plus position) when it has
one, else its page. Returns true if the bookmark has a page target.
public bool GoToBookmark(Avalonia.Controls.Pdf.Core.PdfBookmark bookmark)
Parameters
bookmark Avalonia.Controls.Pdf.Core.PdfBookmark
Returns
bool
GoToPage Method
Navigates to a specific page.
public void GoToPage(int pageNumber)
Parameters
pageNumber int
HighlightSelectionAsync Method
public System.Threading.Tasks.Task<int> HighlightSelectionAsync(Nullable<Avalonia.Controls.Pdf.Core.PdfAnnotationColor> color)
Parameters
color Nullable<Avalonia.Controls.Pdf.Core.PdfAnnotationColor>
Returns
System.Threading.Tasks.Task<int>
IsPageBookmarked Method
Returns whether the given 1-based page currently has a bookmark.
public bool IsPageBookmarked(int pageNumber)
Parameters
pageNumber int
Returns
bool
LoadDocumentAsync overloads
LoadDocumentAsync Method
Loads a PDF document from a stream. The stream is read once, from its current position (a seekable stream left at its end is read from the start), and is never disposed or kept: the viewer holds its own copy of the bytes, so the caller may dispose the stream as soon as this call returns. The document has no path; save with Avalonia.Controls.PdfViewer.SaveDocumentAsync(string) or Save As.
public System.Threading.Tasks.Task LoadDocumentAsync(System.IO.Stream stream, string password)
Parameters
stream System.IO.Stream
password string
Returns
System.Threading.Tasks.Task
LoadDocumentAsync Method
public System.Threading.Tasks.Task LoadDocumentAsync(ReadOnlyMemory<byte> data, string password)