A free PDF viewer control for WPF applications.
To the best of my knowledge, there is currently no other free PDF viewer available for WPF, so I created one, as I needed it in a recent customer project.
PdfView
is a custom WPF control designed to easily display PDF documents within WPF applications. It features:
- Zooming: Easily zoom in and out of PDF pages.
- Navigation: Navigate between pages using commands for next and previous pages.
- View Modes: Switch between different view modes, including single-page, double-page, and scrolling modes.
- Fit to Width/Height: Commands to automatically adjust the zoom level to fit the width or height of the control.
A demo WPF application to demonstrate how to use the PdfView
control is provided, so check out the ADaxer.Pdf.Wpf.DemoApp (which uses the wonderful MaterialDesignInXaml toolkit).
To use the PdfView
control in your WPF project, follow these simple steps:
- Add it to Your Project
-
by copying the source code or by adding it as a project reference.
-
Or by adding the NuGet Package:
dotnet add package PdfViewerControl --version 1.0.0
You can find the package here.
-
XAML Usage: Add the
PdfView
control to your XAML file.<Window x:Class="YourNamespace.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:adaxer="http://adaxer.de/pdf/wpf" Title="PDF Viewer" > <Grid> <adaxer:PdfView x:Name="pdfViewer" PdfBytes="{Binding PdfBytes}" Zoom="{Binding ZoomLevel}" ViewMode="{Binding SelectedViewMode}" CurrentPage="{Binding CurrentPage}" /> </Grid> </Window>
-
Bind the Properties: Bind the properties (
PdfBytes
,Zoom
,ViewMode
,CurrentPage
) to your view model or code-behind as needed. -
Load PDF Data: Load a PDF file into the
PdfBytes
property as a byte array.byte[] pdfData = File.ReadAllBytes("path/to/your/file.pdf"); pdfViewer.PdfBytes = pdfData;
-
Use Commands: Use the commands provided by the control to navigate and interact with the PDF.
// Zoom in pdfViewer.ZoomInCommand.Execute(null); // Move to the next page pdfViewer.NextPageCommand.Execute(null);
The image processing of the Pdf is done via PdfiumCore and uses ImageSharp, apart from that there are no dependencies.
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.