Pdf |
The PdfViewer type exposes the following members.
| Name | Description | |
|---|---|---|
| BrowserExecutableFolder | The folder of a fixed version WebView2 Runtime to use instead of the installed Evergreen runtime. Set it before the control is shown. When not set, a fixed version runtime in a "WebView2Runtime" folder next to the application is used (WebView2Runtime\x64 or WebView2Runtime\x86 for the bitness of the process, or the folder Microsoft's .cab file expands to inside it); without one, the installed Evergreen runtime. | |
| CanAssembleDocument | Can assemble the document (create bookmarks, thumbnail images or insert, rotate, delete pages). This property has effect when a 128 bit key is used. The default value is true. | |
| CanCopyContent | Can copy the document content. The viewer honours this permission. The default value is true. | |
| CanEditAnnotations | Can edit PDF document annotations. The default value is true. | |
| CanEditContent | Can edit PDF document content. The default value is true. | |
| CanFillFormFields | Can fill the form fields. This property has effect when a 128 bit key is used. The default value is true. | |
| CanPrint | Can print the document. The viewer honours this permission. The default value is true. | |
| CoreWebView2 | The Microsoft Edge WebView2 instance that displays the viewer, for advanced customization (for example browser settings). It is null until the viewer has started; the viewer itself is driven through the members of this control. | |
| CurrentPage | Gets the page shown in the viewer, or goes to the specified page. The first page in a document is page 1. Set before a document is loaded, the document opens at that page. -1 means the viewer shows the first page. | |
| DocumentDisplayMode | Gets or sets the display mode of the document to show the page thumbnails, the outline (bookmarks) or the attachments next to the document. The default value is NotSet (the document's own page mode). | |
| InstallWebView2RuntimeIfMissing | Installs the Evergreen Microsoft Edge WebView2 Runtime when it is missing on the computer: the viewer runs Microsoft's installer (WebView2BootstrapperPath) for the current user, silently, then starts. The default value is false: the viewer shows a message with the download address instead. Set it before the control is shown. | |
| IsDocumentLoaded | True when a document is loaded and displayed in the viewer (after DocumentLoaded). | |
| KeySize | The dimension of the encryption key. By default a 128 bit key is used. | |
| LicenseKey | Gets or sets the license key | |
| OpenPassword | The password of a password protected PDF document. It opens the document without asking the user, and it is used to change the viewer preferences and security options of a protected document. When it is not set (or not correct), PasswordRequired is raised; when the application does not give the password there, the viewer asks the user for it. | |
| OwnerPassword | The password required to change permissions of the PDF document like printing or editing. The default value is an empty string. If the OwnerPassword property is an empty string and the UserPassword is not empty, an owner password is generated, so the permissions cannot be changed by opening the document with the user password. | |
| PageCount | Gets the page count of the currently loaded PDF document, or -1 when no document is loaded. | |
| PageFitMode | Gets or sets the fit mode of the PDF page in the viewer. The default value is NotSet. | |
| PageLayoutMode | Gets or sets the layout mode for a page view. The default value is NotSet. | |
| PdfSecurityOptions | Gets a reference to the object controlling the PDF document security settings like user and owner password, and restricting printing or copying of the displayed document. The viewer honours the printing and copying permissions. The settings take effect for the next document loaded (or after ReloadPdfDocument). | |
| PdfViewerPreferences | Gets a reference to the object controlling the PDF document viewer preferences. The properties of this object allow you to hide the toolbar and the navigation panel, and to change the page mode and the page layout of the document. They are written into the displayed document, and take effect for the next document loaded (or after ReloadPdfDocument). | |
| ShowDocumentPropertiesButton | Show or hide the document properties command of the viewer. The default value is true. | |
| ShowDownloadButton | Show or hide the download (save a copy) button of the toolbar (and Ctrl+S). The default value is true. | |
| ShowFindButton | Show or hide the find button of the toolbar and its find bar (and Ctrl+F). Find(String, Boolean, Boolean) works either way. The default value is true. | |
| ShowNavigationPanel | Show or hide the navigation panel on the left side of the viewer, with the page thumbnails, the document outline (bookmarks) and the attachments. The default value of this property is true. This property is a shortcut for the PdfViewerPreferences.HideWindowUI. | |
| ShowOpenButton | Show or hide the open file command of the viewer (in the tools menu of the toolbar; Ctrl+O): the user can open another PDF file from the computer in the viewer. A document the user opens is only displayed: ReloadPdfDocument reloads the document loaded by the application. The default value is false. | |
| ShowPageNavigationButtons | Show or hide the page navigation of the toolbar (previous page, next page, the page number box and the first and last page commands). The default value is true. | |
| ShowPresentationModeButton | Show or hide the presentation mode (full screen) command of the viewer. The default value is true. | |
| ShowPrintButton | Show or hide the print button of the toolbar (and Ctrl+P). The print methods of the control work either way; printing also depends on the document permissions (CanPrint). The default value is true. | |
| ShowScrollbars | Show or hide the viewer scrollbars. The document can still be scrolled with the mouse wheel and the keyboard. The default value is true. | |
| ShowSidebarButton | Show or hide the toolbar button that opens and closes the navigation panel (the panel itself can still be shown with DocumentDisplayMode). The default value is true. | |
| ShowToolbarMode | Show or hide the viewer toolbar. The default value is NotSet (the toolbar is shown). | |
| ShowZoomButtons | Show or hide the zoom buttons and the zoom list of the toolbar. The default value is true. | |
| UserDataFolder | The folder where the viewer keeps its browser data (cache, settings). Set it before the control is shown. When not set, a folder under the local application data folder (ExpertPdf\PdfViewer\WebView2) is used. A viewer that uses a fixed version runtime gets a folder of its own (WebView2-<hash> next to it): WebView2 cannot share one folder between runtimes. When the folder is in use by WebView2 with other settings (another application), the viewer uses a folder of the application's own, and a viewer whose window has another DPI awareness than the first viewer of the process (a Windows Forms application becomes DPI aware when it first shows WPF content) uses WebView2-dpi-<awareness> next to it. A folder set here is always used as it is: give viewers with different settings different folders. | |
| UserPassword | The password required to open the PDF document. The viewer asks the user for it. The default value is an empty string. | |
| ViewerTheme | Gets or sets the color theme of the viewer: light, dark, or as set in Windows (the default). The pages of the document keep their own colors. | |
| WebView2BootstrapperPath | The Microsoft Edge WebView2 Runtime installer (bootstrapper) used by InstallWebView2Runtime and InstallWebView2RuntimeIfMissing. The default value is MicrosoftEdgeWebview2Setup.exe in the application folder, where the NuGet package of the viewer puts it. | |
| ZoomPercentage | Gets or sets the zoom percentage of the viewer. For example, 100 represents a magnification of 100%. Reading it gives the zoom of the viewer (it changes when the user zooms, or with the fit modes). A negative value means the default zoom is used. The default value is -1. |
| Name | Description | |
|---|---|---|
| Close | Releases the resources used by this control | |
| CloseDocument | Closes the document displayed in the viewer. | |
| Dispose |
Clean up any resources being used.
(Overrides ContainerControlDispose(Boolean)) | |
| Find(String) | Searches the displayed document for a text (not case sensitive, also inside words). See Find(String, Boolean, Boolean). | |
| Find(String, Boolean, Boolean) | Searches the displayed document for a text, highlights every match and scrolls the first match from the current page on into view. SearchCompleted is raised with the number of matches when the whole document is searched. An empty text removes the highlights of the previous search. | |
| FindNext | Selects the next match of the last search (after the last match, the first one) and scrolls it into view. SearchCompleted is raised with the selected match. | |
| FindPrevious | Selects the previous match of the last search (before the first match, the last one) and scrolls it into view. SearchCompleted is raised with the selected match. | |
| GetPageCount(Stream) | A fast method to obtain the page count of a specified PDF document. | |
| GetPageCount(String) | A fast method to obtain the page count of a specified PDF document. | |
| GoBackwardStack | Goes to the previous view in the navigation history (for example back from a link), if it exists. | |
| GoForwardStack | Goes to the next view in the navigation history, if it exists. | |
| GoToFirstPage | Goes to the first page in the document. | |
| GoToLastPage | Goes to the last page in the document. | |
| GoToNextPage | Goes to the next page in the document, if it exists. | |
| GoToPreviousPage | Goes to the previous page in the document, if it exists. | |
| InstallWebView2Runtime | Installs the Evergreen Microsoft Edge WebView2 Runtime for the current user with Microsoft's installer (WebView2BootstrapperPath, run silently; it downloads the runtime) and waits for it, for up to 5 minutes. Returns true when the installer succeeded and the runtime is installed. Call it from a background thread: it blocks while the runtime is installed. | |
| LoadBytes | Opens and displays the PDF document in the specified byte array. | |
| LoadFile | Opens and displays the specified PDF file. | |
| LoadStream | Opens and displays the PDF document in the specified stream. The stream is read when the method is called. | |
| OnCurrentPageChanged | Raises the CurrentPageChanged event. | |
| OnDocumentLoaded | Raises the DocumentLoaded event. | |
| OnHandleCreated |
Starts the viewer when the control gets its window.
(Overrides ControlOnHandleCreated(EventArgs)) | |
| OnLoadError | Raises the LoadError event. | |
| OnPasswordRequired | Raises the PasswordRequired event. | |
| OnSearchCompleted | Raises the SearchCompleted event. | |
| Prints the document according to the options selected in the print dialog. This method returns immediately, even if the printing has not completed. NOTE: If security settings do not allow printing, this method will be ignored. | ||
| PrintAll | Prints the entire document on the default printer without displaying a dialog. This method returns immediately, even if the printing has not completed. Use PrintAsync(Int32, Int32, String) to know the result. | |
| PrintAllFit | Prints the entire document on the default printer without displaying a dialog. This method returns immediately, even if the printing has not completed. | |
| PrintAsync | Prints pages of the document without displaying a dialog. | |
| PrintPages | Prints the specified pages on the default printer without displaying a dialog. This method returns immediately, even if the printing has not completed. | |
| PrintPagesFit | Prints the specified pages on the default printer without displaying a dialog. This method returns immediately, even if the printing has not completed. | |
| PrintWithDialog | Prints the document according to the options selected in the print dialog. This method returns immediately, even if the printing has not completed. NOTE: If security settings do not allow printing, this method will be ignored. | |
| ReloadPdfDocument | Call this method to reload the currently loaded PDF document after changing the PdfViewerPreferences or the PdfSecurityOptions. | |
| RemoveProductLogo | Call this method to remove the product logo image when no PDF document is loaded in the viewer. | |
| SetCurrentHighlight | Highlights the specified rectangle on the current page. A rectangle with no width or height removes the highlight. | |
| SetCurrentPage | Goes to the specified page in the document. | |
| SetLayoutMode | Sets the layout mode for a page view according to the specified string. | |
| SetNamedDest | Changes the page view to the named destination in the specified string. | |
| SetPageMode | Sets the page mode according to the specified string. | |
| SetShowScrollbars | Determines whether scrollbars will appear in the document view. | |
| SetShowToolbar | Determines whether the toolbar will appear in the viewer. | |
| SetView | Sets the view of a page according to the specified string. | |
| SetViewRect | Scrolls and zooms the current page so that the specified rectangle fills the view. | |
| SetViewScroll | Sets the view of a page according to the specified string, and scrolls the page by the specified offset. | |
| SetZoom | Sets the magnification according to the specified value. | |
| SetZoomScroll | Sets the magnification according to the specified value, and scrolls the current page so that the specified point is at the top left corner of the view. |
| Name | Description | |
|---|---|---|
| CurrentPageChanged | Raised when the page shown in the viewer changes (CurrentPage). | |
| DocumentLoaded | Raised when a document loaded with LoadFile(String), LoadStream(Stream) or LoadBytes(Byte) is displayed in the viewer. PageCount holds the number of pages. | |
| LoadError | Raised when the viewer cannot load or display a document, or when the WebView2 Runtime is missing. | |
| PasswordRequired | Raised when the document being opened is password protected and the viewer needs its password: when no OpenPassword is set, and again when the password given was not correct (IsPasswordIncorrect). Set Password to open the document, or Cancel to stop opening it. When no password is set (or the event is not handled), the viewer asks the user for the password. | |
| SearchCompleted | Raised when a search is complete: after Find(String, Boolean, Boolean), FindNext and FindPrevious, and after a search made by the user in the find bar of the viewer. The event data has the number of matches in the document and the selected match. |
The control displays PDF documents with a modern, built-in viewer: page thumbnails, outline (bookmarks) and attachments panels, text search and selection, zoom, page layouts and printing. Adobe Reader is not needed. The viewer runs on the Microsoft Edge WebView2 Runtime, which is part of Windows 10 and Windows 11 (on older systems, and on Windows Server, install the Evergreen WebView2 Runtime or point BrowserExecutableFolder at a fixed version runtime).
Load a document with LoadFile(String), LoadStream(Stream) or LoadBytes(Byte). Loading is asynchronous: the methods return as soon as the document is handed to the viewer, and DocumentLoaded is raised when it is displayed. The navigation, zoom and layout settings can be set at any time; set before a document is loaded, they apply to the next document.